/[dotgnu-pnet]/pnetlib/samples/FormsHello.cs
ViewVC logotype

Contents of /pnetlib/samples/FormsHello.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (show annotations) (download)
Tue Dec 23 22:07:08 2003 UTC (20 years, 4 months ago) by uid66024
Branch: MAIN
CVS Tags: HEAD
Changes since 1.16: +0 -0 lines
FILE REMOVED
Re-sync against offline CVS server - see ChangeLog for details.

1 /*
2 * FormsHello.cs - Sample program for Forms.
3 *
4 * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
5 *
6 * This program is free software, you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY, without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program, if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 using System;
22 using System.Drawing;
23 using System.Drawing.Drawing2D;
24 using System.Windows.Forms;
25
26 public class FormsHello : Form
27 {
28 private Button button;
29 private ProgressBar progress;
30 private int msgNum;
31 private ToolBar toolbar;
32 private ScrollBar scrollbar;
33 private CheckBox checkbox;
34
35 private FormsHello()
36 {
37 // Force the entire form to repaint when it is resized.
38 SetStyle(ControlStyles.ResizeRedraw, true);
39
40 // Set some initial form properties.
41 Size = new Size(400, 270);
42 Text = "Forms Hello";
43
44 // Create a button control on the form.
45 button = new Button();
46 button.Text = "Click Me!";
47 button.Location = new Point(30, 130);
48 Controls.Add(button);
49
50 // Create a progress bar control
51 progress = new ProgressBar();
52 progress.Location = new Point(30, 175);
53 progress.Anchor = AnchorStyles.Top |
54 AnchorStyles.Left |
55 AnchorStyles.Right;
56 Controls.Add(progress);
57
58 // Create a label and dock it to the bottom.
59 Label label = new Label();
60 label.Text = "This is a label, docked to the bottom ...";
61 label.BackColor = Color.White;
62 label.Dock = DockStyle.Bottom;
63 Controls.Add(label);
64
65 // Hook up interesting events.
66 Paint += new PaintEventHandler(HandlePaint);
67 button.Click += new EventHandler(HandleClick);
68
69 // Create a scrollbar control.
70 scrollbar = new HScrollBar();
71 scrollbar.Dock = DockStyle.Bottom;
72 Controls.Add(scrollbar);
73 scrollbar = new VScrollBar();
74 scrollbar.Dock = DockStyle.Right;
75 Controls.Add(scrollbar);
76
77 // Create a toolbar control and some toolbar buttons.
78 toolbar = new ToolBar();
79 toolbar.Buttons.Add("Hello");
80 ToolBarButton tbb = new ToolBarButton();
81 tbb.Style = ToolBarButtonStyle.Separator;
82 toolbar.Buttons.Add(tbb);
83 tbb = new ToolBarButton("World!");
84 toolbar.Buttons.Add(tbb);
85 toolbar.Appearance = ToolBarAppearance.Flat;
86 toolbar.BorderStyle = BorderStyle.FixedSingle;
87 Controls.Add(toolbar);
88
89 // Create another toolbar.
90 // This reveals some layout bugs, so
91 // the Controls.Add is commented out
92 // to keep the sample looking good
93 toolbar = new ToolBar();
94 toolbar.Buttons.Add("This one's");
95 tbb = new ToolBarButton();
96 tbb.Style = ToolBarButtonStyle.Separator;
97 toolbar.Buttons.Add(tbb);
98 tbb = new ToolBarButton("left docked.");
99 tbb.Style = ToolBarButtonStyle.DropDownButton;
100 toolbar.Buttons.Add(tbb);
101 toolbar.BorderStyle = BorderStyle.Fixed3D;
102 toolbar.Dock = DockStyle.Left;
103 //toolbar.DropDownArrows = false;
104 //Controls.Add(toolbar);
105
106 checkbox=new CheckBox();
107 checkbox.Location=new Point(70,95);
108 checkbox.Text="Any Good ?";
109 checkbox.Checked=true;
110 checkbox.CheckStateChanged += new EventHandler(HandleCheck);
111 Controls.Add(checkbox);
112 }
113
114 private void HandlePaint(Object sender, PaintEventArgs e)
115 {
116 Graphics graphics = e.Graphics;
117 Form form = (sender as Form);
118 Rectangle bounds = form.ClientRectangle;
119
120 Pen pen = new Pen(Color.Black, 1.0f);
121 graphics.DrawLine(pen, 0, 0, bounds.Width, bounds.Height - 23);
122 pen.Dispose();
123
124 pen = new Pen(Color.Red, 2.0f);
125 graphics.DrawRectangle
126 (pen, 10, 10, bounds.Width - 20, bounds.Height - 40);
127 pen.Dispose();
128
129 ControlPaint.DrawFocusRectangle
130 (graphics,
131 new Rectangle(15, 15, bounds.Width - 30, bounds.Height - 50));
132
133 Brush brush = new SolidBrush(Color.Yellow);
134 graphics.FillPie(brush, 20, 20, 60, 60, 30.0f, 70.0f);
135 brush.Dispose();
136
137 Font font = new Font("Arial", 12);
138 brush = new SolidBrush(Color.Blue);
139 graphics.DrawString("Hello", font, brush, 30, 100);
140 brush.Dispose();
141 font.Dispose();
142
143 brush = new HatchBrush
144 (HatchStyle.BackwardDiagonal, Color.Black, Color.White);
145 graphics.FillEllipse(brush, 200, 40, 100, 100);
146 brush.Dispose();
147 }
148
149 private static readonly String[] Messages = {
150 "I've been clicked!",
151 "Oww! That hurts!",
152 "Stop it!",
153 "Thank you sir! May I have another?"
154 };
155
156 private void HandleClick(Object sender, EventArgs e)
157 {
158 Console.WriteLine(Messages[msgNum]);
159 msgNum = (msgNum + 1) % Messages.Length;
160 progress.PerformStep();
161 }
162
163 private void HandleCheck(Object sender, EventArgs e)
164 {
165 bool check=(sender as CheckBox).Checked;
166 Console.WriteLine(check ? "You changed your mind ? , Good.." :
167 "Naaw , didn't think so..");
168
169 }
170
171 public static void Main(String[] args)
172 {
173 FormsHello form = new FormsHello();
174 Application.Run(form);
175 }
176 }

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26