Dotnet 4th Chapter - Docx. Edit
Dotnet 4th Chapter - Docx. Edit
CHAPTER-4
Windows Forms is a Graphical User Interface(GUI) class library which is bundled in .Net
Framework.Its main purpose is to provide an easier interface to develop the applications for
desktop, tablet, PCs. It is also termed as the WinForms. The applications which are developed by
using Windows Forms or WinForms are known as the Windows Forms Applications that runs on
the desktop computer. WinForms can be used only to develop the Windows Forms Applications
not web applications. WinForms applications can contain the different type of controls like labels,
list boxes, tooltip etc.
● After that following window will display which will be divided into three parts as follows:
Editor Window or Main Window:Here,you will work with forms and code editing.You can
notice the layout of form which is now blank.You will double click the form then it will open the
code for that.
● Solution Explorer Window: It is used to navigate between all items in solution. For
example, if you will select a file form this window then particular information will be
GFGC,TumakuruPage 1
C# programming
display in the property window.
●
● Properties Window: This window is used to change the different propertiesof the selected
item in the Solution Explorer. Also, you can change the properties of components or controls that
you will add to the forms.
Over view of the visualstudio express IDE
● Visual Studio is an Integrated Development Environment(IDE) developed by Microsoft to
develop Desktop applications, GUI(Graphical User Interface), console, web applications, mobile
applications, cloud, and web services, etc.
● With the help of this IDE,you can create managed code as well as native code.Itusesthe various
platforms of Microsoft software development software like Windows store, Microsoft Silverlight,
and Windows API, etc.
● It is not a language-specific IDE as you can use this to write code in C#, C++, VB(Visual
Basic), Python, JavaScript, and many more languages.
● It provides support for 36 different programming languages.
VisualStudio Editions
1. Community
2. Professional
3. Enterprise
GFGC,TumakuruPage 2
C# programming
live coding support. For faster development, the Platform offers an autocomplete option. The
built-in intelligent system offers descriptions and tips for APIs.
● ThroughVisualStudio IDE you can easily collab with your teammates in a same project. This
IDE helps the developers to share, push and pull their code with their teammates.
● Every user of Visual Studio has the ability to customize it. They have the option to add
features based on their needs. For example, they can download add-ons and install extensions in
their IDE. Even programmers can submit their own extensions.
Commoncontrols
1. Textbox control
A Text Box control is used to display, accept the text from the user a san input,ora single line of
text.
we can add multiple text and scroll barsin textbox control.
Step1:We have to drag the Text Box control from the Tool box and drop it on the Windows
form.
Step2:Once the Text Box is added to the form, we can set various properties of the TextBox by
clicking on the TextBox control.
TextBox Properties
GFGC,TumakuruPage 3
C# programming
▪ Auto Complete Mode: It is used to get or set a value that indicate show the automatic
completion works for the textbox control.
▪ Font: It is used to set the font style of the text displayed on a Windows form.
▪ Multiline: It is used to enter more than one line in a Text Box control, by changing the
Multiline property value from False to True.
▪ Preferred Height:It is used to set the preferred height of the textbox controlin the window
form.
▪ Scroll Bars: It is used to display a scroll barona multi line textbox by setting a value for a
Textbox control.
▪ Visible:TheVisible property sets a value that indicates whether the textbox should be
displayed on a Windows Form.
TextBox Events
▪ Click:When a textbox is clicked, a click event is called in the textbox control.
▪ Accept Tabs Changed: It is found in the TextBox control when the property value of
the Accept Tab is changed.
▪ Back Color Changed: It is found in the TextBox Control when the property value of the
BackColor is changed.
▪ Border Style Changed: It is found in the TextBox Control when the value of the Border
Style is changed.
▪ Font Changed: It occurs when the property of the Font is changed.
2. Label control
A label control is used to display descriptive text for the form in control. It does not participate in
user input or keyboard or mouse events. Also,we can not rename labels at runtime.
Step1:We have to drag the Label control from the Tool box and drop it on the Windows form.
Step2:Once the Label is added to the form, we can set various properties to the Label by clicking
on the Label control.
GFGC,TumakuruPage 4
C# programming
LabelProperties
▪ AutoSize: As the name defines, an Auto Size property of label control is used to set or get a
value if it is automatically resized to display all its contents.
▪ BorderStyle: It is used to set the style of the border in theWindows form.
▪ Preferred Width: It is used to set or get the preferred width for the Label control.
▪ Font: It is used to get or set the font of the text displayed on a Windows form.
▪ Preferred Height: It is used to set the height for the LabelControl.
▪ Text Align: It is used to set the alignment of text such as centre, bottom,top,left, or right.
▪ Fore Color: It is used to set the color of the text.
▪ Image: It is used to set the image to a label in Windows Form.
Label Events
▪ Auto Size Changed: An Auto Size Changed event occurs in the Label control when the
value of Auto Size property is changed.
▪ Click: Click event is occurring in the Label Control to perform a click.
▪ Double Click: When a user performs a double- clicked in the Label control, the Double Click
event occurs.
▪ Back Color Changed: A Back Color Changed event occurs in the Label control when the
value of the Back Color property is changed.
▪ Drag Drop: A Drag Drop event occurs in the Label control when a drag and drop
operation is completed.
When a checkbox is selected, a tick or check mark will appear on the Windows form.
Step1: We need to drag the CheckBox control from the tool box and drop it to the
Windows form.
GFGC,TumakuruPage 5
C# programming
Step2: Once the Check Box is added to the form, we can set various properties of the check box
by clicking on the Check Box control.
Step1:We need to drag the combo box control from the tool box and drop it to the
Windows form.
Step2: Once the Combo Box is added to the form, we can set various properties of the Combo
Box by clicking on the Combo Box control.
GFGC,TumakuruPage 6
C# programming
▪ Created: Ittakes a value that determines whether the control is created or not.
▪ Data Binding: It is used to bind the data with a Combo Box Control.
▪ Back Color: The Back Color property is used to set the background color of the combo
box control.
▪ Max Length: It is used by the user to enter maximum characters in the edit able area of the
combo box.
▪ Sorted: The Sorted property is used to sort all the items in the Combo Box by setting the
value.
The Radio Button is used to select one option from the number of choices.
The Radio Button is mutually exclusive that represents only one it emis active and the remains
unchecked in the form.
GFGC,TumakuruPage 7
C# programming
Step1: Drag the Radio Button control from the tool box and drop it to the Windows form.
Step2: Once the Radio Button is added to the form, we can set various properties of the Radio Button
by clicking on the Radio control.
Event handling
Event handling in C# is a mechanism that allows classes or objects to communicate and respond
to actions or occurrences(events)that happen during the execution of a program. Event: An event
is a member of a class that allows other classes to subscribe to it
Event Handler: An event handler is a method that gets executed when the event is raisedor
triggered.
Example
using System;
class Button
{
//Definethe event
public event EventHandler Click;
GFGC,TumakuruPage 8
C# programming
}
GFGC,TumakuruPage 9
C# programming
GUI stands for Graphical User Interface. It refers to aninter face that allows one to interact with
electronic devices like computers and tablets through graphic elements.
Ituses icons, menusand other graphical representations to display information,as opposed to text-
based commands.
Mouse-event handling
Mouse event handling involves responding to actions performed by the user using the mouse,
such as clicking, moving, or scrolling.
GFGC,TumakuruPage 10
C# programming
This functionality is of tencrucialin graphical user interface (GUI) applications to provide interactivity
and user feedback.
Event Types
Mouse Double Click: Occurs when the mouse button is double-clicked. MouseEnter:
Mouse Leave: Occurs when the mouse pointer leaves the control. MouseWheel:
Keyboard-event handling
Keyboard event handling involves capturing and responding to user input from the keyboard.
This functionality is crucial for building interactive applications, such as text editors, games, or
form-based applications.
Event Types:
Key Press: Occurs when a key is pressed while the control has focus and can represent a
character.
The simplest type of dialogbox is the warning which display same message and may require the
user to acknowledge that the message has been read, usually by clicking “OK” or a decision as to
whether or not an action should continue by clicking “OK” or “Cancel”.
GFGC,TumakuruPage 11
C# programming
if (res == DialogResult.Cancel) {
MessageBox.Show("YouhaveclickedCancelButton");
//Some task…
}
MDI
MDI stands for Multiple Document Interface applications that allow users to work with
multiple documents by opening more than one document at a time. Single Document Interface
(SDI) application can manipulate only one document at a time.
The MDI applications act as the parent and child relationship in a form.A parent form is a
container that contains child forms, while child forms can be multiple to display different
modules in a parent form.
1. Mid Parent: The Mid Parent property is used to seta parent form to a childform.
2. Active Mdi Child: The Active Mdi Child property is used to get the reference of the current
child form.
3. Is Mdi Container: The Is Mdi Container property set a Boolean value to True that represents
the creation of a form as an MDI form.
4. Layout Mdi(): The Layout Mdi () method is used to arrange the child forms in the parent or
main form.
5. Controls: It is used to get the reference of control from the child form.
Step1:First,we have to open the Windows form and create the Menu bar with the use of Menu Strip
control.
GFGC,TumakuruPage 12
C# programming
Step2: After creating the Menu, add the Sub items into the Menu bar.
GFGC,TumakuruPage 13
C# programming
Menubar
Menus are displayed as one word strings clustered in a ro wat the top of the IDE.
Menu Description
File Containscommandsforopening, closing,addingandsavingprojects,aswellas
printingproject dataandexitingVisual Studio.
Edit Containscommandsforeditingprograms,suchascut,copy,paste,undo, redo,
delete,findandselect.
View Containscommandsfordisplayingwindows(e.g.,SolutionExplorer, Toolbox,
Propertieswindow)andforaddingtoolbarstotheIDE.
Project Containscommandsformanagingprojectsandtheir files.
Build Containscommandsforcompilingaprogram.
Debug Containscommandsfordebugging(i.e.,identifyingandcorrectingproblemsina
program) and running a program. Debugging is discussed in detail in Appendix
C.
Data Containscommandsforinteractingwithdatabases(i.e.,organizedcollectionsof data
stored on computers), which we discuss in Chapter 20, Database, SQL and
ADO.NET).
Format Containscommandsforarrangingandmodifyingaform'scontrols.Notethatthe
Formatmenu appearsonlywhenaGUIcomponentis selectedin Design view.
Tools ContainscommandsforaccessingadditionalIDE tools(e.g.,theToolbox) and
optionsthatenable youtocustomizetheIDE.
Window Containscommandsforarranginganddisplaying windows.
CommunityContainscommandsforsendingquestionsdirectlytoMicrosoft, checking
questionstatus,sendingfeedbackonVisualC#andsearchingtheCodeZone developer
center and the Microsoft developers community site.
Help ContainscommandsforaccessingtheIDE'shelp features.
Tool box
Tool box window displays controls that you can add to visual studio project.
To open tool box,choose viewtool box from the menu baror press ctrl+alt+X.
You can drag and drop different controls on to the surface of the designer you are using,and
resize and position the controls.
GFGC,TumakuruPage 14
C# programming
Solution Explorer
The Solution Explorer tool window appears as apane in the upper-right side of the Visual Studio
integrated development environment(IDE).
If you don't see the Solution Explorer tool window, you can open it from the Visual Studio menu bar
by using View >Solution Explorer, or by selecting Ctrl+Alt+L.
GFGC,TumakuruPage 15
C# programming
Properties windows
The Properties window to edit and view file, project, and solution properties. You can find
Properties Window on theView menu. You can also open it by pressing F4 or by typing
Properties in the search box.
The Properties window displays different types of editing fields, depending on the needs of a
particular property.
Tool bar
Tool bars typically are rows of buttons and other controls, such as combo boxes, list boxes, text
boxes, and menu controllers. All toolbar controls are associated with commands. When you click a
toolbar button, its associated command is activated.
Using help
GFGC,TumakuruPage 16