8b43e8eeb6c1f6006d3efbd1e341c7b8666962f4
[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                         this.vScrollBar1.ForeColor = Color.Brown;
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                         this.button2.Location = new Point(150, 85);
63                         this.button2.Name = "button2";
64                         this.button2.Size = new Size(128, 44);
65                         this.button2.Text = "File";
66                         this.button2.Click += new EventHandler(this.button2_Click); 
67
68                         this.copybutton.Click += new EventHandler(this.copybutton_Click); 
69                         this.pastebutton.Click += new EventHandler(this.pastebutton_Click); 
70                         this.cutbutton.Click += new EventHandler(this.cutbutton_Click); 
71
72                         this.copybutton.Location = new Point(320, 80); 
73                         this.pastebutton.Location = new Point(320, 100); 
74                         this.cutbutton.Location = new Point(320, 120);
75
76                         this.copybutton.Size = new Size(150, 20); 
77                         this.pastebutton.Size = new Size(150, 20); 
78                         this.cutbutton.Size = new Size(150, 20); 
79
80                         this.copybutton.Text ="Copy";
81                         this.pastebutton.Text ="Paste";
82                         this.cutbutton.Text ="Cut";
83
84                         this.text1.Location = new Point(320,48);
85                         this.text1.Name = "textBox1";
86                         this.text1.Size = new Size(150, 22);
87                         this.text1.Text = this.button1.Name;
88
89                         this.bar1.Location = new Point(0, 230);
90                         this.bar1.Size = new Size(512, 20);
91                         this.bar1.Text = "This is a ProgressBar";
92                         this.bar1.Value = 25;
93
94                         this.label1.Location = new Point(330, 20);
95                         this.label1.Text = "This is a Label";   
96
97                         this.check1.Location = new Point(150, 160);
98                         this.check1.Size = new Size(180, 20);
99                         this.check1.Text = "arbitrary CheckBox";
100                         this.check1.Checked = false;
101
102                         this.opt1.Location = new Point(20, 160);
103                         this.opt1.Size = new Size(100, 20);
104                         this.opt1.Text = "CenterImage";
105
106                         this.opt2.Location = new Point(20,180);
107                         this.opt2.Size = new Size(100, 20);
108                         this.opt2.Text = "StretchImage";
109
110                         this.opt3.Location = new Point(20,200);
111                         this.opt3.Size = new Size(100, 20);
112                         this.opt3.Text = "Normal";
113
114                         this.frame1.Location = new Point(15, 140);
115                         this.frame1.Size = new Size (110, 85);
116                         this.frame1.Text = "Properties";
117
118                         this.pbox.Location = new Point (25, 28);
119                         this.pbox.Size = new Size(100, 100);
120
121                         //
122                         // Add you image name and path below
123                         // pbox.File = "/home/jstrike/Shared/7804.jpg";
124                         //
125
126                         this.Controls.AddRange(new System.Windows.Forms.Control[] { 
127                                                 this.button1,
128                                                 this.button2,
129                                                 this.copybutton,
130                                                 this.pastebutton,
131                                                 this.cutbutton,
132                                                 this.text1, 
133                                                 this.bar1, 
134                                                 this.check1,
135                                                 this.opt1,
136                                                 this.opt2,
137                                                 this.opt3,
138                                                 this.frame1,
139                                                 this.pbox,
140                                                 this.fdialog,
141                                                 this.vScrollBar1,
142                                                 this.hScrollBar1,
143                                                 this.label1 });
144
145                         this.Size = new Size(512, 250);
146                 }
147
148                 public GtkForm()
149                 {
150                         InitializeWidgets();
151                 }
152
153                 private void set_Text1_to_scrollbarvalues() {
154                         this.text1.Text = String.Format ("{0}, {1}", this.vScrollBar1.Value, this.hScrollBar1.Value);
155                         this.bar1.Value = this.hScrollBar1.Value;
156                 }
157
158                 private void vScrollBar1_ValueChanged (object sender, EventArgs e) { 
159                         this.set_Text1_to_scrollbarvalues ();
160                 }
161
162                 private void hScrollBar1_ValueChanged (object sender, EventArgs e) { 
163                         this.set_Text1_to_scrollbarvalues ();
164                 }
165
166
167                 private void copybutton_Click(object sender, EventArgs e){ 
168                         //text1.Select (1, 4);
169                         text1.Copy();
170                 }
171
172                 private void pastebutton_Click(object sender, EventArgs e){ 
173                         //text1.SelectAll();
174                         text1.Paste();
175                 }
176
177                 private void cutbutton_Click(object sender, EventArgs e){ 
178                         text1.Cut();
179                 }
180
181                 private void button1_Click(object sender, EventArgs e){ 
182                 
183                         pbox.File = fdialog.OpenFile;
184                                 if (this.opt2.Checked) { 
185                                         this.pbox.SizeMode = PictureBoxSizeMode.StretchImage;
186                                 }
187                                 if (this.opt1.Checked){
188                                         this.pbox.SizeMode = PictureBoxSizeMode.CenterImage;
189                                 }       
190                                 if (this.opt3.Checked){
191                                         this.pbox.SizeMode = PictureBoxSizeMode.Normal;
192                                 }       
193                 }
194
195                 private void button2_Click(object sender, EventArgs e){                                                         
196                         fdialog.ShowDialog();
197                         button1.Enabled = true;
198                 }
199
200                 }
201         
202         public class GtkMain
203         {
204                 public static void Main()
205                 {
206                         GtkForm form1 = new GtkForm ();
207                         form1.Text = "System.Windows.Forms at work!";                   
208                         Application.Run(form1);
209                 }
210         }
211 }