C# Unit4
C# Unit4
LinkButton Click, Command It is used to create a button that looks similar to the
hyperlink.
ListBox SelectedIndexCnhaged It is used to create a ListBox control like the HTML control.
DataGrid CancelCommand, It used to create a frid that is used to show data. We can
EditCommand, also perform paging, sorting, and formatting very easily
DeleteCommand, with this control.
ItemCommand,
SelectedIndexChanged,
PageIndexChanged,
SortCommand,
UpdateCommand,
ItemCreated,
ItemDataBound
CheckBoxList SelectedIndexChanged It is used to create a group of check boxes that all work
together.
Label Control
Next comes the Label Control. The label control is used to display a text
or a message to the user on the form. The label control is normally used
along with other controls. Common examples are wherein a label is
added along with the textbox control.
The label indicates to the user on what is expected to fill up in the
textbox.
Button
The Windows Forms Button control allows the user to click it to perform
an action. The Button control· can display both text and images. When
the button is clicked, it looks as if it is being pushed in and released.
Whenever the user clicks a button, the Click event handler is invoked.
You place code in the Click event handler to perform any action you
choose.
The text displayed on the button is contained in the Text property.
List box
A Listbox is used to showcase a list of items on the Windows form. Let’s
see how we can implement this with an example shown below. We will
add a list box to the form to store some city locations.
RadioButton
A Radiobutton is used to showcase a list of items out of which the user
can choose one. Let’s see how we can implement this with an example
shown below. We will add a radio button for a male/female option.
Checkbox
A checkbox is used to provide a list of options in which the user can
choose multiple choices. Let’s see how we can implement this with an
example shown below. We will add 2 checkboxes to our Windows forms.
These checkboxes will provide an option to the user on whether they
want to learn C# or ASP.Net.
Button
A button is used to allow the user to click on a button which would then
start the processing of the form. Let’s see how we can implement this
with an example shown below. We will add a simple button called
‘Submit’ which will be used to submit all the information on the form.
Tool tips:
A tooltip is a small pop-up window that displays some information when
you rollover on a control.
Creating a Tooltip
Tooltip class represents a tooltip control. Once a Tooltip object is
created, we need to call SetToolTip method and pass a control and text.
The following code snippet creates a Tooltip and attaches to a Button
control using SetToolTip method.
ToolTip toolTip1 = newToolTip();
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(button1, "Click me to execute.");
Tooltip Properties
Active: A tooltip is currently active.
AutomaticDelay: Automatic delay for the tooltip.
AutoPopDelay: The period of time the ToolTip remains visible if the
pointer is stationary on a control with specified ToolTip text.
InitialDelay: Gets or sets the time that passes before the ToolTip
appears.
IsBaloon: Gets or sets a value indicating whether the ToolTip should
use a balloon window.
ReshowDelay: Gets or sets the length of time that must transpire
before subsequent ToolTip windows appear as the pointer moves
from one control to another.
ShowAlways: Displays if tooltip is displayed even if the parent
control is not active.
ToolTipIcon: Icon of tooltip window.
ToolTipTitle: Title of tooltip window.
UseAnimation: Represents whether an animation effect should be
used when displaying the tooltip.
UseFading: Represents whether a fade effect should be used when
displaying the tooltip.
Mouse Events:
Mouse Events
There are several kinds of mouse events:
Click
This event occurs when the mouse button is released, typically before the
MouseUp event. The handler for this event receives an argument of type
EventArgs. Handle this event when you only need to determine when a
click occurs.
MouseClick
This event occurs when the user clicks the control with the mouse. The
handler for this event receives an argument of type MouseEventArgs.
Handle this event when you need to get information about the mouse
when a click occurs.
DoubleClick
This event occurs when the control is double-clicked. The handler for
this event receives an argument of type EventArgs. Handle this event
when you only need to determine when a double-click occurs.
MouseDoubleClick
This event occurs when the user double-clicks the control with the
mouse. The handler for this event receives an argument of type
MouseEventArgs. Handle this event when you need to get information
about the mouse when a double-click occurs.
MouseDown
This event occurs when the mouse pointer is over the control and the
user presses a mouse button. The handler for this event receives an
argument of type MouseEventArgs.
MouseEnter
This event occurs when the mouse pointer enters the border or client
area of the control, depending on the type of control. The handler for this
event receives an argument of type EventArgs.
MouseHover
This event occurs when the mouse pointer stops and rests over the
control. The handler for this event receives an argument of type
EventArgs.
MouseLeave
This event occurs when the mouse pointer leaves the border or client
area of the control, depending on the type of the control. The handler for
this event receives an argument of type EventArgs.
MouseMove
This event occurs when the mouse pointer moves while it is over a
control. The handler for this event receives an argument of type
MouseEventArgs.
MouseUp
This event occurs when the mouse pointer is over the control and the
user releases a mouse button. The handler for this event receives an
argument of type MouseEventArgs.
MouseWheel
This event occurs when the user rotates the mouse wheel while the
control has focus. The handler for this event receives an argument of
type MouseEventArgs. You can use the Delta property of
MouseEventArgs to determine how far the mouse has scrolled.
Keyboard events
Windows Forms provides two events that occur when a user presses a
keyboard key and one event when a user releases a keyboard key:
The KeyDown event occurs once.
The KeyPress event, which can occur multiple times when a user holds
down the same key.
The KeyUp event occurs once when a user releases a key.
When a user presses a key, Windows Forms determines which event to
raise based on whether the keyboard message specifies a character key or
a physical key. For more information about character and physical keys
A KeyEventArgs parameter,
which provides the KeyCode
property (which specifies a
physical keyboard button).
The Modifiers property (SHIFT,
CTRL, or ALT).
The KeyData property (which
combines the key code and
modifier). The KeyEventArgs
parameter also provides: