This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
105 lines (91 loc) · 3.44 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using System.Collections;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Number", typeof(int));
tbl.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < RowCount; i++)
tbl.Rows.Add(new object[] { String.Format("Name{0}", i), i, 3 - i, DateTime.Now.AddDays(i) });
return tbl;
}
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = CreateTable(20);
dataNavigator1.DataSource = dataGridView1.DataSource;
}
}
public class DataNavigatorButtonCaptionHelper : Component
{
private DataNavigator _SelectedNavigator;
public DataNavigator SelectedNavigator
{
get { return _SelectedNavigator; }
set { BeforeSelectedNavigatorChanged(value); _SelectedNavigator = value; AfterSelectedNavigatorChanged(); }
}
public ImageList _imageList;
void BeforeSelectedNavigatorChanged(DataNavigator newNavigator)
{
if (_SelectedNavigator != null)
{
_SelectedNavigator.Buttons.ImageList = null;
}
if (newNavigator != null)
{
newNavigator.Buttons.ImageList = _imageList;
}
}
private void TraverseCollection(ICollection collection)
{
NavigatorButtonCollectionBase col1 = collection as NavigatorButtonCollectionBase;
NavigatorCustomButtons col2 = collection as NavigatorCustomButtons;
for (int i = 0; i < collection.Count; i++)
{
NavigatorButtonBase button = null;
if (col1 != null) button = col1[i];
else button = col2[i];
if (button.Tag == null) continue;
_imageList.Images.Add(GetBitmap(button.Tag));
button.ImageIndex = _imageList.Images.Count - 1;
}
}
private void AfterSelectedNavigatorChanged()
{
if (SelectedNavigator == null) return;
TraverseCollection(SelectedNavigator.Buttons.ButtonCollection);
TraverseCollection(SelectedNavigator.Buttons.CustomButtons);
}
Bitmap GetBitmap(object text)
{
Bitmap image = new Bitmap(_imageList.ImageSize.Width, _imageList.ImageSize.Height);
Graphics g = Graphics.FromImage(image);
Rectangle rect = new Rectangle(new Point(0, 0), image.Size);
g.FillRectangle(Brushes.White, rect);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
g.DrawString(text.ToString(), AppearanceObject.DefaultFont, Brushes.Black, rect, sf);
image.MakeTransparent();
return image;
}
public DataNavigatorButtonCaptionHelper()
{
_imageList = new ImageList();
_imageList.ImageSize = new Size(70, 20);
}
}
}