-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaddingButtonEditViewInfo.cs
48 lines (42 loc) · 1.87 KB
/
PaddingButtonEditViewInfo.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
using System.Drawing;
using DevExpress.Utils.Drawing;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.ViewInfo;
namespace ButtonEditWithPadding
{
class PaddingButtonEditViewInfo : ButtonEditViewInfo
{
public PaddingButtonEditViewInfo(RepositoryItem item)
: base(item)
{
}
public Rectangle AdjustBoundsWithMargins(Rectangle boundsToAdjust)
{
boundsToAdjust.X += ((RepositoryItemPaddingButtonEdit)Item).Padding.Left;
boundsToAdjust.Y += ((RepositoryItemPaddingButtonEdit)Item).Padding.Top;
boundsToAdjust.Width -= ((RepositoryItemPaddingButtonEdit)Item).Padding.Right * 2;
boundsToAdjust.Height -= ((RepositoryItemPaddingButtonEdit)Item).Padding.Bottom * 2;
return boundsToAdjust;
}
public Rectangle RevertMarginedBounds(Rectangle boundsToRevert)
{
boundsToRevert.X -= ((RepositoryItemPaddingButtonEdit)Item).Padding.Left;
boundsToRevert.Y -= ((RepositoryItemPaddingButtonEdit)Item).Padding.Top;
boundsToRevert.Width += ((RepositoryItemPaddingButtonEdit)Item).Padding.Right * 2;
boundsToRevert.Height += ((RepositoryItemPaddingButtonEdit)Item).Padding.Bottom * 2;
return boundsToRevert;
}
protected override void OnBeforeButtonStateChanged(EditorButtonObjectInfoArgs info, ObjectState newState, int buttonId)
{
if ( Item is RepositoryItemPaddingButtonEdit )
{
info.Bounds = AdjustBoundsWithMargins(info.Bounds);
base.OnBeforeButtonStateChanged(info, newState, buttonId);
info.Bounds = RevertMarginedBounds(info.Bounds);
}
else
base.OnBeforeButtonStateChanged(info, newState, buttonId);
}
}
}