Top 37 Windows Controls Interview Questions You Must Prepare 20.Apr.2024

You can set the PasswordChar property of the TextBox class to True to enable it to accept passwords. The code to change the PasswordChar property of the TextBox class is given as follows:

textBox1.PasswordChar = '*';

The MaskedTextBox control is an improvement of the TextBox control. It forces the user to provide the proper input, which is specified by the Mask property. In other words, it prevents the user to provide any invalid input to an application. The Mask property gets or sets the input type to the MaskedTextBox control. There are many built-in formats for the Mask property, such as phone no., short date, time, zip code, and custom.

Open a new Windows form, which is by default rectangular in design and then set the TransparencyKey property to the same value as BackColor, which will effectively make the background of the form transparent. Then, set the FormBorderStyle property to FormBorderStyle.None, which removes the contour and contents of the form.

The DropDownStyle property changes the style of the ComboBox control. It consists of Simple, DropDown, and DropDownList as its values. When you select Simple, the list of items are displayed as a ListBox control. When you select DropDown, the list is displayed in a drop down style. When you select DropDownList, the list displayed in a drop down style and you cannot edit its text.

The TrackBar control, also known as the slider control, works as a navigator to display a large amount of information or for visual adjustment of numeric setting. There are two parts in a TrackBar control - thumb (also known as slider) and tick marks. The thumb part acts as a slider. You can adjust the thumb part using the Value property. The tick marks are visual indicators that are spaced at regular intervals.

A toolstrip container is used to contain controls, such as ToolStrip, MenuStrip, and StatusStrip, so that these controls can be docked and moved at the run time.

The TextBox class contains the ContextMenuStrip property. When we set this property to a dummy instance of the ContextMenu class, the TextBox control is unable to provide any context menu on the right-click of the mouse.

Each type has a ToString() method that can used to format date, currencies, and numbers. You can also use the String.Format() method to format these things as well. To format dates, use the ToString() member of the DateTime type.

Panels acts as a container to group other controls. It is an important control, when you want to show/hide a group of controls and relocate a number of controls simultaneously.

When you generate a new control at runtime, it works as a container control. As we know, it is a container control; therefore, it is not displayed at runtime.

User-defined controls are particularly useful in situations where you need to enhance the functionality of an existing control.

A Button control is an important Windows control, which provides the most common way of creating and handling an event in the code with the help of its Click event.

The ComboBox class contains the DropDownStyle property, which is used to define the display style of the items in the ComboBox control. The DropDownStyle property accepts a value from the ComboBoxStyle enumeration, which contains three members to define the styles for the items: Simple, DropDownList, and DropDown. The DropDownList value of the ComboBoxStyle enumeration is selected to set a ComboBox control as non-editable by users, as shown in the following code snippets:

Code for VB:

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList

Code for C#:

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

The Tick Frequency property gets or sets a value that specifies the distance between ticks. By default, the distance between ticks is 1.

An MDI form closely resembles a standard form with one major difference-the client area of an MDI form acts as a container for other forms. It means that an MDI form, also known as an MDI parent form, can display MDI child forms inside it.

The Button class contains the Image property, which is used to set an image on the Button control. We can also set the alignment of the image by using the Image Align property of the Button class.

The PictureBox control offers the BorderStyle property, which can be set to define the style of its border. This property can accept any of the three values from Fixed3D, FixedSingle, or None. These properties can be easily set through code or through the Properties window of the Visual Studio IDE.

The difference between a MenuStrip control and a ContextMenuStrip control is that a MenuStrip control is associated with the Windows Form; whereas, a ContextMenuStrip control is associated with a control, which is added to the Windows Form.

Yes, it is possible to enter more than one line in a TextBox control. To do this, you need to set the Multiline property of the TextBox control to True. You can set this property at design time as well as runtime.

The syntax to set this property at runtime is as follows:

Textbox1.Multiline = true;

The TextBox class contains the CharacterCasing property, which is used to specify the case of the content for a text box. This property accepts a value from the CharacterCasing enumeration of .NET Framework. The members specified in the CharacterCasing enumeration are Lower, Upper, and Normal. You can select any one of these enumerations as a value for the CharacterCasing property of a specified text box, as shown in the following code snippet:

textBox1.CharacterCasing = CharacterCasing.Upper;

The Button control has the AutoSize property, which can be set to true or false. If we set the value of the AutoSize property to true, then the button control automatically alters its size according to the content displayed on it.

Docking refers to attaching a control to either an edge (top, right, bottom, or left) or the client area of the parent control. On the other hand, anchoring is a process in which you need to specify the distance that each edge of your control maintains from the edges of the parent control.

The TextBox control is an input control, which allows a user to enter text to an application at runtime. By default, it allows only single line text; however, you can change its property to accept the multiline text as well as scroll bar also.

The RichTextBox control is similar to the TextBox control with the difference that it allows the user to format its text also. You can format the text in various ways, such as bold, italic, and underlined as well as change its color and font. You can save your RichTextBox value to a RTF (Rich Text Format) file and load value of RTF file to the RichTextBox control.

The Panel and GroupBox controls both can be used as a container for other controls, such as radio buttons and check box. The main differences between a Panel and a GroupBox control are as follows:

  • Panel does not display captions, while GroupBox do
  • Panel has scrollbar, while GroupBox does not

The difference between a toolstrip drop-down button and a toolstrip split button is that a toolstrip split button is a combination of two controls - a push button and a drop-down button; whereas, a toolstrip drop-down button is a single control.

A pixel is the lowest-resolution dot that the computer monitor supports. Its size depends on user's settings and the size of the monitor. A point is always 1/72 of an inch. An em is the number of pixels it takes to display the letter M.

The Windows Default Location property makes the form to start up at a location selected by the operating system, but with internally specified size. The Windows Default Bounds property delegates both size and starting position choices to the operating system.

The CheckState property gets or sets the state of CheckBox.

If the ThreeState property is set to false, the CheckState property value can only be set to CheckState.Indeterminate in code and not by user interaction.

Checked - The CheckBox displays a check mark. The control appears sunken.

Unchecked - The CheckBox is empty. The control appears raised.

Indeterminate - The CheckBox displays a check mark and is shaded.

Initialize an instance of the AppSettingsReader class. Call the GetValue() method of the AppSettingsReader class, passing in the name of the property and the type expected. Finally, assign the result to the appropriate variable.

Use a FileInfo class and instantiate its object with the full path as the constructor argument and then simply call the FileInfo.Name file and you will get just the name of the file.

The Timer control is a mechanism to perform an iterative task at a specified time interval. You cannot pause it because it can only start and stop.

The RichTextBox control contains the Lines array property, which displays one item of an array in a separate line. Each line entry has a Length property,

which can be used to accurately position the cursor at a character, as shown in the following code snippet:

private void GoToLineAndColumn(RichTextBox RTB, int Line, int Column)

{

 int offset = 0;

 for(int i = 0; i < Line -1 && i < RTB.Lines.Length; i++)

 {

 offset += RTB.Lines[i].Length + 1;

 }

 RTB.Focus();

 RTB.Select(offset + Column, 0);

}

The SizeMode property determines how the picture will be displayed in the PictureBox control. The following five enumerations are used to set the value of the SizeMode property:

  1. Normal - Represents Standard picture box behavior (the upper-left corner of the image is placed at upper-left in the picture box)
  2. StretchImage - Displays image according the PictureBox size
  3. AutoSize - Increases or decreases the picture size automatically as per the actual size of the PictureBox control.
  4. CenterImage - Displays the image in the center if it is smaller than the PictureBox control; otherwise, the center part of the image is placed in the PictureBox control and its outside edges are clipped
  5. Zoom - Helps in stretching or shrinking the image so that it fits the PictureBox control, by maintaining the aspect ratio of the image.

The ToolTip control generates a small pop-up window with explanatory text for an element It is displayed when the user pauses the mouse for a certain period over an element/control. Tool tips provide a quick help to user to understand about that element. To associate a tool tip with other control, you need to implement the SetToolTip() method.

With a ListBox control, the user can only make a selection from a list of items; whereas, with a ComboBox control, the user can make a selection from the list of items as well as can add custom entry and select the same.

You can control the height of a combo box drop-down list by setting the MaxDropDownItems property of the combo box. The MaxDropDownItems property sets the maximum number of entries that will be displayed by the drop-down list.

A CheckBox control is square shaped; whereas, a RadioButton control is round in shape. Moreover, you can select more than one CheckBox control from a group of CheckBox controls; whereas, you can select only a single RadioButton control from a group of RadioButton controls.

The DialogResult property of a Button control can be assigned a value from the DialogResult enumerations, which are as follows:

  • Abort-Returns Abort
  • Cancel-Returns Cancel
  • Ignore-Returns Ignore
  • No-Returns No
  • None-Nothing is returned from the dialog box
  • OK-Returns OK
  • Retry-Returns Retry
  • Yes-Returns Yes