0% found this document useful (0 votes)
16 views29 pages

Unit No 3 Ques-Ans

This document provides an overview of various Windows controls in VB.NET, including properties, methods, and events for controls like MenuStrip, TextBox, Button, RadioButton, CheckBox, InputBox, MsgBox, and SaveFileDialog. It explains the functionalities and usage of these controls with examples and descriptions of their properties and events. The document serves as a guide for understanding how to implement and utilize these controls in VB.NET applications.

Uploaded by

ethvg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views29 pages

Unit No 3 Ques-Ans

This document provides an overview of various Windows controls in VB.NET, including properties, methods, and events for controls like MenuStrip, TextBox, Button, RadioButton, CheckBox, InputBox, MsgBox, and SaveFileDialog. It explains the functionalities and usage of these controls with examples and descriptions of their properties and events. The document serves as a guide for understanding how to implement and utilize these controls in VB.NET applications.

Uploaded by

ethvg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

VB.NET UNIT NO.

3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 1

1) What is use of word wrap property?


Indicates whether a multiline text box control automatically wraps words to the beginning of the next
line when necessary.

2) Explain Menu control using example


The MenuStrip control represents the container for the menu structure. The MenuStrip control works as
the top-level container for the menu structure. The ToolStripMenuItem class and the
ToolStripDropDownMenu class provide the functionalities to create menu items, sub menus and drop-
down menus. The following diagram shows adding a MenuStrip control on the form

Sr.No. Property & Description

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.

Events of the MenuStrip Control


The following are some of the commonly used events of the MenuStrip control −

Sr.No. Event & Description

1
MenuActivate : Occurs when the user accesses the menu with the keyboard or mouse.

2
MenuDeactivate : Occurs when the MenuStrip is deactivated.

3) Explain Masked Textbox


Masked TextBox Control in .NET is used to restrict the input from user . Masked Edit controls are also
used to change the format of output that is to be delivered. Masked Text box control is similar to a simple Text
box control. But it provides access to mask or change the format of input as well as output.

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

4) Explain Textbox and Button controls.


Text box controls allow entering text on a form at runtime. By default, it takes a single line of text,
however, you can make it accept multiple texts and even add scroll bars to it.
Let's create a text box by dragging a Text Box control from the Toolbox and dropping it on the form.

The Properties of the TextBox Control

The following are some of the commonly used properties of the TextBox control −

Sr.No. Property & Description

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

as they are typed.

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.

The Methods of the TextBox Control


The following are some of the commonly used methods of the TextBox control −
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 5

Sr.No. Method Name & Description

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.

Events of the TextBox Control


The following are some of the commonly used events of the Text control −

Sr.No. Event & Description

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

5) Explain Button controls.


The Button control represents a standard Windows button. It is generally used to generate a Click event
by providing a handler for the Click event.
Let's create a label by dragging a Button control from the Toolbox ad dropping it on the form.

Properties of the Button Control


The following are some of the commonly used properties of the Button control −
Sr.No. Property & Description

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.

Methods of the Button Control


The following are some of the commonly used methods of the Button control −
Sr.No. Method Name & Description

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.

Events of the Button Control


The following are some of the commonly used events of the Button control −

Sr.No. Event & Description

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

Radio button allows only one option to be selected


check box allows one or many options to be selected
out of several available options

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

Check box have 3 states:Checked, Unchecked,


Radio button have only 2 states: True, False
Indeterminate

7) Explain Input Box and Message Box in details


InputBox function display a prompt in the form of dialog box as shown below and waits for the user to
input some value in textbox or click a button.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 9

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.

InputBox (Prompt As String,[Title As String=""], [DefaultResponse As


String=""], [XPos As Integer = -1], [YPos As integer = -1] ) As String

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:

MsgBox(Prompt, Style Value, Title)

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

Style Value Named Constant Buttons Displayed

0 vbOkOnly Ok button

1 vbOkCancel Ok and Cancel buttons

2 vbAbortRetryIgnore Abort, Retry and Ignore buttons.

3 vbYesNoCancel Yes, No and Cancel buttons

4 vbYesNo Yes and No buttons

5 vbRetryCancel Retry and Cancel buttons

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.

Table 12.2 : Return Values and Command Buttons


Value Named Constant Button Clicked
1 vbOk Ok button
2 vbCancel Cancel button
3 vbAbort Abort button
4 vbRetry Retry button
5 vbIgnore Ignore button
6 vbYes Yes button
7 vbNo No button
Example
Dim testmsg As Integer
testmsg = MsgBox("Click to test", 1, "Test message")
If testmsg = 1 Then
MessageBox.Show("You have clicked the OK button")
Else
MessageBox.Show("You have clicked the Cancel button")
End If
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 11

Value Named Constant Icon

16 vbCritical

3 vbQuestion

48 vbExclamation

64 vbInformation

8) Explain save file dialog boxes in detail


The SaveFileDialog control prompts the user to select a location for saving a file and allows the user to specify
the name of the file to save data. The SaveFileDialog control class inherits from the abstract class FileDialog.
Following is the Save File dialog box –

Properties of the SaveFileDialog Control


The following are some of the commonly used properties of the SaveFileDialog control −
Sr.No. Property & Description

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

warning if the user specifies a path that does not exist.

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.

5 DefaultExt : Gets or sets the default file name extension.

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.

15 SupportMultiDottedExtensions : Gets or sets whether the dialog box supports


displaying and saving files that have multiple file name extensions.

16 Title : Gets or sets the file dialog box title.

17 ValidateNames : Gets or sets a value indicating whether the dialog box accepts only valid
Win32 file names.

Methods of the SaveFileDialog Control


The following are some of the commonly used methods of the SaveFileDialog control −

Sr.No. Method Name & Description

1 OpenFile : Opens the file with read/write permission.

2 Reset : Resets all dialog box options to their default values.


VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 13

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 −

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
SaveFileDialog1.Filter = “TXT Files (*.txt*)|*.txt"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
RichTextBox1.SaveFile(SaveFileDialog1.FileName,PlainText)
End If
End Sub

9) Explain open file dialog box in detail


The OpenFileDialog control prompts the user to open a file and allows the user to select a file to
open. The user can check if the file exists and then open it. The OpenFileDialog control class inherits
from the abstract class FileDialog.
If the ShowReadOnly property is set to True, then a read-only check box appears in the dialog box.
You can also set the ReadOnlyChecked property to True, so that the read-only check box appears
checked. Following is the Open File dialog box −

Properties of the
OpenFileDialog Control
The following are some of the
commonly used properties of the
OpenFileDialog control –

Sr.No. Property & Description

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

should automatically upgrade appearance and behavior when running on Windows


Vista.

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

file dialog box.

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.

Methods of the OpenFileDialog Control


The following are some of the commonly used methods of the OpenFileDialog control −

Sr.No. Method Name & Description

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:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
If OpenFileDialog1.ShowDialog = DialogResult.ok Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
When the application is compiled and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window −
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 16

Click on the Load Image File button to load an image stored in your computer

10) Explain Unstructured Exception handling in VB.Net


o Code is difficult to read, debug and maintain
o Errors may be overlooked
Syntax:
On Error GoTo [Label| Resume Next

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

11) Explain Structured Exception handling in VB.Net


An exception is a problem that arises during the execution of a program. An exception is a
response to circumstance that arises while a program is running, such as an attempt to divide by
zero.
Exceptions provide a way to transfer control from one part of a program to another. VB.Net exception
handling is built upon four keywords - Try, Catch, Finally and Throw.
 Try − A Try block identifies a block of code for which particular exceptions will be activated. It's
followed by one or more Catch blocks. We can implement Nested Try…Catch block also.
 Catch − A program catches an exception with an exception handler at the place in a program
where you want to handle the problem. The Catch keyword indicates the catching of an
exception.
 Finally − The Finally block is used to execute a given set of statements, whether an error is
occur or not occur. For example, if you open a file, it must be closed whether an exception is
raised or not, to destroy object and close database connection objects.
 Throw – Throw is generally used in User Define Function or in Procedure. When any error is
occur in UDF, it Throw the Exception and that is Catch by its calling part. A program throws an
exception when a problem shows up. This is done using a Throw keyword.
Syntax
Try
[ tryStatements ]
[ Exit Try ]
[ Catch [ exception [ As type ] ] [ When expression ]
[ catchStatements ]
[ Exit Try ] ]
[ Catch ... ]
[ Finally
[ finallyStatements ] ]
End Try
EXAMPLE
Sub division(ByVal num1 As Integer, ByVal num2 As Integer)
Dim result As Integer
Try
result = num1 \ num2
Catch ex As DivideByZeroException
Msgbox(ex.Message)
Finally

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 –

Exception Class Description

System.IO.IOException Handles I/O errors.

System.IndexOutOfRangeException Handles errors generated when a method refers to an


array index out of range.

System.ArrayTypeMismatchException Handles errors generated when type is mismatched with


the array type.

System.NullReferenceException Handles errors generated from deferencing a null object.

System.DivideByZeroException Handles errors generated from dividing a dividend with


zero.

System.InvalidCastException Handles errors generated during typecasting.

System.OutOfMemoryException Handles errors generated from insufficient free memory.

System.StackOverflowException Handles errors generated from stack overflow.

12) Explain Structured Exception handling in VB.Net


visible property make the control visible or invisible means physical appearance
Enable property, control will visible physically but we can do any changes if it set to false.

13) What is the use of Catch block in Try…Catch statement?


When any error is occur in try block, execution pointer will directly jump to that specified Catch block
and it is use to handle the error and shows the user about that error.

14) Explain Font and Color dialog boxes in detail


It prompts the user to choose a font from among those installed on the local computer and lets the
user select the font, font size, and color. It returns the Font and Color objects.
Following is the Font dialog box −
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 19

By default, the Color ComboBox is not


shown on the Font dialog box. You should
set the ShowColor property of the
FontDialog control to be True.

Properties of the FontDialog


Control
The following are some of the commonly
used properties of the FontDialog control −

Sr.No. Property & Description

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.

Methods of the FontDialog Control


The following are some of the commonly used methods of the FontDialog control −

Sr.No. Method Name & Description

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.

Events of the FontDialog Control


The following are some of the commonly used events of the FontDialog control −
Sr.No. Event & Description

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

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
If FontDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
RichTextBox1.ForeColor = FontDialog1.Color
RichTextBox1.Font = FontDialog1.Font
End If
End Sub

15) What is event?


Events are basically a user action like key press, clicks, mouse movements, etc., or some occurrence
like system generated notifications. Applications need to respond to events when they occur.
Clicking on a button, or entering some text in a text box, or clicking on a menu item, all are examples
of events. An event is an action that calls a function or may cause another event. Event handlers are
functions that tell how to respond to an event.
VB.Net is an event-driven language. There are mainly two types of events −
 Mouse events
 Keyboard events

Handling Mouse Events


Mouse events occur with mouse movements in forms and controls. Following are the various mouse
events related with a Control class −
 MouseDown − it occurs when a mouse button is pressed
 MouseEnter − it occurs when the mouse pointer enters the control
 MouseHover − it occurs when the mouse pointer hovers over the control
 MouseLeave − it occurs when the mouse pointer leaves the control
 MouseMove − it occurs when the mouse pointer moves over the control
 MouseUp − it occurs when the mouse pointer is over the control and the mouse button is
released
 MouseWheel − it occurs when the mouse wheel moves and the control has focus

Handling Keyboard Events


Following are the various keyboard events related with a Control class −
 KeyDown − occurs when a key is pressed down and the control has focus
 KeyPress − occurs when a key is pressed and the control has focus
 KeyUp − occurs when a key is released while the control has focus

15) Explain Properties, Methods and events of Rich TextBox control.


 RichTextBox Control allows user to display, input, edit and format text information.
 RichTextBox Control supports advance formatting features as compared to TextBox.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 22

 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

AutoWordSelection It is used to specify weather automatic word selection is ON or OFF. It has


Boolean value. Default value is false.

BackColor It is used to get or set background color of the RichTextBox.

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.

ReadOnly It is used to specify weather text associated with RichTextBox is ReadOnly or


not. It has Boolean value. Default value is false.

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.

Text It is used to get or set text associated with RichTextBox Control.

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

Default value is true.

SelectedText It is used to get or set currently selected text in RichTextBox.

SelectionAlignment It is used to get or set horizontal alignment of the text selected in RichTextBox.

SelectionBackColor It is used to get or set BackColor 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.

SelectionLength It is used to get or set number of characters selected in the RichTextBox.

SelectionStart It is used to get or set starting point of the text selected in the RichTextBox.

Methods of RichTextBox
Method Purpose

Cut It is used to move current selection of RichTextBox into clipboard.

Copy It is used to copies selected text of RichTextBox in clipboard.

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.

Select It is used to select specific text from RichTextBox.

SelectAll It is used to select all text of RichTextBox.

DeselectAll It is used to deselect all text selected in RichTextBox.

Clear It is used to clear all text from RichTextBox Control.

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.

Undo It is used to undo last edit operation of RichTextBox.

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.

16) Explain CheckBox control.


The CheckBox control allows the user to set true/false or yes/no type options. The user can select or
deselect it. When a check box is selected it has the value True, and when it is cleared, it holds the
value False.

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.

Properties of the CheckBox Control


The following are some of the commonly used properties of the CheckBox control −
Sr.No. Property & Description

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.

Methods of the CheckBox Control


The following are some of the commonly used methods of the CheckBox control −

Sr.No. Method Name & Description

1
OnCheckedChanged : Raises the CheckedChanged event.

2
OnCheckStateChanged : Raises the CheckStateChanged event.

3
OnClick : Raises the OnClick event.

Events of the CheckBox Control


The following are some of the commonly used events of the CheckBox control −
Sr.No. Event & Description

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

16) Explain Timer control.


Timer Control plays an important role in the Client side programming and Server side programming,
also used in Windows Services. By using this Timer Control, windows allow you to control when
actions take place without the interaction of another thread.

Use of Timer Control

We can use Timer Control in many situations in our


development environment. If you want to run some code after a
certain interval of time continuously, you can use the Timer
control. As well as to start a process at a fixed time schedule, to
increase or decrease the speed in an animation graphics with time schedule etc. you can use the
Timer Control. The Visual Studio toolbox has a Timer Control that allowing you to drag and drop the
timer controls directly onto a Windows Forms designer. At runtime it does not have a visual
representation and works as a component in the background.

How to Timer Control ?

With the Timer Control, we can control programs in


millisecond, seconds, minutes and even in hours. The
Timer Control allows us to set Interval property in milliseconds (1 second is equal to 1000
milliseconds). For example, if we want to set an interval of two minute we set the value at Interval
property as 120000, means 120x1000 .

The Timer Control starts its functioning only after its Enabled property is set to True, by default
Enabled property is False.

Timer example

The following program shows a Timer example


that display current system time in a Label
control. For doing this, we need one Label control
and a Timer Control. Here in this program, we
can see the Label Control is updated each
seconds because we set Timer Interval as 1
second, that is 1000 milliseconds. After drag and
drop the Timer Control in the designer form , double click the Timer control and set the
DateTime.Now.ToString to Label control text property.

Start and Stop Timer Control


We can control the Timer Control Object that when it start its function as well as when it stop its
function. The Timer Control has a start and stop methods to perform these actions.
VB.NET UNIT NO. 3 INTRODUCTION TO WINDOWS CONTROL (QUESTION-ANSWER) 27

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

17) List out various container control in VB.Net.


Panel, GroupBox, FlowLayout, SplitContainer, TableLayout, Toolstrip.

18) Describe Properties, methods, Events.


Properties which describe the object,
Methods cause an object to do something and
Events are what happens when an object does something.

19) What is use of Multiline and word wrap property of textbox?


Multiline : Gets or sets a value indicating whether this is a multiline TextBox control.
wordwrap: Indicates whether a multiline text box control automatically wraps words to the
beginning of the next line when necessary.

19) What is use of Multiline and word wrap property of textbox?


There's little difference between Design Time and Run Time components. Design
Time means the component can be used in a programming environment such as Visual
Basic when the developer is designing an application. Run time is when the application is
actually running (executing)

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.

20) What is MDI and SDI? Explain in details


The Multiple Document Interface (MDI) was designed to simplify the exchange of information
among documents, all under the same roof. With the main application, you can maintain multiple
open windows, but not multiple copies of the application. Data exchange is easier when you can
view and compare many documents simultaneously.

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.

Difference Between MDI and SDI


MDI SDI
Full Name Multiple Document Interface Single Document Interface
It is the type of Graphic User Interface It is a Graphic User Interface which
which is able to show more than a is able to show one document at a
Type
single document at a time on the time on the screen.
screen.
All the documents can be maximized in There needs to be a special
Maximization the MDI command in order to maximize the
documents.
Example Latest web browsers. windows notepad

You might also like