C# doc2
C# doc2
C# doc2
Properties window. It also consists of a toolbox which contains many useful controls that allow a
programmer to develop VC# programs.
Form Designer: it is a window for each form to customize the designed interface of the application.
Using the form designer, the user can add controls, graphics, and text to create the desired form
appearance.
Project Explorer Window: it is a list of the forms and modules for the current projects. It is a
hierarchical tree- branch structure, where the project at top of tree and other parts like forms ,modules
descend from this tree.
Properties Window: it is a List of properties settings for a selected form or a control. These properties
are characteristics (such as size, visible, or color) of the selected object it provides an easy way to set
properties.
ToolBox: it contains a collection of tools that are needed for project design.
Frequently used common controls are Button, Label, ComboBox, ListBox, PictureBox,
and TextBox. To insert a control into your form in Visual C# IDE, drag the control from the
toolbox and drop it onto the form. You can reposition and resize it as you like.
Object:
An object is a type of user interface element you create on a Visual C # form by using a toolbox control.
Form itself is an object.
Every Visual C# 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.
Control Properties
All the VC# Objects can be moved, resized or customized by setting their properties.
A property is a value or characteristic held by a VC# object, such as Caption or Font Colour.
Properties can be set at:
Design time using the Properties window.
At run time using statements in the program code.
Syntax:
Object. Property = Value;
Where
Object is the name of the object.
Property is the characteristic you want to change.
Value is the new property setting.
Example:
Form1.Text = "Dept CS&IT";
Control Methods
A method is a procedure created as a member of a class and they cause an object to do something. Methods are
used to access or manipulate the characteristics of an object or a variable. There are mainly two categories of
methods you will use in your classes −
If you are using a control such as one of those provided by the Toolbox, you can call any of its public
methods. The requirements of such a method depend on the class being used.
If none of the existing methods can perform your desired task, you can add a method to a class.
For example, the MessageBox control has a method named Show, which is called in the code as below −
Control Events
The action that is used to perform a method or a task. For 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 control like:
Click
double click The control that generates an
close event is known as the event
sender.
load
resize, etc.
{
listBox1.Sorted = true;
}
If you want to initialize some variables like properties, etc., then you will keep such code
inside Form1_Load() subroutine. You can create additional event handlers through the Properties window
KeyDown Occurs when a key is pressed while the control has focus.
KeyPress: Occurs when a key is pressed while the control has focus.
KeyUp: Occurs when a key is released while the control has focus. TEXTBOX
Basic Controls
VC#.Net provides a 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. The following table lists some of the commonly used controls :
Control Description
Forms The container for all the controls that make up the user interface. used to create the GUIs for
programs.
It enables the user to select a single option from a group of choices when paired with other
RadioButton
RadioButton controls.
It represents a Windows control that allows the user to select a date and a time and to display
DateTimePicker
the date and time with a specified format.
It represents a Windows list view control, which displays a collection of items that can be
ListView
displayed using one of four different views.
Design Time Run Time
Programming Time
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Programming Time
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); //
}
{
listBox1.Sorted = true;
}
}
}