Professional Documents
Culture Documents
System.MarshallByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.Control
System.Windows.Forms.ButtonBase
System.Windows.Forms.ScrollableControl
System.Windows.Forms.TextBoxBase
DataGrid,DataGridView,DataTimePicker,
GroupBox,Label,ListControl,ListView,
MidClient,MonthCalendar,PictureBox,
PrinterPreviewControl,ProgressBar,
ScrollBar,splitter,StatusBarTabControl,
ToolBar,TrackBar,TreeView
System.Windows.Forms.ButtonBase
System.Windows.Form.RadioButton
System.Windows.Form.Button
System.Windows.Form.CheckBox
System.Windows.Form.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.Form
System.Windows.Form.RaftingContainer
System.Windows.Form.PropertyGrid
System.Windows.FormUpDownBase
System.Windows.Form.SplitContainer
System.Windows.Form.UserControl
System.Windows.Forms.Panel
System.Windows.Form.ToolStrip
System.Windows.Form.ActivDocumentHost
System.Windows.Form.TextBoxBase
System.Windows.Forms.TextBox
System.Windows.Form.RichTextBox
Creating a project
Click OK
What gets created…
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should
be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
}
}
System.Windows.Forms.Form
• Form class
• represents a window within an application including
dialog boxes, modeless windows, and Multiple
Document Interface (MDI) client and parent windows.
• derives from ContainerControl Class which means
they are special type of controls that can function as a
container for other controls.
• Examples of some of the methods of a
ContainerControl Class (as well as the Form) are
• Dispose(): Releases the resources used by the
Component.
• Refresh() :Forces the control to invalidate its client area
and immediately redraw itself and any child controls
• And all the properties that appears on the form property box
Controls
• data entry controls
• TextBox
• ComboBox
• Display controls
• Label
• ListView
• Command Controls
• Button
• ToolBar
Components
• Both Form and Controls derive from the
Control class.
• There are some ‘components’ that do not derive
from the Control class but still provide visual
features to a Windows-based application.
• Examples
• ToolTip and ErrorProvider, extend the
capabilities or provide information to the user.
• Menu, MenuItem, and ContextMenu, provide
the ability display menus to the user to invoke
commands within an application
• The Help and HelpProvider classes enable
you to display help information to the user of
your applications.
Common Dialog Boxes
• The OpenFileDialog and SaveFileDialog
classes provide the functionality to display a
dialog box that allows the user to browse to and
enter the name of a file to open or save.
• The FontDialog class displays a dialog box to
change elements of the Font object used by
your application
• The PageSetupDialog,
PrintPreviewDialog, and PrintDialog
classes display dialog boxes that allow the user
to control aspects of printing documents.
• MessageBox class for displaying a message box
that can display and retrieve data from the user
Does not fall into ‘common’ dialog box
Creating a forms with controls
View Toolbar
Drag and Drop Controls
Simple Example
• We will enter Name and ID in two text boxes and
display them on the screen when ok button is
clicked.
• Drag three Labels and two TextBoxes.
• Drag a button.
• Change the title of labels to Name and ID. Make
the third labels ‘visible’ property as false. Change
the title of the Button to OK.
• Change the name of the TextBoxes – one to
NameTxt and other to IDTxt.
• Double click on the button to add code on what
will happen when it is clicked.
using System;
using System.Collections.Generic;
…
namespace WApp1{
public partial class EmployeeForm : Form
{
public EmployeeForm() {
InitializeComponent();
}
private void OKBtn_Click(object sender, You add this
EventArgs e) {
ResultL.Text = NameTxt.Text + "( ID )" +
IDTxt.Text;
ResultL.Visible = true;
}
}} TIP : After typing a part of the control name, you could press CTRL-SPACE
to invoke the ‘CODE ASSIST’.
Try it out
• Add a combo box called hobbies with ‘Reading’,
‘Writing’ , ‘Drawing’ and ‘Programming’
• On clicking ok the selected text must appear
concatenated in the result label.
errorProvider1.Clear();
if (NameTxt.Text.Length == 0 )
errorProvider1.SetError(NameTxt, "Must enter a value");
try {
if (IDTxt.Text.Length > 0 && Convert.ToInt32(IDTxt.Text) <
1)
errorProvider1.SetError(IDTxt, "Must be a non-zero +ve
number");
} catch (Exception ex) {
errorProvider1.SetError(IDTxt, "Must be a non-zero +ve
number");
}
ResultL.Text = NameTxt.Text + "( ID:" + IDTxt.Text + ")
Hobby:" + comboBox1.Text;
ResultL.Visible = true;
On Executing….
Creating new form