Monday, 8 December 2014

Windows Controls – .NET Interview Questions and Answers

31. How can you attach a horizontal scroll bar with the ListBox control?
You need to set the the MultiColumn property of the ListBox control to True to attach a horizontal scroll bar with it.
32. What is the difference between the Add() and Insert() methods of a ListBox control?
The Add() method simply adds an item into the list box; whereas, the Insert() method inserts an item at the specified index.
33. Consider a situation where you have added panels in a StatusBar control; however, they are not displayed at run time. What could be the reason for this?
To display panels in the StatusBar control, the ShowPanels property needs to be set totrue.
34. What is the function of the SizeMode property of the PictureBox control?
The SizeMode property determines how the picture will be displayed in the PictureBoxcontrol. The following five enumerations are used to set the value of the SizeModeproperty:
  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 PictureBoxcontrol; 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 PictureBoxcontrol, by maintaining the aspect ratio of the image
35. How can you prevent users of an application from editing the text in the ComboBoxcontrols 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: SimpleDropDownList, 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;
36. Which class manages the event and layout of all ToolStrip elements?
The ToolStripItem class manages the event and layout of all elements that the ToolStripcontrol contains.
37. 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.
38. 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.
39. 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.
40. Is it possible to add an image on the RadioButton control?
Yes, you can add an image on the RadioButton control by setting the Image property.
41. What is the use of a toolstrip container?
A toolstrip container is used to contain controls, such as ToolStripMenuStrip, andStatusStrip, so that these controls can be docked and moved at the run time.
42. Name the methods, available in .NET 4.0, that are used to add and delete items from aListBox control?
The following methods can be used to add and delete items from a ListBox control. TheItems.Add() and Items.Insert() methods are used to add items; whereas, theItems.Remove()Items.RemoveAt(), and Items.Clear() methods are used to delete items from a ListBox control.

No comments:

Post a Comment