Windows Forms and Controls
Windows Forms and Controls
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
}
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
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.
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.
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.
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.
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.
SelectionProtected Tells whether the selected text or all the text after the insertion
point is protected.
DataSource Specifies the source of data that the ListBox will display.
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.
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.