Color demo
[mono.git] / mcs / class / System.Windows.Forms / Gtk / demo.cs
1 //
2 // System.Windows.Forms Demo app
3 //
4 // Authors: 
5 //    Joel Basson (jstrike@mweb.co.za)
6 //    Philip Van Hoof (me@freax.org)
7 //
8 //
9
10 using System;
11 using System.Drawing;
12 using System.Windows.Forms;
13
14 namespace demo
15 {
16         
17         public class GtkForm : System.Windows.Forms.Form
18         {
19                 private Button copybutton = new Button();
20                 private Button pastebutton = new Button();
21                 private Button cutbutton = new Button();
22                 private Button button1 = new Button(); 
23                 private Button button2 = new Button(); 
24                 private Label label1 = new Label();
25                 private TextBox text1 = new TextBox(); 
26                 private ProgressBar bar1 = new ProgressBar();
27                 private CheckBox check1 = new CheckBox();
28                 private RadioButton opt1 = new RadioButton();
29                 private RadioButton opt2 = new RadioButton();
30                 private RadioButton opt3 = new RadioButton();
31                 private GroupBox frame1 = new GroupBox();
32                 private PictureBox pbox = new PictureBox();
33                 private FileDialog fdialog = new FileDialog();
34                 private VScrollBar vScrollBar1 = new VScrollBar();
35                 private HScrollBar hScrollBar1 = new HScrollBar();
36
37                 private void InitializeWidgets()
38                 {
39                         this.vScrollBar1.Location = new Point(10, 10);
40                         this.vScrollBar1.Maximum = 200;
41                         this.vScrollBar1.Name = "vScrollBar1";
42                         this.vScrollBar1.Size = new Size(24, 200);
43                         this.vScrollBar1.TabIndex = 0;
44                         this.vScrollBar1.ValueChanged += new EventHandler(this.vScrollBar1_ValueChanged);
45                         
46                         this.vScrollBar1.BackColor = Color.Brown;
47
48                         this.hScrollBar1.Location = new System.Drawing.Point(50, 60);
49                         this.hScrollBar1.Maximum = 200;
50                         this.hScrollBar1.Minimum = 10;
51                         this.hScrollBar1.Name = "hScrollBar1";
52                         this.hScrollBar1.Size = new System.Drawing.Size(360, 24);
53                         this.hScrollBar1.ValueChanged += new EventHandler(this.hScrollBar1_ValueChanged);
54
55                         this.button1.Location = new Point(150, 28);
56                         this.button1.Name = "button1";
57                         this.button1.Size = new Size(128, 44);
58                         this.button1.Text = "Apply";
59                         this.button1.Click += new EventHandler(this.button1_Click);    
60                         this.button1.Enabled = false;
61                         
62
63                         this.button2.Location = new Point(150, 85);
64                         this.button2.Name = "button2";
65                         this.button2.Size = new Size(128, 44);
66                         this.button2.Text = "File";
67                         this.button2.Click += new EventHandler(this.button2_Click); 
68                         this.button2.ForeColor = Color.Brown;
69
70                         this.copybutton.Click += new EventHandler(this.copybutton_Click); 
71                         this.pastebutton.Click += new EventHandler(this.pastebutton_Click); 
72                         this.cutbutton.Click += new EventHandler(this.cutbutton_Click); 
73
74                         this.copybutton.Location = new Point(320, 80); 
75                         this.pastebutton.Location = new Point(320, 100); 
76                         this.cutbutton.Location = new Point(320, 120);
77
78                         this.copybutton.Size = new Size(150, 20); 
79                         this.pastebutton.Size = new Size(150, 20); 
80                         this.cutbutton.Size = new Size(150, 20); 
81
82                         this.copybutton.Text ="Copy";
83                         this.pastebutton.Text ="Paste";
84                         this.cutbutton.Text ="Cut";
85
86                         this.text1.Location = new Point(320,48);
87                         this.text1.Name = "textBox1";
88                         this.text1.Size = new Size(150, 22);
89                         this.text1.Text = this.button1.Name;
90
91                         this.bar1.Location = new Point(0, 230);
92                         this.bar1.Size = new Size(512, 20);
93                         this.bar1.Text = "This is a ProgressBar";
94                         this.bar1.Value = 25;
95
96                         this.label1.Location = new Point(330, 20);
97                         this.label1.Text = "This is a Label";   
98
99                         this.check1.Location = new Point(150, 160);
100                         this.check1.Size = new Size(180, 20);
101                         this.check1.Text = "arbitrary CheckBox";
102                         this.check1.Checked = false;
103
104                         this.opt1.Location = new Point(20, 160);
105                         this.opt1.Size = new Size(100, 20);
106                         this.opt1.Text = "CenterImage";
107
108                         this.opt2.Location = new Point(20,180);
109                         this.opt2.Size = new Size(100, 20);
110                         this.opt2.Text = "StretchImage";
111
112                         this.opt3.Location = new Point(20,200);
113                         this.opt3.Size = new Size(100, 20);
114                         this.opt3.Text = "Normal";
115
116                         this.frame1.Location = new Point(15, 140);
117                         this.frame1.Size = new Size (110, 85);
118                         this.frame1.Text = "Properties";
119
120                         this.pbox.Location = new Point (25, 28);
121                         this.pbox.Size = new Size(100, 100);
122
123                         //
124                         // Add you image name and path below
125                         // pbox.File = "/home/jstrike/Shared/7804.jpg";
126                         //
127
128                         this.Controls.AddRange(new System.Windows.Forms.Control[] { 
129                                                 this.button1,
130                                                 this.button2,
131                                                 this.copybutton,
132                                                 this.pastebutton,
133                                                 this.cutbutton,
134                                                 this.text1, 
135                                                 this.bar1, 
136                                                 this.check1,
137                                                 this.opt1,
138                                                 this.opt2,
139                                                 this.opt3,
140                                                 this.frame1,
141                                                 this.pbox,
142                                                 this.fdialog,
143                                                 this.vScrollBar1,
144                                                 this.hScrollBar1,
145                                                 this.label1 });
146
147                         this.Size = new Size(512, 250);
148                 }
149
150                 public GtkForm()
151                 {
152                         InitializeWidgets();
153                 }
154
155                 private void set_Text1_to_scrollbarvalues() {
156                         this.text1.Text = String.Format ("{0}, {1}", this.vScrollBar1.Value, this.hScrollBar1.Value);
157                         this.bar1.Value = this.hScrollBar1.Value;
158                 }
159
160                 private void vScrollBar1_ValueChanged (object sender, EventArgs e) { 
161                         this.set_Text1_to_scrollbarvalues ();
162                 }
163
164                 private void hScrollBar1_ValueChanged (object sender, EventArgs e) { 
165                         this.set_Text1_to_scrollbarvalues ();
166                 }
167
168
169                 private void copybutton_Click(object sender, EventArgs e){ 
170                         //text1.Select (1, 4);
171                         text1.Copy();
172                 }
173
174                 private void pastebutton_Click(object sender, EventArgs e){ 
175                         //text1.SelectAll();
176                         text1.Paste();
177                 }
178
179                 private void cutbutton_Click(object sender, EventArgs e){ 
180                         text1.Cut();
181                 }
182
183                 private void button1_Click(object sender, EventArgs e){ 
184                 
185                         pbox.File = fdialog.OpenFile;
186                                 if (this.opt2.Checked) { 
187                                         this.pbox.SizeMode = PictureBoxSizeMode.StretchImage;
188                                 }
189                                 if (this.opt1.Checked){
190                                         this.pbox.SizeMode = PictureBoxSizeMode.CenterImage;
191                                 }       
192                                 if (this.opt3.Checked){
193                                         this.pbox.SizeMode = PictureBoxSizeMode.Normal;
194                                 }       
195                 }
196
197                 private void button2_Click(object sender, EventArgs e){                                                         
198                         fdialog.ShowDialog();
199                         button1.Enabled = true;
200                 }
201
202                 }
203         
204         public class GtkMain
205         {
206                 public static void Main()
207                 {
208                         GtkForm form1 = new GtkForm ();
209                         form1.Text = "System.Windows.Forms at work!";                   
210                         Application.Run(form1);
211                 }
212         }
213 }