1 // Permission is hereby granted, free of charge, to any person obtaining
\r
2 // a copy of this software and associated documentation files (the
\r
3 // "Software"), to deal in the Software without restriction, including
\r
4 // without limitation the rights to use, copy, modify, merge, publish,
\r
5 // distribute, sublicense, and/or sell copies of the Software, and to
\r
6 // permit persons to whom the Software is furnished to do so, subject to
\r
7 // the following conditions:
\r
9 // The above copyright notice and this permission notice shall be
\r
10 // included in all copies or substantial portions of the Software.
\r
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
20 // Copyright (c) 2007 Novell, Inc.
\r
23 // Andreia Gaita <avidigal@novell.com>
\r
27 using System.Collections.Generic;
\r
28 using System.Windows.Forms;
\r
29 using System.Drawing;
\r
31 namespace System.Windows.Forms.WebBrowserDialogs
\r
33 internal class Generic : Form
\r
35 TableLayoutPanel table;
\r
37 public Generic (string title)
\r
39 this.SuspendLayout ();
\r
40 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
\r
41 this.AutoSize = true;
\r
42 this.ControlBox = true;
\r
43 this.MinimizeBox = false;
\r
44 this.MaximizeBox = false;
\r
45 this.ShowInTaskbar = (Owner == null);
\r
46 this.FormBorderStyle = FormBorderStyle.FixedDialog;
\r
48 table = new TableLayoutPanel ();
\r
49 table.SuspendLayout ();
\r
50 table.AutoSize = true;
\r
51 this.Controls.Add (table);
\r
56 public new DialogResult Show ()
\r
58 return this.RunDialog ();
\r
61 private void InitSize ()
\r
65 protected void InitTable (int rows, int cols)
\r
67 table.ColumnCount = cols;
\r
68 for (int i = 0; i < cols; i++)
\r
69 table.ColumnStyles.Add (new ColumnStyle ());
\r
70 table.RowCount = rows;
\r
71 for (int i = 0; i < rows; i++)
\r
72 table.RowStyles.Add (new RowStyle ());
\r
75 protected void AddLabel (int row, int col, int colspan, string text, int width, int height)
\r
77 Label ctl = new Label ();
\r
79 if (width == -1 && height == -1)
\r
80 ctl.AutoSize = true;
\r
83 ctl.Height = height;
\r
85 table.Controls.Add (ctl, col, row);
\r
87 table.SetColumnSpan (ctl, colspan);
\r
90 protected void AddButton (int row, int col, int colspan, string text, int width, int height, bool isAccept, bool isCancel, EventHandler onClick)
\r
92 Button ctl = new Button ();
\r
94 if (width == -1 && height == -1) {
\r
95 //SizeF s = TextRenderer.MeasureString (text, ctl.Font);
\r
96 //ctl.Width = (int) ((float) s.Width / 62f);
\r
97 //ctl.Height = (int)s.Height;
\r
100 ctl.Height = height;
\r
103 if (onClick != null)
\r
104 ctl.Click += onClick;
\r
106 AcceptButton = ctl;
\r
108 CancelButton = ctl;
\r
109 table.Controls.Add (ctl, col, row);
\r
111 table.SetColumnSpan (ctl, colspan);
\r
114 protected void AddCheck (int row, int col, int colspan, string text, bool check, int width, int height, EventHandler onCheck)
\r
116 CheckBox ctl = new CheckBox ();
\r
118 ctl.Checked = check;
\r
120 if (width == -1 && height == -1) {
\r
121 SizeF s = TextRenderer.MeasureString (text, ctl.Font);
\r
122 ctl.Width += (int) ((float) s.Width / 62f);
\r
123 if (s.Height > ctl.Height)
\r
124 ctl.Height = (int) s.Height;
\r
127 ctl.Height = height;
\r
130 if (onCheck != null)
\r
131 ctl.CheckedChanged += onCheck;
\r
133 table.Controls.Add (ctl, col, row);
\r
135 table.SetColumnSpan (ctl, colspan);
\r
138 protected void AddText (int row, int col, int colspan, string text, int width, int height, EventHandler onText)
\r
140 TextBox ctl = new TextBox ();
\r
146 ctl.Height = height;
\r
148 if (onText != null)
\r
149 ctl.TextChanged += onText;
\r
151 table.Controls.Add (ctl, col, row);
\r
153 table.SetColumnSpan (ctl, colspan);
\r
156 protected void AddPassword (int row, int col, int colspan, string text, int width, int height, EventHandler onText)
\r
158 TextBox ctl = new TextBox ();
\r
159 ctl.PasswordChar = '*';
\r
165 ctl.Height = height;
\r
167 if (onText != null)
\r
168 ctl.TextChanged += onText;
\r
170 table.Controls.Add (ctl, col, row);
\r
172 table.SetColumnSpan (ctl, colspan);
\r
175 protected DialogResult RunDialog ()
\r
177 this.StartPosition = FormStartPosition.CenterScreen;
\r
181 table.ResumeLayout (false);
\r
182 table.PerformLayout ();
\r
183 this.ResumeLayout (false);
\r
184 this.PerformLayout ();
\r
186 this.ShowDialog ();
\r
188 return this.DialogResult;
\r