4 using System
.Windows
.Forms
;
6 using System
.Threading
;
8 namespace MonoTests
.System
.Windows
.Forms
11 public class EventClass
13 static bool eventhandled
= false;
14 public static void Event_Handler1 (object sender
, EventArgs e
)
20 public void BackColorChangedTest ()
22 Control c
= new Control ();
23 // Test BackColorChanged Event
24 c
.BackColorChanged
+= new EventHandler (Event_Handler1
);
25 c
.BackColor
= Color
.Black
;
26 Assert
.AreEqual (true, eventhandled
, "#A1");
31 public void BgrndImageChangedTest ()
33 Control c
= new Control ();
34 // Test BackgroundImageChanged Event
35 c
.BackgroundImageChanged
+= new EventHandler (Event_Handler1
);
38 c
.BackgroundImage
= Image
.FromFile (abc
);
39 Assert
.AreEqual (true, eventhandled
, "#A2");
43 public void BindingContextChangedTest ()
45 Control c
= new Control ();
46 // Test BindingContextChanged Event
47 c
.BindingContextChanged
+= new EventHandler (Event_Handler1
);
48 BindingContext bcG1
= new BindingContext ();
50 c
.BindingContext
= bcG1
;
51 Assert
.AreEqual (true, eventhandled
, "#A3");
56 public void CausesValidationChangedTest ()
58 Control c
= new Control ();
59 // Test CausesValidationChanged Event
60 c
.CausesValidationChanged
+= new EventHandler (Event_Handler1
);
62 c
.CausesValidation
= false;
63 Assert
.AreEqual (true, eventhandled
, "#A4");
68 public void CursorChangedTest ()
70 Control c
= new Control ();
71 // Test CursorChanged Event
72 c
.CursorChanged
+= new EventHandler (Event_Handler1
);
74 c
.Cursor
= Cursors
.Hand
;
75 Assert
.AreEqual (true, eventhandled
, "#A6");
79 public void DisposedTest ()
81 Control c
= new Control ();
82 // Test Disposed Event
83 c
.Disposed
+= new EventHandler (Event_Handler1
);
86 Assert
.AreEqual (true, eventhandled
, "#A7");
90 public void DockChangedTest ()
92 Control c
= new Control ();
93 // Test DockChanged Event
94 c
.DockChanged
+= new EventHandler (Event_Handler1
);
96 c
.Dock
= DockStyle
.Bottom
;
97 Assert
.AreEqual (true, eventhandled
, "#A8");
101 public void EnabledChangedTest ()
103 Control c
= new Control ();
104 // Test EnabledChanged Event
105 c
.EnabledChanged
+= new EventHandler (Event_Handler1
);
106 eventhandled
= false;
108 Assert
.AreEqual (true, eventhandled
, "#A9");
112 public void FontChangedTest ()
114 Control c
= new Control ();
115 // Test FontChanged Event
116 c
.FontChanged
+= new EventHandler (Event_Handler1
);
117 eventhandled
= false;
118 c
.Font
= new Font (c
.Font
, FontStyle
.Bold
);
119 Assert
.AreEqual (true, eventhandled
, "#A11");
123 public void ForeColorChangedTest ()
125 Control c
= new Control ();
126 // Test ForeColorChanged Event
127 c
.ForeColorChanged
+= new EventHandler (Event_Handler1
);
128 eventhandled
= false;
129 c
.ForeColor
= Color
.Red
;
130 Assert
.AreEqual (true, eventhandled
, "#A12");
134 public void HandleCreatedTest ()
136 Control c
= new Control ();
137 // Test HandleCreated Event
138 c
.HandleCreated
+= new EventHandler (Event_Handler1
);
139 eventhandled
= false;
141 Assert
.AreEqual (true, eventhandled
, "#A15");
145 public void ImeModeChangedTest ()
147 Control c
= new Control ();
148 // Test ImeModeChanged Event
149 c
.ImeModeChanged
+= new EventHandler (Event_Handler1
);
150 eventhandled
= false;
151 c
.ImeMode
= ImeMode
.Off
;
152 Assert
.AreEqual (true, eventhandled
, "#A19");
156 public void LocationChangedTest ()
158 Control c
= new Control ();
159 // Test LocationChanged Event
160 c
.LocationChanged
+= new EventHandler (Event_Handler1
);
161 eventhandled
= false;
163 Assert
.AreEqual (true, eventhandled
, "#A20");
167 public void ResizeTest ()
169 Control c
= new Control ();
171 c
.Resize
+= new EventHandler (Event_Handler1
);
172 eventhandled
= false;
174 Assert
.AreEqual (true, eventhandled
, "#A22");
178 public void RightToLeftChangedTest ()
180 Control c
= new Control ();
181 // Test RightToLeftChanged Event
182 c
.RightToLeftChanged
+= new EventHandler (Event_Handler1
);
183 eventhandled
= false;
184 c
.RightToLeft
= RightToLeft
.Yes
;
185 Assert
.AreEqual (true, eventhandled
, "#A23");
189 public void SizeChangedTest ()
191 Control c
= new Control ();
192 // Test SizeChanged Event
193 c
.SizeChanged
+= new EventHandler (Event_Handler1
);
194 eventhandled
= false;
196 Assert
.AreEqual (true, eventhandled
, "#A24");
200 public void TabIndexChangedTest ()
202 Control c
= new Control ();
203 // Test TabIndexChanged Event
204 c
.TabIndexChanged
+= new EventHandler (Event_Handler1
);
205 eventhandled
= false;
207 Assert
.AreEqual (true, eventhandled
, "#A27");
211 public void TabStopChangedTest ()
213 Control c
= new Control ();
214 // Test TabStopChanged Event
215 c
.TabStopChanged
+= new EventHandler (Event_Handler1
);
216 eventhandled
= false;
218 Assert
.AreEqual (true, eventhandled
, "#A28");
222 public void TextChangedTest ()
224 Control c
= new Control ();
225 // Test TextChanged Event
226 c
.TextChanged
+= new EventHandler (Event_Handler1
);
227 eventhandled
= false;
228 c
.Text
= "some Text";
229 Assert
.AreEqual (true, eventhandled
, "#A29");
233 public void VisibleChangedTest ()
235 Control c
= new Control ();
236 // Test VisibleChanged Event
237 c
.VisibleChanged
+= new EventHandler (Event_Handler1
);
238 eventhandled
= false;
240 Assert
.AreEqual (true, eventhandled
, "#A30");
246 public class LayoutEventClass
248 static bool eventhandled
= false;
249 public static void LayoutEvent (object sender
, LayoutEventArgs e
)
255 public void LayoutTest ()
257 Control c
= new Control ();
258 c
.Layout
+= new LayoutEventHandler (LayoutEvent
);
259 eventhandled
= false;
262 Assert
.AreEqual (true, eventhandled
, "#D1");
267 int size_changed_event
;
270 void resize (object sender
, EventArgs e
)
272 resize_event
= ++event_count
;
275 void layout (object sender
, LayoutEventArgs le
)
277 layout_event
= ++event_count
;
280 void size_changed (object sender
, EventArgs e
)
282 size_changed_event
= ++event_count
;
286 public void LayoutResizeTest ()
288 Control c
= new Control ();
289 c
.Layout
+= new LayoutEventHandler (layout
);
290 c
.Resize
+= new EventHandler (resize
);
291 c
.SizeChanged
+= new EventHandler (size_changed
);
292 c
.Size
= new Size (100, 100);
293 Assert
.AreEqual (1, layout_event
, "1");
294 Assert
.AreEqual (2, resize_event
, "2");
295 Assert
.AreEqual (3, size_changed_event
, "3");
300 public class ControlAddRemoveEventClass
302 static bool eventhandled
= false;
303 public static void ControlEvent (object sender
, ControlEventArgs e
)
309 public void ControlAddedTest ()
311 Control c
= new Control ();
312 c
.ControlAdded
+= new ControlEventHandler (ControlEvent
);
313 TextBox TB
= new TextBox ();
314 eventhandled
= false;
316 Assert
.AreEqual (true, eventhandled
, "#F1");
320 public void ControlRemovedTest ()
322 Control c
= new Control ();
323 c
.ControlRemoved
+= new ControlEventHandler (ControlEvent
);
324 TextBox TB
= new TextBox ();
326 eventhandled
= false;
327 c
.Controls
.Remove (TB
);
328 Assert
.AreEqual (true, eventhandled
, "#F2");
333 public class ControlRefresh
342 public void HandleNotCreated ()
344 Control c
= new Control ();
345 c
.Invalidated
+= new InvalidateEventHandler (Control_Invalidated
);
349 Assert
.AreEqual (0, invalidated
, "#1");
353 Assert
.AreEqual (0, invalidated
, "#2");
357 [Category ("NotWorking")]
358 public void Visible ()
360 Control c
= new Control ();
361 c
.Invalidated
+= new InvalidateEventHandler (Control_Invalidated
);
364 Form form
= new Form ();
365 form
.ShowInTaskbar
= false;
366 form
.Controls
.Add (c
);
369 Assert
.AreEqual (0, invalidated
, "#1");
372 Assert
.AreEqual (1, invalidated
, "#2");
375 Assert
.AreEqual (1, invalidated
, "#3");
379 public void NotVisible ()
381 Control c
= new Control ();
382 c
.Invalidated
+= new InvalidateEventHandler (Control_Invalidated
);
385 Form form
= new Form ();
386 form
.ShowInTaskbar
= false;
387 form
.Controls
.Add (c
);
390 Assert
.AreEqual (0, invalidated
, "#1");
393 Assert
.AreEqual (0, invalidated
, "#2");
396 Assert
.AreEqual (0, invalidated
, "#3");
399 private void Control_Invalidated (object sender
, InvalidateEventArgs e
)
404 private int invalidated
;