@@ -5,29 +5,99 @@ namespace CoreWindowsWrapper.Win32ApiForm
55{
66 internal class Win32Control : IWindowClass
77 {
8-
9- public static int LastControlId { get ; set ; } = 500 ;
8+
9+ public static int LastControlId { get ; set ; } = 500 ;
1010 public IntPtr Handle { get ; protected set ; }
1111 public IntPtr ParentHandle { get ; internal set ; }
1212 public string Text { get ; set ; }
1313 public string Name { get ; set ; }
1414 public Point Location { get ; set ; }
15- public int Left { get ; set ; }
16- public int Top { get ; set ; }
17- public int Width { get ; set ; }
18- public int Height { get ; set ; }
19- public bool ClientEdge { get ; set ; }
15+ private bool _Enabled = true ;
16+ public bool Enabled
17+ {
18+ get
19+ {
20+ return this . _Enabled ;
21+ }
22+ set
23+ {
24+ this . _Enabled = value ;
25+ if ( this . Handle != IntPtr . Zero )
26+ {
27+ Win32Api . EnableWindow ( this . Handle , this . _Enabled ) ;
28+ }
29+ }
30+ }
31+ public int Left
32+ {
33+ get
34+ {
35+ return this . _Left ;
36+ }
37+ set
38+ {
39+ this . _Left = value ;
40+ MoveMyWindow ( ) ;
41+
42+ }
43+ }
44+ public int Top
45+ {
46+ get
47+ {
48+ return this . _Top ;
49+ }
50+ set
51+ {
52+ this . _Top = value ;
53+ MoveMyWindow ( ) ;
54+ }
55+ }
56+ public int Width
57+ {
58+ get
59+ {
60+ return this . _Width ;
61+ }
62+ set
63+ {
64+ this . _Width = value ;
65+ MoveMyWindow ( ) ;
66+ }
67+ }
68+ public int Height
69+ {
70+ get
71+ {
72+ return this . _Height ;
73+ }
74+ set
75+ {
76+ this . _Height = value ;
77+ MoveMyWindow ( ) ;
78+ }
79+ }
80+ public bool ClientEdge { get ; set ; }
2081 public string TypeIdentifyer { get ; set ; }
2182 public int ControlId { get ; set ; }
2283 public int BackColor { get ; set ; }
23- public int ForeColor { get ; set ; }
24- public Font Font { get ; set ; }
84+ public int ForeColor { get ; set ; }
85+ public Font Font { get ; set ; }
2586 public CommonControls CommonControType { get ; set ; } = CommonControls . ICC_UNDEFINED ;
2687 public uint Style { get ; set ; } =
2788 ( WindowStylesConst . WS_VISIBLE | WindowStylesConst . WS_CHILD | WindowStylesConst . WS_TABSTOP ) ;
2889
2990 private readonly WndProc _DelegateWndProc = MyWndProc ;
91+ private int _Left ;
92+ private int _Top ;
93+ private int _Width ;
94+ private int _Height ;
3095
96+ private void MoveMyWindow ( )
97+ {
98+ if ( this . Handle == IntPtr . Zero ) return ;
99+ Win32Api . MoveWindow ( this . Handle , this . Left , this . Top , this . Width , this . Height , true ) ;
100+ }
31101 private static IntPtr MyWndProc ( IntPtr hwnd , uint msg , IntPtr wparam , IntPtr lparam )
32102 {
33103 return Win32Api . DefWindowProc ( hwnd , msg , wparam , lparam ) ;
@@ -46,29 +116,29 @@ internal virtual bool Create(IntPtr parentHandle)
46116 Win32Api . InitCommonControlsEx ( ref ccInit ) ;
47117 }
48118 this . ParentHandle = parentHandle ;
49-
119+
50120 int ediged = 0 ;
51- if ( this . ClientEdge )
52- ediged = ( int ) WindowStyles . WS_EX_CLIENTEDGE ;
121+ if ( this . ClientEdge )
122+ ediged = ( int ) WindowStyles . WS_EX_CLIENTEDGE ;
53123
54- this . Handle = Win32Api . CreateWindowEx ( ediged ,
55- this . TypeIdentifyer , this . Text ,
56- this . Style , this . Left ,
124+ this . Handle = Win32Api . CreateWindowEx ( ediged ,
125+ this . TypeIdentifyer , this . Text ,
126+ this . Style , this . Left ,
57127 this . Top ,
58128 this . Width , this . Height , this . ParentHandle ,
59- ( IntPtr ) this . ControlId , IntPtr . Zero , IntPtr . Zero ) ;
129+ ( IntPtr ) this . ControlId , IntPtr . Zero , IntPtr . Zero ) ;
60130
61- if ( this . Font != null )
131+ if ( this . Font != null )
62132 {
63133
64134 this . Font . FromLogFont ( this . Handle ) ;
65135
66- LOGFONTW f = this . Font . ToLogFont ( this . Handle ) ;
136+ LOGFONTW f = this . Font . ToLogFont ( this . Handle ) ;
67137 IntPtr hFont = Win32Api . CreateFontIndirect ( ref f ) ;
68- IntPtr retVal = Win32Api . SendMessage ( this . Handle , WindowsMessages . WM_SETFONT , hFont , 0 ) ;
138+ IntPtr retVal = Win32Api . SendMessage ( this . Handle , WindowsMessages . WM_SETFONT , hFont , 0 ) ;
69139
70140 }
71-
141+
72142 return true ;
73143
74144 }
0 commit comments