0% found this document useful (0 votes)
4 views

Unit 2_Notes

The document outlines important classes used in C# for developing Windows applications, including Input/Output, String Handling, and Drawing classes, among others. It also explains how to create and customize Windows Forms, including adding buttons, labels, and controls like TextBox, CheckBox, and RadioButton. Additionally, it discusses ListBox and ComboBox controls, as well as the use of menus and dialog boxes for user interaction.

Uploaded by

yogijadhav708
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Unit 2_Notes

The document outlines important classes used in C# for developing Windows applications, including Input/Output, String Handling, and Drawing classes, among others. It also explains how to create and customize Windows Forms, including adding buttons, labels, and controls like TextBox, CheckBox, and RadioButton. Additionally, it discusses ListBox and ComboBox controls, as well as the use of menus and dialog boxes for user interaction.

Uploaded by

yogijadhav708
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Unit 2

Windows Application & Windows Controls

2.1 Important classes used in windows Application.

In C# Programming for developing the windows application there are


several pre-define classes, these pre-define classes are the part of windows
framework.
.net provide set of library classes which are called as system classes.

 following are the classes used in windows.

1. Input/ Output Class:-


in C# programming I/O classes are used to represent all system I/O
operations by using several methods.

2. String Handling Class:-


this class are used for performing the string operation like compare,
concat, copy, as well as length these all methods are present in class
3. Array-list Class:-
Array-list class is used to perform all array operations such as clear, insert,
sort, reverse, copy this all are the array operations can be perform in C#.

4. Drawing Class:-
Drawing class is used in C# program for working with some drawing
operations such as like line, rectangle, circle.

5.Security Class:-
security classes are used to provide security to the member of the form by
including several components like excepections handler, I/O
controller and data Safety.

6. Database Class:-
these are include by using system database it work about all the database
connectivity process like add new record, delete record and modify record.

7. Registry Class:-
it is compulsory for every windows application because after drag and drop
any control. its compulsory to make registry every control in our application.

8. Mathematical Class:-
this class are used in C# windows project for performing the mathmatical
functions like Sin, Cos, Tang and Log etc.

Above all are the windows classes in C# for make interaction with C#
project.

2.2 Creating & Customizing Windows Form.

After you select your C# project template and name your project, Visual
Studio opens a form for you. A form is a Windows user interface. Create a Hello
World application by adding controls to the form. Then run the app.

Add a button to the form

1. Select Toolbox to open the Toolbox flyout window.

1. If you don't see the Toolbox option, you can open it from the menu bar.
Select View > Toolbox or Ctrl+Alt+X.
2. Expand Common Controls and select the Pin icon to dock
the Toolbox window.

3. Select the Button control and then drag it onto the form

4. In the Properties window, locate Text. Change the name


from button1 to Click this, and then select Enter.
If you don't see the Properties window, you can open it from the menu bar.
Select View > Properties Window or F4.

5. In the Design section of the Properties window, change the name


from button1 to btnClickThis, and then select Enter.

Add a label to the form

After you add a button control to create an action, add a label control to send
text to.
1. Select the Label control from the Toolbox. Then drag it onto the form and
drop it beneath the Click this button.

2. In either the Design section or the (DataBindings) section of


the Properties window, change the name of label1 to lblHelloWorld. Then
select Enter.

Add code to the form:

1. In the Form1.cs [Design] window, double-click the Click this button to


open the Form1.cs window.

Alternatively, you can expand Form1.cs in Solution Explorer, and then


choose Form1.

2. In the Form1.cs window, after the private void line, type or


enter lblHelloWorld.Text = "Hello World!"; as shown in the following
screenshot.
2.3 TextBox & Label Control.

TextBox control:
In Windows forms, TextBox plays an important role. With the help of
TextBox, the user can enter data in the application, it can be of a single line or
of multiple lines.
The TextBox is a class and it is defined
under System.Windows.Forms namespace. In C#, you can create a TextBox in
two different ways:
1. Design-Time: It is the simplest way to create a TextBox as shown in the
following steps:
Label Control.
2.4 Button, Checkbox, Radio Button.

Button:
A Button is an essential part of an application, or software, or webpage. It
allows the user to interact with the application or software.

For example, if a user wants to exit from the current application so, he/she
click the exit button which closes the application. It can be used to perform
many actions like to submit, upload, download, etc. according to the
requirement of your program. It can be available with different shape, size,
color, etc.

and you can reuse them in different applications. In .NET Framework, Button
class is used to represent windows button control and it is inherited
from ButtonBase class.

It is defined under System.Windows.Forms namespace.


In C# you can create a button on the windows form by using two different
ways:
Checkbox:
The CheckBox control is the part of windows form which is used to take input
from the user. Or in other words, CheckBox control allows us to select single
or multiple elements from the given list or it can provide us options like yes or
no, true or false, etc.

It can be displayed as an image or text or both. The CheckBox is a class and


defined under System.Windows.Forms namespace.

In Windows form, you can create CheckBox in two different ways:

1. Design-Time: It is the simplest way to create a CheckBox using the


following steps:
RadioButton

In Windows Forms, RadioButton control is used to select a single option


among the group of the options. For example, select your gender from the
given list, so you will choose only one option among three options like Male
or Female or Transgender.

In C#, RadioButton is a class and it is defined


under System.Windows.Forms namespace. In RadioButton, you are allowed to
display text, image, or both and when you select one radio button in a group
other radio buttons automatically clear.

You can create RadioButton in two different ways:

1. Design-Time: It is the easiest way to create a RadioButton control as shown


in the following steps:
Difference Between Checkbox and Radio Button:
Check Box: Check boxes are designed for multiple options. Users can change
the state of each checkbox independently, allowing multiple options to be
selected at the same time.
Radio Button: But the radio button is used for selecting one in a group.
Selecting one radio button automatically selects any other radio button in the
same group.

Checkboxes: Checkboxes are usually independent objects. Each checkbox


operates independently of the others on the form, and users can select or
deselect it without affecting the state of the other checkboxes.

Radio Buttons: Radio buttons are often used in groups. When radio buttons are
stacked, they form an adversarial set, where only one option can be selected at a
time. This is done by linking all radio buttons in a group to a common parent
object.

Checkbox: Creating a checkbox in Java involves instantiating an instance of


the JCheckBox class. Each checkbox is created separately, and their states are
managed independently.

Radio Button: Java's JRadioButton class is used to create radio buttons. To


ensure exclusivity within a group, radio buttons are usually added to a
ButtonGroup object, which enforces the single-selection constraint.

Checkbox: Checkboxes are suitable when users need to make multiple


selections or when each option is independent of others. For example, in a
settings panel, users might toggle various options like enabling/disabling
features.

Radio Button: Radio buttons are ideal when users need to make a single choice
from a set of mutually exclusive options. Common scenarios include selecting a
gender or choosing a mode of operation (e.g., "Light Mode" or "Dark Mode").

2.5 Listbox, combobox control

Listbox:

In Windows Forms, ListBox control is used to show multiple elements in a


list, from which a user can select one or more elements and the elements are
generally displayed in multiple columns.

The ListBox class is used to represent the windows list box and also provide
different types of properties, methods, and events.
It is defined under System.Windows.Forms namespace. The ListBox class
contains three different types of collection classes, i.e.
 ListBox.ObjectCollection: This class holds all the elements contained in
the ListBox control.

 ListBox.SelectedObjectCollection: This class holds a collection of the


selected items which is a subset of the items contained in the ListBox
control.

 ListBox.SelectedIndexCollection: This class holds a collection of the


selected indexes, which is a subset of the indexes of
the ListBox.ObjectCollection and these indexes specify elements that are
selected.

In C# you can create a ListBox in the windows form by using two different
ways:

1. Design-Time: It is the easiest way to create a ListBox as shown in the


following steps:
combobox control:

In Windows Forms, the ComboBox control combines the features of a


TextBox and a ListBox.

It displays a single item at a time, with additional items accessible through a


drop-down menu. The ComboBox class is part of the System.Windows.Forms
namespace in C#.

We can create a ComboBox in two ways basically which are – Design-Time


and Run-Time.
2.6 Menus & Dialog boxes.

Menus

To apply the same property settings to multiple Menu controls, use


the Style property. You can modify the default ControlTemplate to give the
control a unique appearance.

For more information about creating a ControlTemplate, see Customizing the


Appearance of an Existing Control by Creating a ControlTemplate. To see the
parts and states that are specific to the Menu, see Menu Styles and Templates.

Dependency properties for this control might be set by the control's default
style. If a property is set by a default style, the property might change from its
default value when the control appears in the application.

The default style is determined by which desktop theme is used when the
application is running.
Dialog boxes.

A dialog box is a temporary window an application creates to retrieve user


input. An application typically uses dialog boxes to prompt the user for
additional information for menu items.

A dialog box usually contains one or more controls (child windows) with which
the user enters text, chooses options, or directs the action.

Windows also provides predefined dialog boxes that support common menu
items such as Open and Print.

Applications that use these menu items should use the common dialog boxes to
prompt for this user input, regardless of the type of application.

You might also like