Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Controls and Events

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 59

Controls and Events

Radio Button

The RadioButton control is used to provide a set of


mutually exclusive options. The user can select one
radio button in a group. If you need to place more
than one group of radio buttons in the same form,
you should place them in different container controls
like a GroupBox control.
Radio Button Cont.…

The Checked property of the radio button is used to


set the state of a radio button. You can display text,
image or both on radio button control. You can also
change the appearance of the radio button control by
using the Appearance property.
Properties of the RadioButton Control

S.N Property Description

Gets or sets a value determining the


1 Appearance
appearance of the radio button.

Gets or sets a value indicating whether the


Checked value and the appearance of the
2 AutoCheck
control automatically change when the
control is clicked.

Gets or sets the location of the check box


3 CheckAlign
portion of the radio button.

Gets or sets a value indicating whether the


4 Checked
control is checked.

5 Text Gets or sets the caption for a radio button.

Gets or sets a value indicating whether a


6 TabStop user can give focus to the RadioButton
control using the TAB key.
Methods of the RadioButton Control

S.N Method Name & Description

PerformClick
1 Generates a Click event for the
control, simulating a click by a user.
Events of Radio Button Control

S.N Event Description

Occurs when the value of


the Appearance property
1 AppearanceChanged
of the RadioButton
control is changed.

Occurs when the value of


the Checked property of
2 CheckedChanged
the RadioButton control
is changed.
Example

In the following example, let us create two groups of radio buttons


and use their CheckedChanged events for changing the BackColor
and ForeColor property of the form.
Sample Code
When the above code is executed and run using Start button available at
the Microsoft Visual Studio tool bar, it will show the following window:
Picture Box Control

The PictureBox control is used for displaying images


on the form. The Image property of the control
allows you to set an image both at design time or at
run time.
Create a picture box by dragging a PictureBox
control from the Toolbox and dropping it on the
form.
Properties of the Picture Box Control

S.N Property Description


o
1. Error Gets or specifies an image to be displayed when an error occurs during the
Image image-loading process or if the image load is cancelled.

2.
Text Gets or sets the text for the picture box.

2.
Image Gets or sets the image that is displayed in the control.

3.
•Determines the size of the image to be displayed in the control. This
property takes its value from the PictureBoxSizeMode enumeration,
which has values:
•Normal - the upper left corner of the image is placed at upper left
part of the picture box
SizeMode •StrechImage - allows stretching of the image
•AutoSize - allows resizing the picture box to the size of the image
•CenterImage - allows centering the image in the picture box
•Zoom - allows increasing or decreasing the image size to maintain
the size ratio.
Methods of the PictureBox Control

S.N Method Name & Description

CancelAsync
1 Cancels an asynchronous image
load.

Load
2 Displays an image in the picture
box

LoadAsync
3
Loads image asynchronously.

ToString
Returns the string that
4
represents the current picture
box.
Events of the Picture Box Control
S.No Event Description
1. Occurs when the control is
Click
clicked.
2. Overrides the Control.Enter
Enter
property.
3. Occurs when the value of the
FontChanged
Font property changes.
4.
Occurs when the value of the
ForeColorChanged
ForeColor property changes.

5.
Occurs when a key is pressed
KeyDown
when the control has focus.

6.
Occurs when a key is pressed
KeyPress
when the control has focus.

7.
Occurs when a key is released
KeyUp
when the control has focus.

8. Occurs when the control is


Resize
resized.
9. Occurs when the Size property
SizeChanged
value changes.
Example

Public Class Form1


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
' Set the caption bar text of the form.
Me.Text = "Picture Element"
End Sub

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


Button1.Click
PictureBox1.ClientSize = New Size(300, 300)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
End Class
Progress Bar control

It represents a Windows progress bar control. It is


used to provide visual feedback to your users about
the status of some task. It shows a bar that fills in
from left to right as the operation progresses.
Progress Bar Cont.…

The main properties of a progress bar are Value,


Maximum and Minimum. The Minimum and
Maximum properties are used to set the minimum
and maximum values that the progress bar can
display. The Value property specifies the current
position of the progress bar.
Progress Bar Cont.…

The ProgressBar control is typically used when an


application performs tasks such as copying files or
printing documents. To a user the application might
look unresponsive if there is no visual cue. In such
cases, using the ProgressBar allows the programmer
to provide a visual status of progress.
Properties of Progress Bar

Property Description
Gets or sets the background image for the
BackgroundImage
ProgressBar control.
BackgroundImageLayo Gets or sets the layout of the background image
ut of the progress bar.
Gets or sets the maximum value of the range of
Maximum
the control.
Gets or sets the space between the edges of a
Padding
ProgressBar control and its contents.
Gets or sets the current position of the progress
Value
bar.
Gets or sets the time period, in milliseconds, that
MarqueeAnimationSpe
it takes the progress block to scroll across the
ed
progress bar.
Font Gets or sets the font of text in the ProgressBar.
Methods of the ProgressBar Control
Events of the ProgressBar Control

Event Description
Click Occurs when the control is clicked
Occurs when the user presses a key while the control has
KeyDown
focus.
Occurs when the user presses a key while the control has
KeyPress
focus.
Occurs when the user releases a key while the control has
KeyUp
focus.
MouseClick Occurs when the control is clicked by the mouse.
Paint Occurs when the ProgressBar is drawn.
Enter Occurs when focus enters the control.
TextChanged Occurs when the Text property changes.
Leave Occurs when focus leaves the ProgressBar control.
Example
Tree View Control

The TreeView control is used to display hierarchical


representations of items similar to the ways the files
and folders are displayed in the left pane of the
Windows Explorer. Each node may contain one or
more child nodes.
Properties of Tree View Control
Property Description
BackColor Gets or sets the background color for the control.
BackgroundIma Gets or set the background image for the TreeView
ge control.

Gets or sets a value indicating whether check boxes are


CheckBoxes
displayed next to the tree nodes in the tree view control.

Font Gets or sets the font of the text displayed by the control.

Gets the collection of tree nodes that are assigned to the


Nodes
tree view control.
Gets or sets a value indicating whether the tree view
Scrollable
control displays scroll bars when they are needed.
Text Gets or sets the text of the TreeView.
Gets the number of tree nodes that can be fully visible in
VisibleCount
the tree view control.
Gets or sets a value indicating whether the tree nodes in
Sorted
the tree view are sorted.
Methods of the Tree View Control
Events of Tree View Control
Events Cont.…
Example
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.
Use of Timer Control Contd…

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.
Timer Control
How timer Control Works

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.
Properties of Timer Control
Properties of Timer Control

Enabled - Property used to Get or set whether the


timer is running.

Interval - Property used to set or get the time in


millisecond between the timer clicks.
Methods and Events for Timer Control

Start – Method used to start timer


Stop – Method used to stop timer

Tick - Triggered when the time interval has elapsed.


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.
Example1

Public Class Form1 Private Sub Timer1_Tick(ByVal


sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Label1.Text = DateTime.Now.ToString
End Sub
End Class
Example 2
Public Class Form1
 Dim second As Integer
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
 Timer1.Interval = 1000
 Timer1.Start() 'Timer starts functioning
 End Sub
  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
 Label1.Text = DateTime.Now.ToString
  second = second + 1
 If second >= 10 Then
 Timer1.Stop() 'Timer stops functioning
 MsgBox("Timer Stopped....")
 End If
  End Sub
 End Class
Panel Introduction

The Panel control is a container of other controls.


The Panel control is displayed by default without any
borders at run time.
Panel Control

To move a control in the Windows Forms


Designer is very easy. Just click and drag the
control to its new position. In addition you can
drag controls in and out of container controls
(controls that contain, group, and help arrange
other controls).

These controls include FlowLayoutPanel,


TableLayoutPanel, GroupBox, Panel,
TabControl, and SplitContainer.
Panel Control

The Panel control just like a GroupBox, can also


contain the Radio Button controls in a Radio Button
group, but unlike a GroupBox control, the Panel
control doesn't display a visible border, so you
must use some other method to ensure that the user
can tell that the buttons are forming a group.
Properties of Panel
Example
Example (Transparent Panel)

Public Class Form2


 Private Sub Form2_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
 'change back color of Panel
 Panel1.BackColor = Color.Red
 'set Form's TransparencyKey to the same color as
Panel's back color
 Me.TransparencyKey = Color.Red
 End Sub
End Class
Panel Properties

BackColor: Panel BackColor can be changed


through BackColor property.

BorderStyle: Get or set BorderStyle of Panel.

Visible: You can hide all control inside panel


through visible property of Panel. If you want to hide
then set visible to false.
Backcolor

Private Sub Form3_Load(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
 'change panel backcolor
 Panel1.BackColor = Color.BlanchedAlmond
 End Sub
Border Style

Private Sub Form4_Load(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
 'set BorderStyle of panel
 Panel1.BorderStyle = BorderStyle.FixedSingle
End Sub
Visible

Private Sub Form25_Load(ByVal sender As


System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
 'hide panel
 Panel1.Visible = False
 End Sub
Folder Browser Dialog Control

Visual Basic offers a wide range of dialog boxes


that allow the user to make standard selections and
each of them has a very specific purpose.

The purpose of the FolderBrowserDialog is


selecting a folder (directory).

This control lets the user select a folder (directory)


in the file system. The dialog box is displayed by
calling the ShowDialog()
Folder Dialog Box
Creating a Folder Browser Dialog

We can create a FolderBrowserDialog control using a


Forms designer at design-time or using the
FolderBrowserDialog class in code at run-time (also
known as dynamically).
Example

Private Sub BrowseButton_Click(ByVal sender As


System.Object,ByVal e As System.EventArgs) Handles
BrowseButton.Click
          Dim folderDlg As New FolderBrowserDialog
        folderDlg.ShowNewFolderButton = True
        If (folderDlg.ShowDialog() = DialogResult.OK) Then
            TextBox1.Text = folderDlg.SelectedPath
            Dim root As Environment.SpecialFolder =
folderDlg.RootFolder
        End If
      End Sub
Dim folderDlg As New FolderBrowserDialog
ShowDialog method displays the
FolderBrowserDialog.
folderDlg.ShowDialog()
Once the ShowDialog method is called, you can
browse and select a file.
FolderBrowserDialog Properties
SelectedPath property represents the selected path
in a FolderBrowserDialog control.
RootFolder property represents the root folder
where the browsing starts from.

You might also like