0% found this document useful (0 votes)
22 views54 pages

Windows Forms and Controls

Uploaded by

Sujal Padiya
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)
22 views54 pages

Windows Forms and Controls

Uploaded by

Sujal Padiya
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/ 54

Priyank Bhojak

 Graphical user interface to make window


client application.
 Microsoft Foundation class library was
converted into window forms.
“Window form application allows to design
multiple forms to perform various tasks using
window controls by specifying their
properties and events.”
 Used to create user friendly GUI Application.
 Uses classes of DOT NET Framework class
library
 Create secure and functional software
applications.
 Contains various inbuilt and user defined
controls.
 Used to perform various task such as creating
dialogs, printing, references, printing and
documentation
 Windows Form are the base on which we
build, develop all our user interface and they
come with a rich set of classes.
• Forms allow us to work visually with controls
and other items from the toolbox.
• System.Windows.Forms namespace
and the form class is
System.Windows.Forms.Form.
• The form class is based on the Control class
which allows it to share many properties and
methods with other controls.
From Window to Control to Form
• One common base class: Control
– Represents a window
• Offers properties and methods
• The Form class is derived from Control
• New Controls and Forms through Inheritance
System.object
System.MarshalByRefobject
System.ComponentModel.Component
System.Windows.Forms.Control

System.Windows.Forms.ScrollableControl

System.Windows.Forms.ContainerControl

System.Windows.Forms.Form
 Each Form in this namespace is an instance of
Form Class.
 There are two kind of class members.
o Static / Share Members: Access Directly
using class
Classname.membername
o Instance Members : Access by using
instance of class(an object)
Objectname.membername
 Simple Code.txt

 Using code control properties.txt


 An object is a type of user interface element
you create on a Visual Basic form by using a
toolbox control.
 The form itself is an object.
 Every control consists of three important
elements:
◦ Properties which describe the object,
◦ Methods cause an object to do something and
◦ Events are what happens when an object does
something.
 All the Objects can be moved, resized or
customized by setting their properties.
 A property is a value or characteristic held by
a Visual Basic object, such as Caption or Fore
Color.
 Properties can be set at design time by using
the Properties window or at run time by using
statements in the program code.
Syntax
Object. Property = Value
Where-
Object is the name of the object you're
customizing.
Property is the characteristic you want to
change.
Value is the new property setting.
Ex:- Form1.Caption = "Hello"
 An event is a signal that informs an application
that something important has occurred.
◦ Example:- when a user clicks a control on a form,
the form can raise a Click event and call a procedure
that handles the event.
 There are various types of events associated
with a Form like click, double click, close, load,
resize, etc.
 public partial class Form1 : Form
 {
 public Form1()
 {
 InitializeComponent();
 }

 private void Form1_Load(object sender,


EventArgs e)
 {

 }
 C# &VB.Net provides a huge variety of
controls that help you to create rich user
interface.
 Functionalities of all these controls are
defined in the respective control classes.
 The control classes are defined in
the System.Windows.Forms namespace.
 Visual Basic Form is the container for all the
controls that make up the user interface.
 Creating windows form
 Adding Control to windows form
 Disabling and Enabling Windows Forms
 Changing the title of windows forms
 Setting Border of windows form
 Displaying and hiding Maxi, Mini & close
button of windows form
 Specifying the initial position of windows
form
 Creating Multiform Windows Application
 Mouse and Keyboard Events.docx
Properties Description
AcceptButton The button that's automatically activated when you
press Enter, no matter which control has the focus at
the time. Usually the OK button on a form is set as
AcceptButton for a form.
CancelButton The button that's automatically activated when you hit
the Esc key.
AutoScroll This Boolean property indicates whether scroll bars
will be automatically attached to the form if it is
resized to a point that not all its controls are visible.
AutoScrollMinSi This property lets you specify the minimum size of
ze the form, before the scroll bars are attached.
AutoScrollPositi The AutoScrollPosition is the number of pixels by
on which the two scroll bars were displaced from their
initial locations.
Properties Description
Back Color Sets the form background color.
Border Style The BorderStyle property determines the style of the
form's border and the appearance of the form:
None: Borderless window that can't be resized.
Sizable: This is default value and will be used for
resizable window that's used for displaying regular
forms.
Fixed3D: Window with a visible border, "raised"
relative to the main area. In this case, windows can't
be resized.
FixedDialog: A fixed window, used to create dialog
boxes.
FixedSingle: A fixed window with a single line border.
FixedToolWindow: A fixed window with a Close button
only. It looks like the toolbar displayed by the drawing
and imaging applications.
SizableToolWindow: Same as the FixedToolWindow
but resizable. In addition, its caption font is smaller
than the usual.
Properties Description
Font This property specify font type, style, size

Height This is the height of the Form in pixels.


MinimizeBox By default, this property is True and you can set it to
False to hide the Minimize button on the title bar.
MaximizeBox By default, this property is True and you can set it to
False to hide the Maximize button on the title bar.
MinimumSize This specifies the minimum height and width of the
window you can minimize.
MaximumSize This specifies the maximum height and width of the
window you maximize.
Name This is the actual name of the form.
Width This is the width of the form in pixel.
Properties Description
StartPosition Sets the form background color.
This property determines the initial position of the
form when it's first displayed. It will have any of the
following values:
CenterParent: The form is centered in the area of its
parent form.
CenterScreen: The form is centered on the monitor.
Manual: The location and size of the form will
determine its starting position.
WindowsDefaultBounds: The form is positioned at the
default location and size determined by Windows.
WindowsDefaultLocation: The form is positioned at
the Windows default location and has the dimensions
you've set at design time.
Text The text, which will appear at the title bar of the form.
Top, Left These two properties set or return the coordinates of
the form's top-left corner in pixels.
TopMost This property is a True/False value that lets you
specify whether the form will remain on top of all
Name Description

Activate Activates the form and gives it focus.

AddOwnedForm Adds an owned form to this form.

BringToFront Brings the control to the front of the z-order.

CenterToParent Centers the position of the form within the


bounds of the parent form.
CenterToScreen Centers the form on the current screen.

Close Closes the form.

Focus Sets input focus to the control.


Hide Conceals the control from the user.
Scale(SizeF) Scales the control and all child controls by the
specified scaling factor.
Show Shows the form.
SetDesktopLocation() Set the Location of the form in desktop
coordinators
SetDesktopbounds() Set the bounds of the form in desktop
coordinators
Name Description
MouseDown Occurs when the mouse pointer is over the form and
a mouse button is pressed.
MouseEnter Occurs when the mouse pointer enters the form.
MouseHover Occurs when the mouse pointer rests on the form.
MouseLeave Occurs when the mouse pointer leaves the form.
MouseMove Occurs when the mouse pointer is moved over the
form.
MouseUp Occurs when the mouse pointer is over the form and
a mouse button is released.
MouseWheel Occurs when the mouse wheel moves while the
control has focus.
Resize Occurs when the control is resized.
Scroll Occurs when the user or code scrolls through the
client area.
Shown Occurs whenever the form is first displayed.
Name Description
ScaleControl Scales the location, size, padding, and margin of a
control.
ScaleCore Performs scaling of the form.
Select Activates the control.
SendToBack Sends the control to the back of the z-order.
SetAutoScrollMargin Sets the size of the auto-scroll margins.
SetDesktopBounds Sets the bounds of the form in desktop
coordinates.
SetDesktopLocation Sets the location of the form in desktop
coordinates.
SetDisplayRectLocati Positions the display window to the specified
on value.
Show Displays the control to the user.
ShowDialog Shows the form as a modal dialog box.
Name Description
Activated Occurs when the form is activated in code or by
the user.
Click Occurs when the form is clicked.
Closed Activates the control.
Closing Occurs when the form is closing.
DoubleClick Occurs when the form control is double-clicked..
DragDrop Occurs when a drag-and-drop operation is
completed.
Enter Occurs when the form is entered.
GotFocus Occurs when the form control receives focus.
HelpButtonClicked Occurs when the Help button is clicked.
KeyDown Occurs when a key is pressed while the form has
focus.
KeyPress Occurs when a key is pressed while the form has
focus.
KeyUp Occurs when a key is released while the form has
Enlist various Windows Form Controls. Create a NET Application for
demonstrating use of any five Controls. (GTU Exam)
 The Button Control
 The Label Control
 The TextBox Control
 The RichTextBox Control
 The RadioButton Control
 The CheckBox Control
 The ComboBox Control
 The ListBox Control
 The PictureBox Control
 The Panel control
(System.Windows.Forms.Label) is used to add
text to a form that can be used to show
messages, or add labels to identify what
other controls' functionality is.
 By default, it will have an initial text like
lable1
 label1.Text = "Hello World!";

 label1.Image =
Image.FromFile("C:\\testimage.jpg");
Property Description
AutoSize If true, the size of the borders of the label control
in the designer will be resized automatically
depending on the text inside it.

BorderStyle Specifies the type of border around the label.

Font Used to change the font properties of the text


inside the label control.

Text The text of the label.

TextAlign The alignment of the text inside the Label control


 (System.Windows.Forms.Button) is commonly
used to execute commands when it is clicked.
 When a button is clicked, you specify codes
that will be used.
 Buttons are typically used to confirm or
cancel an action, to perform different actions,
and to open some more dialogs.
Property Description
AutoEllipsis Specifies whether to append dots (...) when the text in the
button is too long and can't fit the button.

AutoSize Specifies whether the button will automatically resize to fit its
content.
FlatStyle Determines the style of the button. Popup makes the button
flat, and when you hover on the button, the button will pop
out. Flat makes the button flat and when you move point your
mouse inside the button, the background color of the button
changes.
Enabled If set to false, the button cannot be clicked or receive focus.

Image An optional image that you can place inside the control.

ImageAlign The alignment of the image in the button.


Text The caption inside the button.
Visible Tells whether the button is visible or not.
Event Description
Leave Occurs when the control becomes inactive anymore.
Enter Occurs when the control becomes the active control
of the form.

Occurs when the location of the button is changed.


LocationChanged
MouseDown Occurs when the mouse pointer is in the button
and the mouse button is pressed down.

MouseEnter Occurs when the mouse enters the button.

MouseHover Occurs when the mouse stays stationary in the button for
an amount of time.

MouseUp Occurs when you pressed the button and you let go of
the mouse button.

MouseLeave Occurs when the mouse pointer leaves the button.


 (System.Windows.Forms.TextBox) is the most
basic means of input in a windows forms.
 You give the input data by typing it inside
the text box.
 The text you type can be accessed by using
the Textproperty of the control
Property Description
AcceptsReturn Used with Multiline. Tells if whether the return key is included in the
input. The return will be converted into a \n escape sequence.

AcceptsTab Indicates whether to accept tab as an input. By default, hitting tab will
bring the focus to the control with the next TabIndex in the form.

Enabled Set to false to make the text box read-only therefore making the text
box act like a label.
Font The font properties that will be used by the textbox.

Lines The lines of text in a multiline text box.

Multiline Set to true to allow multiple lines in a text box.

Text The text inside the text box.

PasswordChar Accepts a character that will be used to mask each character typed by
the user.
ReadOnly Tells whether the text in the form can be edited.

Visible Tells whether the text box is visible inside the form.

WordWrap Used with Multiline. Set to true to enable automatic wrapping of words.
 (System.Windows.Forms.RichTextBox) is similar
to a TextBox control, but it allows you to
format different parts of the text inside it.
 The TextBox control is typically used to accept
text input from the user while
the RichTextBox control is used to show
formatted text and save it in Rich Text Format
(RTF).
Property Description
AcceptsTab Specifies whether to accept focus as a result of pressing the tab key.

BulletIndent Specifies the indentation used in the RichTextBox control when the
bullet style is applied to the text.
DetectUrls Specifies whether to automatically detect and add the target link to
URLs inside the RichTextBox control.
Lines A collection of individual lines in a RichTextBox control.
Modified Tells whether the contents of the RichTextBox control has been
modified since the last time it was set.
Multiline Tells whether the RichTextBox control can have multiple lines of text
(true by default).
ReadOnly Tells whether the RichTextBox control is read-only.
Scrollbars Specifies the type of scrollbars to display.
SelectedText Gets or sets the selected text within the RichTextBox.
SelectionAlignment Specifies the alignment to apply to the current selection or insertion
point.
SelectionBackColor Specifies the background color of the selected text.
SelectionBullet Specifies whether the bullet style is applied to the current selection or
insertion point.
SelectionColor Specifies the color of the selected text.

SelectionFont Specifies the font that the selected text will use.

SelectionLength Specifies the number of characters of the selected text.

SelectionProtected Tells whether the selected text or all the text after the insertion
point is protected.

SelectionRightIndent The distance (in pixels) between the right edge of


the RichTextBox control and the right edge of the text that is
selected or added at the current insertion point.

SelectionStart Specifies the starting position of the selection or the insertion


point.

ShortcutsEnabled Specifies whether predefined or defined shortcut keys is enabled.

Text The plain text inside the RichTextBox control.

WordWrap Specifies whether to wrap the text inside


the RichTextBox control.
 (System.Windows.Forms.RadioButton) is a button that
can be either turned on or off.
 When the radio button is turned on, a dot can be seen
and when it is turned off, the circle appears empty.
 Radio buttons are usually used when a user must select
one choice from a set of choices.
 For example, if you want to determine the gender of the
user, then you can use two radio buttons labeled Male
and Female. Since you used a radio button, you can
only choose one of the two.
Property Description
Appearance The radio button can be displayed as a normal
button,
or a circular button with a label beside it.

CheckAlign Determines the alignment of the button. The


default is
MiddleLeft, which will show the button
to the left of the label.

Checked When set to true, the radio button will be in


its "ON" state and a dot will be
seen inside the button.

Text Sets the text inside the label of


the radio button.
 (System.Windows.Forms.CheckBox) is also a
type of button and appears as an empty box
with a label beside it.
 By default, when the empty box is clicked, a
check will show up inside the box telling that
the checkbox control is in its "checked" state.
 Unlike a radio button, you can check multiple
or even all of the checkboxes.
 The CheckBox control contains similar
properties as the radio button control.
Property Description
Checked Determines if the checkbox is checked.

CheckState Tells whether the checkbox


is Checked, Unchecked.

ThreeState If true, the checkbox can accept


an Intermediate state.

three states are


Checked, Unchecked or Intermediate. Intermediate indicates that
value of the checkbox is invalid or cannot be determined.
 The ComboBox control is another way of allowing a
user to choose from a set of options.
 The ComboBox control looks like a text box with
a button in its right side.
 When the button is clicked, the ComboBox show a
drop-down box containing the list of
options/items available. The user can then choose
from these options by clicking one of them.
Property Description
DataSource A list of data that the control will use to get its items.

DropDownHeight The height in pixels of the dropdown box in a combo


box.

Items The items in the combo box.

Sorted Specifies whether the items on the combo box should


be sorted.

Text The default text when there is no item selected.

SelectedItem Gets or sets the item of the currently selected item.


 The ListBox control is used to show a list of
strings which you can select. By default, you
can only select one item.
 The ListBoxcontrol is best used if you are
trying to display a large number of items. The
following are the commonly used properties
of the ListBoxcontrol.
Property Description
ColumnWidth Specifies the width of each column if MultiColumn is set to true.

DataSource Specifies the source of data that the ListBox will display.

Items Contains the items that the ListBox will display.

MultiColumn Tells whether the ListBox supports multiple columns.

SelectedItem Returns the selected item as an object.

SelectedItems An object collection of the selected items.

SelectionMode Specifies the number of items you can select at the same time.
• SelectionMode.None - you cannot select anything
• SelectionMode.One - you can only select one item
• SelectionMode.MultiSimple - you can select multiple items by
simply clicking them
• SelectiomMode.MultiExtended - you can select multiple items by
holding ctrl, shift and arrow keys

ScrollAlwaysVisible Tells whether the scrollbars are always visible regardless of the number
of items in the ListBox.
Sorted Tells whether to sort the items in the ListBox alphabetically or in
ascending order.
Text If you set a string value, the first item that matches will be selected. This
property returns the text of the first selected item.
 The ListView control is an ItemsControl that is
derived from ListBox.
 You can display images on your form by
using the PictureBox control. It is a simple
control which has a main purpose of
displaying images.
 All you have to do is browse for the desired
image and Visual Studio/VCE will import it to
your project. You can use several image
formats such as JPEG, GIF, PNG, and BMP.
Properties Description
ErrorImage The image that will be displayed when the loading of the actual
image failed or is canceled.
Image The image that will be displayed by the control.

ImageLocation The path of the image to be displayed by the PictureBox.

InitialImage The image that is initially displayed while the main image is
loading.
SizeMode Tells how the image will be displayed. Accepts values from
the System.Windows.Forms.PictureBoxSizeMode
WaitOnLoad If set to true, blocks all interaction to the form while the image is
being loaded.
PictureBoxSize
Mode Description
Normal The image will be positioned in the upper-left corner of
the PictureBox and if the image is larger than
thePictureBox, the image will be clipped.

StretchImage Resizes the image to match the size of the PictureBox.

AutoSize Resizes the PictureBox to match the size of the image.

CenterImage The image is centered inside the PictureBox. If the image is


larger than the PictureBox, the image will be clipped.

Zoom Fits the whole image inside the PictureBox w while


maintaining the image's size ratio.
 The Panel control is used to group controls
on a form.
 Once you place a control inside a panel, the
control becomes the child of the panel. The
panel, therefore, becomes the parent of the
control.
 To better illustrate that relationship, try
moving the panel. All controls inside the
panel move with it. The relationship also
allows the parent and the child to share the
values of common properties.
 The GroupBox control is a similar control but allows
you to add captions for each group. You do that by
using the Text property of the GroupBox control.
The GroupBox control also has a default border.
 Crate Windows Form Application for Student
Information Detail with use of all form
controls .

 Lits of controls with example:


 Control Detail.docx

You might also like