Interview FAQs

FAQs of level

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.

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
The Splitter control is used to resize other controls. The purpose of this is to save space on the form. This control can be very useful when you are working with controls both at design time and run time (which are not visible at design time).
To load a Picture into the PictureBox control drag a PictureBox control and a Command Button from the Toolbox. When you click the Command Button, the picture you specified will be loaded into the Picturebox. The following code is a demonstration -

PictureBox1.Image=Image.FromFile("C:\images\image.gif") //Assuming you have a folder named images in C: drive and a gif image in that

Docking is the property of the control to attach itself to a particular edge of the window (or other containing control). You can either dock a control to an edge or to fill the available space in the parent control or window.

Common examples of docking includes menu bar and toolbars which dock themselves at the top of the window so that they may remain at top regardless of the size and of the window.

Represents a Windows control that allows the user to select a date and a time and to display the date and time with a specified format.

Namespace: System.Windows.Forms

The DateTimePicker control is used to allow the user to select a date and time, and to display that date and time in the specified format. You can limit the dates and times that can be selected by setting the MinDate and MaxDate properties.

You can change the look of the calendar portion of the control by setting the CalendarForeColor, CalendarFont, CalendarTitleBackColor, CalendarTitleForeColor, CalendarTrailingForeColor, and CalendarMonthBackground properties.

The Format property sets the DateTimePickerFormat of the control. The default date Format is DateTimePickerFormat.Long. If the Format property is set to DateTimePickerFormat.Custom, you can create your own format style by setting the CustomFormat property and building a custom format string. The custom format string can be a combination of custom field characters and other literal characters. For example, you can display the date as "June 01, 2001 - Friday" by setting the CustomFormat property to "MMMM dd, yyyy - dddd".

To use a spin button control (also known as an up-down control) to adjust the date/time value, set the ShowUpDown property to true. The calendar control will not drop down when the control is selected. The date and time can be adjusted by selecting each element individually and using the up and down buttons to change the value.

Formats supported by DateTimePicker are -


Use this code -
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dateTimePicker1.CustomFormat = "dd/MM/yyyy";
this.dateTimePicker1.ShowUpDown = false;
dateTimePicker1.MinDate = DateTime.Today;
dateTimePicker1.MaxDate = DateTime.Today.AddYears( 1 );
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();

tb.Location = new Point( 10, 10);
tb.Size = new Size(100, 20);
tb.Text = "I was created at runtime";


Displaying 1 of 6Next
1 2 3 4 5 6
Need Help? Contact Us.

Log in


Forgot password?


New User