300+ TOP Windows Controls Interview Questions and Answers

Q1. How Can You Enable A Text Box To Change Its Characters Format, So That Users Can Enter Password?

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 = ‘*’;

Q2. What Is The Maskedtextbox Control? What Does The Mask Property Do?

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.

Q3. How Would You Create An Ellipse, Which Is A Non- Rectangular Window?

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.

Q4. What Is Use Of The Dropdownstyle Property Of The Combobox Control?

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.

Q5. Define The Trackbar Control?

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.

Q6. What Is The Use Of A Toolstrip Container?

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.

Q7. How Can We Disable The Context Menu For A Textbox Control?

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.

Q8. How Do We Format Numbers, Dates, And Currencies In A Text Box?

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.

Q9. What Is The Use Of The Panel Control? Does It Display At Runtime?

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.

Q10. Why Do You Require User-defined Controls?

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

Q11. What Is The Importance Of A Button 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.

Q12. How Can You Prevent Users Of An Application From Editing The Text In The Combobox Controls In .net 4.0?

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;

Q13. What Does The Tick Frequency Property Of The Trackbar Control Do?

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

Q14. How Does An Mdi Form Differ From A Standard Form?

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.

Q15. How Can We Display An Icon Or A Bitmap Image On The Button Control?

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.

Q16. How Can You Place A Border Around A Picture Box?

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.

Q17. What Is The Difference Between A Menustrip Control And A Contextmenustrip Control?

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.

Q18. Is It Possible To Enter More Than One Line In A Textbox Control?

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;

Q19. How Can You Enforce A Text Box To Display Characters In Uppercase?

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;

Q20. How Can We Auto Size A Button To Fit Its Text?

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.

Q21. How Is Anchoring Different From Docking?

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.

Q22. Differentiate Between A Textbox Control And Richtextbox 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.

Q23. What Is The Difference Between The Panel And Groupbox 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

Q24. What Is The Difference Between A Toolstrip Drop-down Button And A Toolstrip Split Button?

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.

Q25. What Is The Difference Between Pixels, Points, And Em’s When Fonts Are Displayed?

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.

Q26. What Is The Difference Between The Windows Default Location And Windows Default Bounds Properties?

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.

Q27. What Is The Function Of The Checkstate Property Of The Checkbox Control?

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.

Q28. How Do You Retrieve The Customized Properties Of A .net Application From The Xml .config File?

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.

Q29. Write A Method To Get Only The Name Of A File From The Complete Path String In C#?

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.

Q30. What Is The Use Of A Timer Control? Can A Timer Control Pause?

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.

Q31. How Can You Programmatically Position The Cursor On A Given Line Or On A Character In The Richtextbox Control In C#?

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); }

Q32. What Is The Function Of The Sizemode Property Of The Picturebox Control?

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.

Q33. Describe The Tooltip Control. How Can You Associate It With Other Controls?

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.

Q34. What Is The Difference Between A Listbox Control And A Combobox Control?

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.

Q35. How Can You Adjust The Height Of A Combo Box Drop-down List?

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.

Q36. What Is Die Difference Between A Checkbox Control And A Radiobutton Control?

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.

Q37. What Are The Values That Can Be Assigned To The Dialogresult Property Of A Button Control?

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