|
|
|
|
|
Winforms Interview Questions / FAQs |
|
|
| What are win form controls? How they are represented in .NET framework class library? |
| A form may contain various user interface (UI) controls. The controls represent the visual components that allow user to interact with the application and perform the desired task. All the controls, in .Net, are represented by subclasses of System.Windows.Forms.Control class. Each form has a collection (named Controls) to store the constituent controls of the form. In fact, a form itself is a special type of control called Container Control, i.e., the Form class itself is derived from the ContainerControl class which is a subclass of the Control class. A container control, as the name suggests, may contain other controls. Other examples of the Container control include Panel and Tab Control. Each control, and thus form, exposes a number of events that can be triggered on certain user action or application behavior. For example, a button raises Click event whenever it is clicked and the text box raises the TextChanged event whenever its text is changed. The application developer can write even handler to catch these events and perform corresponding action. Beside these, a form also has certain set of events called the form life cycle events. These events are triggered during the life cycle of form to indicate the current state of the form. |
|
|
|
|
|
| What are the fundamental and common properties of .Net controls? |
| Almost all the controls have some similar properties like Location, Size, Enabled, Visible, TabIndex, Name, Text, BacKColor, ForeColor, Font, etc. The TabIndex property is very important. It describes the sequence followed by the windows focus when the user presses the Tab button of keyboard |
|
|
|
|
|
| How can I add a control to a Window Form at runtime? |
| To add a control at runtime, you do three steps:
1. Create the control
2. Set control properties
3. Add the control to the Forms Controls collection
Here are code snippets that create a textBox at runtime.
//step 1
TextBox tb = new TextBox();
//step2
tb.Location = new Point( 10, 10);
tb.Size = new Size(100, 20);
tb.Text = "I was created at runtime";
//step3
this.Controls.Add(tb); |
|
|
|
|
|
| What control do I use to insert Separator lines between Controls in my Dialog? |
| Use the Label Control with the BorderStyle set to Fixed3D and height set to 2. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|