--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD - IT)
E- Mail : rupareleducation@gmail.com
Contact No : 7600044051
Windows
Programming
1.
Creating
windows application
·
Window form environment is very common environment
like form with basic control and it give effect like minimize, maximize etc...
·
Window form is a framework located in the Sytem.Windows.Forms
dll for building windows application in .net based graphical user interface (GUI).
·
Each time you create windows application visual studio
will display a default blank form on to
which you can drag the control in the application form and adjust their size
and position.
·
To create a window application the first step is to
start a new project and build a form.
·
Open your visual studio and select fileànew project.
·
And form the new project dialog box selects other
languagesàvisual
c# and select window form application.
·
Enter a project name at the bottom of the dialog box
an click ok button.
·
After selecting a window form application you can see
a default form form1 in your new project.
·
The window form that you see in designer view. You can
switch between this view and code view at any time using double click or
shortcut key F7.
·
In this application you can set property, event and
method as per the requirement each application have their own toolbar, title
bar, control box, server explorer, solution explorer etc...
2.
MessageBox
class with all types of show () method.
·
A message box is a small dialog box that displays a
message to the user.
·
Message box are often use to tell the user about the
result of some action. Such as the file has been copy or file not count etc...
·
A MessageBox is dismiss when the user click one of the
messagebox available buttons. Most application has many message boxes.
·
It is important to remember that when you display a
message to a user that you are communicate with user.
·
The messagebox display its message using show ()
method. The MessageBox.show () can be use to tell a user something or ask the
user a question.
·
A MessageBox.show() is an overloaded method. This
means that the method was return with numeric construct support various option.
·
Following is syntax to call a MessageBox.
MessageBox.Show
()
·
To display a message with a MessageBox or a caption in
the title bar and ok button use the following syntax. MessageBox.show(Message
text, caption);
·
To display a messagebox with a specified text, caption
and one or more specific button user the following syntax.
MessageBox.show
(messagetext, caption, Buttons, icon);
·
According to all above syntax MessageText is text to
display in the MessageBox.
·
Caption determines what appear in the title bar.
·
Buttons determine which button the user can see and
icon determine what icon appears in the MessageBox.
·
Following is some list of buttons which is supported
by the MessageBox that is.
1. AbortRetryIgnore
2. OK
3. OkCancle
4. YesNoCancle
5. YesNo
6. RetryCancle
·
All the button parameter are an enumerated type. Same
MessageBox button a number of icon parameters are available in it.
·
The icon parameters are also an enumerated type
following is list of icon parameters.
1. Asterisk
2. Error
3. Exclamation
4. Hand
5. Information
6. None
7. Question
8. Stop
9. Warning
·
All above listed are a MessageBox icon that represent
with MessageBox.
3.
Dialog
Boxes.
·
A DialogBox is type of window which is use to enable
common communication or dialog between computer and its user.
·
A DialogBox is most often used to provide the user
with the means for specifying how to implement a command or respond to a
question.
·
Window.form is base class for dialog boxes.
·
Sometimes graphic use interface a windows is used to
communicate with user or establish a dialog between user and application.
·
The additional window which is display in an
application which call DialogBox user for a response or to ask something to the
user.
·
A DialogBox can be customized and such DialogBox are
call custom DialogBox.
·
DialogBox are special form that are non resizable.
·
Dialog box are of 2 types that are 1. Model DialogBox
2.
Modeless DialogBox
·
A DialogBox that temporarily hold an application user
can continue until the dialog box has been closed is called model DialogBox.
·
Another DialogBox which is used as a modeless DialogBox.
It is used when the requested information is not essential to continue.
·
Model DialogBox is display using showdialog() method
while modeless DialogBox using show() method.
·
Following is some DialogBox that are used in command
window application that is.
1. Color
dialog
2. Font
dialog
3. Savefile
dialog
4. open
file dialog
5. print
dialog
·
All above listed dialogs are implemented bya an
operating system.
·
So, they can be share across all the application that
run on that operation system.
Color Dialog:
The Color dialog allow as to select a color user can
select any color easily from it. You can get or set selected color value in
color property. Its default color is black. It also provides a custom color
facility.
Font Dialog:
FontDialogBox is use to allow the user to select font
settings. FontDialogBox display font. Font style. Font size, effect color etc.
We can get or set font using font property.
SaveFielDialog:
SaveFielDialog allow as saving the file in a specified
location. Basically the save dialog box display as a save as file dialogs.
OpenFileDialog:
It allow as to open a file from specific location to
display in an application OpenFileDialog control have number of property to
check file is exist or not.
·
It returns a string that contains a complete path of
the filename. It also provides a concept of filter. Which is related with file
of type dropdown Listbox?
·
To display all common dialog control at runtime we meet
to call show dialog () of control dialog.
·
Showdialog () return enumerated type call dialog
result.
·
It defines the identifier which indicates which button
was click.
4.
Basic introduction to form and properties.
·
Window form environment is very common environment
like form with basic control and Windows OS effect like minimize box. Maximize
box etc...
·
Any desktop application is nothing but software and
this software is made up of one or more forms.
·
And the forms are what use see. Just like website contains
WebPages same desktop application contains windows forms.
·
For example ATM machine is display a form. The main
one form is and which form we get from option of that MDI. And those are call
child from of MDI.
·
A form is usually rectangular. That form is primary
platform for user interaction.
·
Form can be single document interface multi document
interface, DialogBox etc...
·
We can place control on the form. Form is the
container form has property event an method.
·
Using this keyword we can gain access windows
property, event and method. To use window form property, event and method. We
need a namespace System.Windows.Forms.form.
·
Following is some list of property of form.
Accept button : get or set the one button for enter
key.
Auto scroll : it set scrollbar to the form when it
require.
Cancel button : get or set the one button for esc
key.
Control button : its default value is true. It is relented
with minimize, maximize, restore button.
Icon : get or set the icon of the form.
IsMDIContainer : get or set whether the form is
container for multiple document interfaces.
StartPosition : get or set starting position at
runtime.
Etc... The properties of windows form.
5. Concept of adding
various events with event parameters.
·
Events handling is perform differently in .net each
control is a derived from basic form and allow to add event in it.
·
Form class can be use any event handler in its
hierarchy.
·
Generally in windows application 2 types of events are
raised.
1. Mouse
event
2. Keyboard
event
·
You don’t have to write any code to deal with mouse
input.
·
C# support a various events that enable you to deal
with mouse input directly.
·
That is mouse enter, mouse move, mouse hover, mouse
down, mouse up, mouse leave etc...
·
Even you can set a single click as well as double
click event in an application.
·
Same as keyboard input is also able to raised an event
you will want to handle keyboard input directly then you can generally keyboard
input eneble key down event, keypress event, keyup event.
·
This event is fire in the save order.
6. Standard Property.
·
Properties are characteristics of any object or
control.
·
Property of the form or any window control can modify
using property window and coding window.
·
Property set in the property window is applied at
design time and set in the coding window are apply at runtime.
·
Following is same standard property.
BackColor : get or set control background color.
BackgroundImage : get or set control background image.
Enabled : get or set whether control is enable.
Font : get or set font for the control.
ForeColor : get or set control foreground color.
Height : get or set control height.
Width : get or set control width.
Name : get or set control’s name.
Visible : get or set control visible or hidden.
Text : get or set the text associate with
control.
7. Different windows
controls.
·
Button
:
Button control is use to perform click operation
generally we are use button control to do something on event like click event,
double click event etc...
Button control is also known as command button and
default event of the button is click event.
It means when button is clicked it respond with the
click event.
Following is some properties of button control.
·
Label
:
Label control is use to define a static text on the screen.
We can create a label with different 2 ways that is design time as well as
runtime.
Runtime we create a label is not editable it means it
can be use as a security reasons. Means we can edit label if we design at
design time.
There are mainly 2 purpose to use a label in form that
is want to say something to the use or want to ask something to the user.
The common property of label control is text property.
Following is same property of label control.
·
Textbox
:
Windows users are familiar with textbox. This control
looks like box and accepts input from the use, or used to display text.
Textbox control display text enters at design time.
That can be edited by user at runtime or change it programmatically.
Typically textbox control is sued to display a single
line of text or allow multiline as well as password character in it.
It means textbox control can work as a password
control.
By default textbox hold upto 32767 character but when
we try to display multiline it hold 2GB of text.
Textbox can be read only. Following is some important
property of textbox.
BorderStyle: We can define nome, fixed single or
fixed 3D style as a border.
MaxLength: It specified the maximum number of
character that can be enter into the
box
where 0 means no limit.
Scrollbar : it is Boolean property to share true or false. It is specially design for
Multiline text box design.
WordWrap: it
is also Boolean property it wraps the word in the textbox.
·
RadioButton:
Radio button control enable use to select a single
option from a group.
When select one radio button with in a group the other
radiobutton clear automatically.
Radiobutton is also known as optional button .a
radiobutton control is in a rounded shape.
We can checked or unchecked the radiobutton. We can
take a radiobutton on the form when
multiple option are there and allow to select only one from the list.
It is generally used in gender, stream, initial name
etc...
RadioButton can make its own group when it keep in
container.
To create multiple groups on one form use groupbox or
panel control as a container.
A most useful property of radiobutton is checked property.
The default value of check property is false.
Following is some important property.
·
Checkbox
:
Checkbox is use to select multiple option from the
list.
It means a checkbox is click to select and again click
to deselect from the list.
When a checkbox is checked a check mark is appear in
it.
We can use a checkbox control in a group to display
multiple choice or also allow a single checkbox to on or off user choice.
The different between checkbox and radiobutton is any
number of checkbox control on a form
can be selected while in a radiobutton only one control is selected at a time.
Following is some property of checkbox.
Check : It
is Boolean property it indicate that whether a checkbox is selected
or not.
·
ComboBox:
ComboBox control si combination of Listbox control and
textbox control.
ComboBox
display and editing field combine with Listbox.
To
select from the list or allow to enter a new text. User can enter a data at design
time as well as runtime.
ComboBox
display data in dropdown style format.
User
can select only one from the given list.
It take a little space on the form and allow to store
long selection of data.
It is
frequently use control in windows application. Following is some important property
of ComboBox control.
SelectedItem : get or set a selected item from the
list.
Sorted : It is Boolean property to set true or
false whether the items in the
Control is sorted or not.
Text : get or set selected text.
selectedIndex : get or set selected index of item.
·
ListBox
:
ListBox control display list of item from which user
can select one or more.
ListBox are best use for displaying large number of
choice.
The alternate option for Listbox control is checkbox.
Checkbox control occupied the space in a form while
Listbox control occupies a little space in compare to checkbox because it automatically
appears scrollbar when many items is available in a Listbox.
By default we can select only single item from the
Listbox. But using Listbox property we can set to select multiple items from
the list.
The item in the Listbox is store as a item collection.
Their are 2 ways to add items in the Listbox that is
design time as well as runtime.
Following is some important property of Listbox item
collection that is.
Count : It
return total number of elements in the Listbox.
Following is some list of method of Listbox item.
Clear :
It clear all the items from Listbox.
Contains : It
return Boolean answer it check whether the given object in the Listbox or not.
IndexOf : It returns an index of the item listed in
the list. It index not found then it
Return -1.
Remove : It removes the item from the Listbox.
Remove At :
It removes the item from the list by index.
·
PictureBox
:
PictureBox
control is use to display images in a window form.
PictureBox
is also one of the container control which control images from the source.
PictureBox
control provide a rectangular region where you can draw an image.
It
support many images format. Allow to adjust size.
Allow
to access file from your disk or from the internet and can resize images in several
different ways.
Following
is some important property.
Image : To set image for picturebox from the
reliable source.
Sizemode : It allow to adjust a picture in a different
size as per the requirement.
·
ScrollBar
:
It is very common control for any window base
application.
There are 2 types of scrollbar HScrollBar &
VScrollBar.
The different between HScrollBar & VScrollBar is
presentation Horizontal and Vertical.
User can select a value between 2 ends of the
ScrollBar.
The left end of the ScrollBar corresponds to its minimum
value and other end of the scrollbar is maximum value.
The current value of the control is assumed by the
positional of the indicator.
Following is some important property of scrollbar. Enable,
Visible, Name
Minimum : Get
or set the lower limit of scrollbar default value is 0.
Maximum : Get or
set the upper limit of the scrollbar default value is 100.
Value :
The controls current value specified by the indicator position. We can get or set numeric value from the current position it
follow value between minimum and maximum range. The default value is 0.
SmallChange: When we click on most left and
right side arrow of the scrollbar. The scrollbar
Move in
small amount it call smallchange. It default is 1.
LargeChange:
When we click in between indicator is call largechange the default value is 10.
The major event the scrollbar is buying
clicking the 2 arrow at its end or by
Clicking the area between the indicator or
by dragging the indicator with
Mouse.
·
TreeView:
It
display hierarchy of nodes both parent and child.
Treeview
control is look like window explorer and solution explorer.
Treeview
control is collection of nodes like list box contain stockitems.
Starting
node in a treeview control is call root node.
Under
the root node real tree is made of branches and leaves hear treeview control also expand liked this.
A one
node can have another node call child node.
We can expand and colspand this node by clicking them.
We can display treeview control with checkbox images
with treeview items.
The items in a treeview are store in node collection.
There are 2 way to add items i the treeview using
design time as well as runtime.
Following is same important property and method of
treeview control.
Control : it return total number
of elements in a treeview at particular level.
SelectNode: it
return selected node using selectnode text property.
Checkbox: It
is a Boolean property display checkbox with treeview nodes.
Showlines: It
is aboolean property to display line between the nodes.
FullPath: It returns
the fullpath of the node selected from the treeview.
·
MenuStrip:
The MenuStrip class is foundation of menu
functionality of window form.
We can create MenuStrip control using form designer at
design time or using a MenuStrip class in code at runtime or dynamically.
To create a MenuStrip control at design time you
simpally drag and drop
MenuStrip control from toolbox to a form in visual
studio.
After adding MenuStrip in a form you can add menus or
submenus and also allow to set it’s property and event or to create MenuStrip
control at runtime.
Creating and instance of MenuStrip class.
We can add MenuStrip at any corner of the window form.
Following is some important property of MenuStrip.
·
ContextMenu
:
ContextMenus are menus that appear when an item is
right click.
ContextMenus is also known as contextual, shortcut and
popup menu.
ContextMenu will appear according to area in any
window application.
When we right click the mouse we get a menu which
might display some shortcuts from the edit menu like cut, copy, paste etc...
All this menus which are available when you right
click are called.
·
ToolStrip
:
ToolStrip control provides functionality of windows
toolbar control.
ToolStrip class represent ToolStrip control in a
windows form and serve as a base class of menustrip, statussrtip and
contextmenu class.
We can create toolstrip control at design time or
using toosrtip class at runtime.
To create a toolstrip control at design time simply
drag and drop toolstrip control from toolbox. By default toolstrip control is
docket at the top of the form.
ToolStrip control nothing but container without adding
a child control.
A ToolStrip control is capable of hosting button,
lable, split button, dropdown button, saprater, combobox, textbox etc...
·
Timer
:
The timer control allows as to set time interval to
execute an event after that interval to continuously.
It is usefull when we want to execute certain
application after certain interval.
There is no visual representation. It add the bottom
of the page.
Property of Timer control is less than any other
controls.
Following is some important property of timer name.
Enable : it is always true to
work with timer control other wise tick event does not fire.
Interval : it allow to set
frequency of event time interval in millisecond.
Tick event of timer control occurs when a specific
time interval is set.
·
Panel
& Group Box :
Panel and Groupbox are that contain other controls.
They both work as a container of other control. Use groupbox
and panel to logically. Group is collection of a control on a form.
Mainly there are two use of it.
1. Radio
Button group.
2. Make
a logical group of controls so that in a one click can visible or enable all
child control.
By default panel control is display without any
border.
Panel control does not have text property.
Groupbox display border around a group of control with
or without caption.
Following is difference between groupbox and panel.
GroupBox
|
Panel
|
A groupbox control can be plce with a title
|
A panel control can bnot be place with a title
|
It can not display the scrollbar
|
It can display the scrollbar
|
Only limited number of control can be placed within
the groupbox
|
Any numbers of conrol can be placed within the
panel.
|
It is a light wait component
|
It is a heavy wait component
|
It does not have tab stop property
|
It have tab stop property.
|
8. MDI concept
·
There are mainly 2 style of user interface that is.
1. SDI
(single Document Interface)
2. MDI
(Multiple Document Interface)
·
SDI means only single document may be open so must
close one document in ordered to open another.
·
While the MDI allow you to create an application what
maintain multiple forms within a single container form.
·
And MDI application allows us to display and open
multiple documents at the same time.
·
MS Word, MS Excel is the example of MDI.
·
MS Excel allows us to work with several documents at
once.
·
It means MDI application follow a parent form and
child form relationship.
·
The parent MDI form organizes and arranges all the child
form or documents that are currently open.
·
MDI form requires a menustrip control to manipulate
all the forms frequently in an application.
9 : Concept of Inheriting Form
Answer: Creating
new Windows Forms by inheriting from base forms is a handy way to duplicate
your best efforts without going through the process of entirely recreating a
form every time you require it.
To inherit a form programmatically
1.
In your class, add a reference to
the namespace containing the form you wish to inherit from.
2.
In the class definition, add a
reference to the form to inherit from. The reference should include the
namespace that contains the form, followed by a period, then the name of the
base form itself.
public class Form2 : Namespace1.Form1
When inheriting forms, keep in mind that issues may
arise with regard to event handlers being called twice, because each event is
being handled by both the base class and the inherited class.
:: Best Of Luck ::
Please Share and Comment it... Thanks