Unit No 3 Ques-Ans
Unit No 3 Ques-Ans
1
CanOverflow : Gets or sets a value indicating whether the MenuStrip supports overflow
functionality.
2
GripStyle : Gets or sets the visibility of the grip used to reposition the control.
3
MdiWindowListItem : Gets or sets the ToolStripMenuItem that is used to display a list of
Multiple-document interface (MDI) child forms.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 2
4
ShowItemToolTips : Gets or sets a value indicating whether ToolTips are shown for the
MenuStrip.
5
Stretch : Gets or sets a value indicating whether the MenuStrip stretches from end to end in
its container.
1
MenuActivate : Occurs when the user accesses the menu with the keyboard or mouse.
2
MenuDeactivate : Occurs when the MenuStrip is deactivated.
If you have defined Mask for validating input or output, then each character position in Masked text box checks
the validation you provided. The Mask property does not allow you to enter Invalid Characters or input data into
the control.
If you try to enter data that is invalid according to Mask Applied, then the control generates Validation Error.
Now it will behave different from normal standard Text box control.
Steps
1. Click on Properties in Right-sidebar. It appears as shown in the image below
2. Click on Set Mask or directly click on Browse button
3. A dialog box appears put value according to your requirement in Mask labeled Textbox
4. Click Ok
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 3
The following are some of the commonly used properties of the TextBox control −
1
AcceptsReturn : Gets or sets a value indicating whether pressing ENTER in a multiline
TextBox control creates a new line of text in the control or activates the default button for the
form.
2
AutoCompleteCustomSource : Gets or sets a custom
System.Collections.Specialized.StringCollection to use when the AutoCompleteSourceproperty
is set to CustomSource.
3
AutoCompleteMode : Gets or sets an option that controls how automatic completion works for
the TextBox.
4
AutoCompleteSource : Gets or sets a value specifying the source of complete strings used
for automatic completion.
5
CharacterCasing : Gets or sets whether the TextBox control modifies the case of characters
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 4
6
Font : Gets or sets the font of the text displayed by the control.
7
FontHeight : Gets or sets the height of the font of the control.
8
ForeColor : Gets or sets the foreground color of the control.
9
Lines : Gets or sets the lines of text in a text box control.
10
Multiline : Gets or sets a value indicating whether this is a multiline TextBox control.
11
PasswordChar : Gets or sets the character used to mask characters of a password in a
single-line TextBox control.
12
ReadOnly : Gets or sets a value indicating whether text in the text box is read-only.
13
ScrollBars : Gets or sets which scroll bars should appear in a multiline TextBox control. This
property has values −
None
Horizontal
Vertical
Both
14
TabIndex : Gets or sets the tab order of the control within its container.
15
Text : Gets or sets the current text in the TextBox.
16
TextAlign : Gets or sets how text is aligned in a TextBox control. This property has values −
Left
Right
Center
17
TextLength : Gets the length of text in the control.
18
WordWrap : Indicates whether a multiline text box control automatically wraps words to the
beginning of the next line when necessary.
1
AppendText : Appends text to the current text of a text box.
2
Clear : Clears all text from the text box control.
3
Copy : Copies the current selection in the text box to the Clipboard.
4
Cut : Moves the current selection in the text box to the Clipboard.
5
Paste : Replaces the current selection in the text box with the contents of the Clipboard.
6
Paste(String) : Sets the selected text to the specified text without clearing the undo buffer.
7
ResetText : Resets the Text property to its default value.
8
ToString : Returns a string that represents the TextBoxBase control.
9
Undo : Undoes the last edit operation in the text box.
1
Click : Occurs when the control is clicked.
2
DoubleClick : Occurs when the control is double-clicked.
3
TextAlignChanged : Occurs when the TextAlign property value changes.
Example
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 6
1
AutoSizeMode : Gets or sets the mode by which the Button automatically resizes itself.
2
BackColor : Gets or sets the background color of the control.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 7
3
BackgroundImage : Gets or sets the background image displayed in the control.
4
DialogResult : Gets or sets a value that is returned to the parent form when the button is
clicked. This is used while creating dialog boxes.
5
ForeColor : Gets or sets the foreground color of the control.
6
Image : Gets or sets the image that is displayed on a button control.
7
Location : Gets or sets the coordinates of the upper-left corner of the control relative to the
upper-left corner of its container.
8
TabIndex : Gets or sets the tab order of the control within its container.
9
Text : Gets or sets the text associated with this control.
1
GetPreferredSize : Retrieves the size of a rectangular area into which a control can be fitted.
2
NotifyDefault : Notifies the Button whether it is the default button so that it can adjust its
appearance accordingly.
3
Select : Activates the control.
4
ToString : Returns a String containing the name of the Component, if any. This method should
not be overridden.
1
Click : Occurs when the control is clicked.
2
DoubleClick : Occurs when the user double-clicks the Button control.
3
GotFocus : Occurs when the control receives focus.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 8
4
TabIndexChanged : Occurs when the TabIndex property value changes.
5
TextChanged : Occurs when the Text property value changes.
6
Validated : Occurs when the control is finished validating.
6) Compare and contrast Radio button and Check box using Example
Radio button control Check Box control
If we were asking a user to select the highest If the user has to select the languages known to him or
qualification, it would be either PG or graduation or can be spoken by him, then the best option would be to
some other professional course. In that case, we have check boxes, as it’s quite possible for a person to
would go with a radio button. speak/know more than one language
If user clicks on OK button then it will return content of textbox in the form of string.
If user clicks on Cancel Button then it will return a blank value.
Here,
(1) Prompt is a compulsory argument. The String that you specify as a Prompt will display as a message in the
InputBox Dialog.
(2) Title is an optional Argument. The String that you specify as a Title will display in the title bar of the
InputBox. If you skip this argument then name of the application will display in the title bar.
(3) DefaultResponse is an Optional Argument. The String that you specify as a DefaultResponse will display as
a default value in the textbox of the InputBox. If you skip this argument then Textbox of the InputBox is
displayed empty.
(4) XPos is an Optional Argument. It Specify the distance (in pixel) of the left edge of the Input box from the left
edge of the screen.
(5) YPos is an Optional Argument. It Specify the distance (in pixel) of the upper edge of the Input box from the
top edge of the screen.
Note: If you skip XPos and YPos then InputBox will display in the centre of the screen.
MsgBox ( ) Function
The objective of MsgBox is to produce a pop-up message box and prompt the user to click on a command button
before he /she can continues. This format is as follows:
The first argument, Prompt, will display the message in the message box. The Style Value will determine what
type of command buttons appear on the message box, please refer to Table 12.1 for types of command button
displayed. The Title argument will display the title of the message board.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 10
0 vbOkOnly Ok button
We can use named constants in place of integers for the second argument to make the programs more readable.
For example:
MsgBox( "Click OK to Proceed", 1, "Startup Menu")
and
MsgBox("Click OK to Proceed". vbOkCancel,"Startup Menu")
are the same.
16 vbCritical
3 vbQuestion
48 vbExclamation
64 vbInformation
1
AddExtension : Gets or sets a value indicating whether the dialog box automatically adds
an extension to a file name if the user omits the extension.
2
CheckFileExists : Gets or sets a value indicating whether the dialog box displays a
warning if the user specifies a file name that does not exist.
3 CheckPathExists : Gets or sets a value indicating whether the dialog box displays a
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 12
4 CreatePrompt : Gets or sets a value indicating whether the dialog box prompts the user
for permission to create a file if the user specifies a file that does not exist.
6 DereferenceLinks : Gets or sets a value indicating whether the dialog box returns the
location of the file referenced by the shortcut or whether it returns the location of the
shortcut (.lnk).
7 FileName : Gets or sets a string containing the file name selected in the file dialog box.
8 FileNames : Gets the file names of all selected files in the dialog box.
9 Filter : Gets or sets the current file name filter string, which determines the choices that
appear in the "Save as file type" or "Files of type" box in the dialog box.
10 FilterIndex : Gets or sets the index of the filter currently selected in the file dialog box.
11 InitialDirectory : Gets or sets the initial directory displayed by the file dialog box.
12 OverwritePrompt : Gets or sets a value indicating whether the Save As dialog box
displays a warning if the user specifies a file name that already exists.
13 RestoreDirectory : Gets or sets a value indicating whether the dialog box restores the
current directory before closing.
14 ShowHelp : Gets or sets a value indicating whether the Help button is displayed in the file
dialog box.
17 ValidateNames : Gets or sets a value indicating whether the dialog box accepts only valid
Win32 file names.
Example
In this example, let's save the text entered into a rich text box by the user using the save file
dialog box. Take the following steps −
Drag and drop a Label control, a RichTextBox control, a Button control and a SaveFileDialog
control on the form.
Set the Text property of the label and the button control to 'We appreciate your comments' and
'Save Comments', respectively.
Double-click the Save Comments button and modify the code of the Click event as shown −
Properties of the
OpenFileDialog Control
The following are some of the
commonly used properties of the
OpenFileDialog control –
1
AddExtension: Gets or sets a value indicating whether the dialog box automatically
adds an extension to a file name if the user omits the extension.
2
AutoUpgradeEnabled: Gets or sets a value indicating whether this FileDialog instance
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 14
3
CheckFileExists : Gets or sets a value indicating whether the dialog box displays a
warning if the user specifies a file name that does not exist.
4
CheckPathExists: Gets or sets a value indicating whether the dialog box displays a
warning if the user specifies a path that does not exist.
5
CustomPlaces :Gets the custom places collection for this FileDialog instance.
6
DefaultExt : Gets or sets the default file name extension.
7
DereferenceLinks : Gets or sets a value indicating whether the dialog box returns the
location of the file referenced by the shortcut or whether it returns the location of the
shortcut (.lnk).
8
FileName : Gets or sets a string containing the file name selected in the file dialog box.
9
FileNames : Gets the file names of all selected files in the dialog box.
10
Filter : Gets or sets the current file name filter string, which determines the choices that
appear in the "Save as file type" or "Files of type" box in the dialog box.
11
FilterIndex : Gets or sets the index of the filter currently selected in the file dialog box.
12
InitialDirectory : Gets or sets the initial directory displayed by the file dialog box.
13
Multiselect : Gets or sets a value indicating whether the dialog box allows multiple files
to be selected.
14
ReadOnlyChecked : Gets or sets a value indicating whether the read-only check box is
selected.
15
RestoreDirectory : Gets or sets a value indicating whether the dialog box restores the
current directory before closing.
16
SafeFileName : Gets the file name and extension for the file selected in the dialog box.
The file name does not include the path.
17
SafeFileNames : Gets an array of file names and extensions for all the selected files in
the dialog box. The file names do not include the path.
18
ShowHelp : Gets or sets a value indicating whether the Help button is displayed in the
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 15
19
ShowReadOnly : Gets or sets a value indicating whether the dialog box contains a
read-only check box.
20
SupportMultiDottedExtensions : Gets or sets whether the dialog box supports
displaying and saving files that have multiple file name extensions.
21
Title : Gets or sets the file dialog box title.
22
ValidateNames : Gets or sets a value indicating whether the dialog box accepts only
valid Win32 file names.
1
OpenFile: Opens the file selected by the user, with read-only permission. The file is
specified by the FileName property.
2
Reset: Resets all options to their default value.
Example
In this example, let's load an image file in a picture box, using the open file dialog box. Take
the following steps −
Drag and drop a PictureBox control, a Button control and a OpenFileDialog control on the form.
Set the Text property of the button control to 'Load Image File'.
Double-click the Load Image File button and modify the code of the Click event:
Click on the Load Image File button to load an image stored in your computer
o GoTo Label- When Error is occur execution statement jump to the Specified
Label that is mention in “On Error Goto ..” Statement. The Label must be in the
same procedure or Event
o GoTo 0-Disables enabled exception handler in the current procedure and resets
to nothing
o GoTo -1 same above
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 17
o Resume Next- Specifies that when an error occurs, execution skips over the
statement that caused the problem and goes to the statement immediately
following. Execution continues from that point
End Try
End Sub
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 18
In the .Net Framework, exceptions are represented by classes. The exception classes in .Net
Framework are mainly directly or indirectly derived from the System.Exception class.
The System.SystemException class is the base class for all predefined system exception.
The following table provides some of the predefined exception classes derived from the
Sytem.SystemException class –
1
AllowSimulations : Gets or sets a value indicating whether the dialog box allows graphics
device interface (GDI) font simulations.
2
AllowVectorFonts : Gets or sets a value indicating whether the dialog box allows vector font
selections.
3
AllowVerticalFonts : Gets or sets a value indicating whether the dialog box displays both
vertical and horizontal fonts, or only horizontal fonts.
4
Color : Gets or sets the selected font color.
5
FixedPitchOnly : Gets or sets a value indicating whether the dialog box allows only the
selection of fixed-pitch fonts.
6
Font : Gets or sets the selected font.
7
FontMustExist : Gets or sets a value indicating whether the dialog box specifies an error
condition if the user attempts to select a font or style that does not exist.
8
MaxSize : Gets or sets the maximum point size a user can select.
9
MinSize : Gets or sets the minimum point size a user can select.
10
ScriptsOnly : Gets or sets a value indicating whether the dialog box allows selection of fonts
for all non-OEM and Symbol character sets, as well as the ANSI character set.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 20
11
ShowApply : Gets or sets a value indicating whether the dialog box contains an Apply
button.
12
ShowColor : Gets or sets a value indicating whether the dialog box displays the color choice.
13
ShowEffects : Gets or sets a value indicating whether the dialog box contains controls that
allow the user to specify strikethrough, underline, and text color options.
14
ShowHelp : Gets or sets a value indicating whether the dialog box displays a Help button.
1
Reset : Resets all options to their default values.
2
RunDialog : When overridden in a derived class, specifies a common dialog box.
3
ShowDialog : Runs a common dialog box with a default owner.
1
Apply : Occurs when the Apply button on the font dialog box is clicked.
Example
In this example, let's change the font and color of the text from a rich text control using the
Font dialog box. Take the following steps −
Drag and drop a RichTextBox control, a Button control and a FontDialog control on the
form.
Set the Text property of the button control to 'Change Font'.
Set the ShowColor property of the FontDialog control to True.
Double-click the Change Color button and modify the code of the Click event −
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 21
Using RichTextBox user can format only selected portion of the text. User can also format
paragraph using RichTextBox Control.
RichTextBox Control also allows user to save as well as load file of RTF format and
Standard ASCII format.
Properties of RichTextBox
Property Purpose
Enabled It is used to specify weather RichTextBox Control is enabled or not at run time. It
has Boolean value. Default value is true.
Font It is used to set Font Face, Font Style, Font Size and Effects of the text
associated with RichTextBox Control.
ForeColor It is used to get or set Fore color of the text associated with RichTextBox
Control.
MaxLength It is used to get or set maximum number of characters that can be entered in
RichTextBox. Default value is 2147483647.
Multiline It is used to specify weather RichTextBox can be expanded to enter more than
one line of text or not. It has Boolean value. Default value is true.
ScrollBars It is used to get or set type of scrollbars to be added with RichTextBox control. It
has following 4 options:
(1) None (2) Horizontal (3) Vertical (3) Both Default value is Both.
Size It is used to get or set height and width of RichTextBox control in pixel.
Visible It is used to specify weather RichTextBox Control is visible or not at run time. It
has Boolean value. Default value is true.
WordWrap It is used to specify weather line will be automatically word wrapped while
entering multiple line of text in RichTextBox control or not. It has Boolean value.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 23
SelectionAlignment It is used to get or set horizontal alignment of the text selected in RichTextBox.
SelectionBullet It is used to get or set value which determines weather bullet style should be
applied to selected text or not.
SelectionColor It is used to get or set Fore Color of the text selected in RichTextBox.
SelectionFont It is used to get or set font face, font style, and font size of the text selected in
RichTextBox.
SelectionStart It is used to get or set starting point of the text selected in the RichTextBox.
Methods of RichTextBox
Method Purpose
Paste It is used to replace current selection of TextBox by contents of clipboard. It is also used
to move contents of Clipboard to RichTextBox control where cursor is currently located.
AppendText It is used to append text at the end of current text in RichTextBox Control.
ClearUndo It is used to clear information from the Undo buffer of the RichTextBox.
Find It is used to find starting position of first occurrence of a string in the RichTextBox control.
If a string is not found then it returns -1.
SaveFile It is used to save contents of RichTextBox in to Rich Text Format (RTF) file.
LoadFile It is used to loads a Rich Text Format (RTF) file or standard ASCII text file into
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 24
RichTextBox Control.
Redo It is used to redo the last operation that is undo using undo method.
Events of RichTextBox
Event Purpose
TextChanged It is the default event of RichTextBox Control. It fires each time a text in the
RichTextBox control changed.
The CheckBox control has three states, checked, unchecked and indeterminate. In the
indeterminate state, the check box is grayed out. To enable the indeterminate state,
the ThreeState property of the check box is set to be True.
1
Appearance : Gets or sets a value determining the appearance of the check box.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 25
2
AutoCheck : Gets or sets a value indicating whether the Checked or CheckedState
value and the appearance of the control automatically change when the check box
is selected.
3
CheckAlign : Gets or sets the horizontal and vertical alignment of the check mark
on the check box.
4
Checked : Gets or sets a value indicating whether the check box is selected.
5
CheckState : Gets or sets the state of a check box.
6
Text : Gets or sets the caption of a check box.
7
ThreeState :Gets or sets a value indicating whether or not a check box should
allow three check states rather than two.
1
OnCheckedChanged : Raises the CheckedChanged event.
2
OnCheckStateChanged : Raises the CheckStateChanged event.
3
OnClick : Raises the OnClick event.
1
AppearanceChanged : Occurs when the value of the Appearance property of the
check box is changed.
2
CheckedChanged : Occurs when the value of the Checked property of the
CheckBox control is changed.
3
CheckStateChanged : Occurs when the value of the CheckState property of the
CheckBox control is changed.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 26
The Timer Control starts its functioning only after its Enabled property is set to True, by default
Enabled property is False.
Timer example
Here is an example for start and stop methods of the Timer Control. In this example we run this
program only 10 seconds. So we start the Timer in the Form_Load event and stop the Timer after
10 seconds. We set timer Interval property as 1000 milliseconds ( 1 second) and in run time the
Timer will execute 10 times its Tick event
19) Explain Image List control with its properties and methods
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 28
The ImageList is a simple control that stores images used by other controls at runtime. For
example, a TreeView control can use icons to identify its nodes. The simplest and quickest
method of preparing these images is to create an ImageList control and add to it all the icons
you need for decorating the TreeView control’s nodes. The ImageList control maintains a
series of bitmaps in memory that the TreeView control can access quickly at runtime. Keep in
mind that the ImageList control can’t be used on its own and remains invisible at runtime.
Method of adding images to an ImageList control is to call the Add method of the
Images collection, which contains all the images stored in the control. To add an image at
runtime, you must first create an Image object with the image (or icon) you want to add to the
control and then call the Add method as follows:
ImageList1.Images.Add(Image.FromFile(path))
The Images collection of the ImageList control is a collection of Image objects, not the files in
which the pictures are stored. This means that the image files need not reside on the computer
on which the application will be executed, as long as they have been added to the collection at
design time.
You almost certainly use Windows applications that can open multiple documents at the same
time and allow the user to switch among them with a mouse-click. Multiple Word is a typical
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 29
example, although most people use it in single document mode. Each document is displayed in its
own window, and all document windows have the same behavior. The main Form, or MDI Form,
isn't duplicated, but it acts as a container for all the windows, and it is called the parent window.
The windows in which the individual documents are displayed are called Child windows.
An MDI application must have at least two Form, the parent Form and one or more child Forms.
Each of these Forms has certain properties. There can be many child forms contained within the
parent Form, but there can be only one parent Form.
SDI
This is a term which is known as Single Document Interface and is a Graphic User Interface which
is able to show one document at a time on the screen. Any type of program which does not have
the ability to show more than one document is considered to be and SDI type of user interface.
There are many examples of this type such as internet explorer 6 and the ones before that.
Notepad is another example where you can just show one window at a time and windows
command is another similar application. The main advantage of this type of interface is that it is
simple to use and a complicated task can be performed in an easy manner without switching from
one app to the other.