/
ShowMessageWhenDataSourceIsNull.cs
103 lines (90 loc) · 2.3 KB
/
ShowMessageWhenDataSourceIsNull.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
using DevExpress.Utils;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace HydroDesktop.Plugins.AttributeDataExplorer
{
public class ShowMessageWhenDataSourceIsNull
{
private const string NoData = "Select a feature layer to examine attribute data.";
private GridView _ActiveView;
private Font _Font;
public GridControl ActiveGridControl
{
get
{
return this.ActiveView.GridControl;
}
}
public GridView ActiveView
{
get
{
return this._ActiveView;
}
set
{
this._ActiveView = value;
}
}
public Font PaintFont
{
get
{
if (this._Font == null)
{
return AppearanceObject.DefaultFont;
}
return this._Font;
}
set
{
this._Font = value;
}
}
public ShowMessageWhenDataSourceIsNull(GridView view)
{
this.ActiveView = view;
this.SubscribeEvents();
}
private void ActiveView_CustomDrawEmptyForeground(object sender, CustomDrawEventArgs e)
{
this.DrawNothingToSee(e);
}
private void DrawNothingToSee(CustomDrawEventArgs e)
{
if (this.ActiveGridControl.DataSource == null)
{
Graphics graphics = e.Graphics;
Font paintFont = this.PaintFont;
Brush gray = Brushes.Gray;
Rectangle seeBounds = this.NothingToSeeBounds(e.Bounds);
graphics.DrawString("Select a feature layer to examine attribute data.", paintFont, gray, seeBounds.Location);
}
}
private Rectangle GetForegroundBounds()
{
return (this.ActiveView.GetViewInfo() as GridViewInfo).ViewRects.Rows;
}
private Size GetStringSize(string s, Font font)
{
Graphics graphic = Graphics.FromHwnd(this.ActiveGridControl.Handle);
return graphic.MeasureString(s, font).ToSize();
}
private Rectangle NothingToSeeBounds(Rectangle bounds)
{
Size stringSize = this.GetStringSize("Select a feature layer to examine attribute data.", this.PaintFont);
int width = (bounds.Width - stringSize.Width) / 2;
int y = bounds.Y + 50;
return new Rectangle(new Point(width, y), stringSize);
}
private void SubscribeEvents()
{
this.ActiveView.CustomDrawEmptyForeground += new CustomDrawEventHandler(this.ActiveView_CustomDrawEmptyForeground);
}
}
}