@@ -11,6 +11,38 @@ namespace System.Windows.Forms
1111 /// </summary>
1212 public static class ControlHelper
1313 {
14+ public static void AddDialogButtons ( this Control f , Control buttonOk , Control buttonCancel , params Control [ ] additionalButtons )
15+ {
16+ if ( buttonOk == null ) buttonOk = new Button ( ) ;
17+ if ( buttonCancel == null ) buttonCancel = new Button ( ) ;
18+
19+ buttonCancel . Anchor = AnchorStyles . Right | AnchorStyles . Bottom ;
20+ buttonCancel . Location = new Point ( f . Width - buttonCancel . Width - 12 , f . Height - buttonCancel . Height - 15 ) ;
21+ buttonCancel . Text = "Cancel" ;
22+ f . Controls . Add ( buttonCancel ) ;
23+
24+ buttonOk . Anchor = AnchorStyles . Right | AnchorStyles . Bottom ;
25+ buttonOk . Location = new Point ( buttonCancel . Location . X - buttonOk . Width - 9 , buttonCancel . Location . Y ) ;
26+ buttonOk . Text = "Ok" ;
27+ f . Controls . Add ( buttonOk ) ;
28+
29+ if ( additionalButtons != null )
30+ {
31+ Point lastLocation = buttonOk . Location ;
32+
33+ for ( int i = 0 ; i < additionalButtons . Length ; i ++ )
34+ {
35+ if ( additionalButtons [ i ] == null )
36+ additionalButtons [ i ] = new Button ( ) ;
37+
38+ additionalButtons [ i ] . Anchor = AnchorStyles . Right | AnchorStyles . Bottom ;
39+ additionalButtons [ i ] . Location = new Point ( lastLocation . X - additionalButtons [ i ] . Width - 9 , lastLocation . Y ) ;
40+ lastLocation = additionalButtons [ i ] . Location ;
41+ f . Controls . Add ( additionalButtons [ i ] ) ;
42+ }
43+ }
44+ }
45+
1446 /// <summary>
1547 /// Sets button's back and border colors for normal and hover state to specified color.
1648 /// </summary>
@@ -22,5 +54,13 @@ public static void ClearColor(this Button button, Color clearColor)
2254 button . HoverColor = clearColor ;
2355 button . HoverBorderColor = clearColor ;
2456 }
57+
58+ public static void ToCenter ( this Form f )
59+ {
60+ f . Location = new Point (
61+ ( Screen . PrimaryScreen . WorkingArea . Width - f . Width ) / 2 ,
62+ ( Screen . PrimaryScreen . WorkingArea . Height - f . Height ) / 2
63+ ) ;
64+ }
2565 }
2666}
0 commit comments