0% found this document useful (0 votes)
54 views25 pages

CH3 3

The document discusses different ways to display message boxes and input boxes in C#.NET applications. It describes how to use the MessageBox.Show method to display basic message boxes with text. It also explains how to add a title, buttons like Yes/No, and icons. The document shows code examples of displaying message boxes with these additional features. It also demonstrates how to handle message box events by checking the dialog result. Finally, it briefly mentions the need for field-level validation when taking user input through text boxes, lists, and other controls.

Uploaded by

Mikiyas Getasew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views25 pages

CH3 3

The document discusses different ways to display message boxes and input boxes in C#.NET applications. It describes how to use the MessageBox.Show method to display basic message boxes with text. It also explains how to add a title, buttons like Yes/No, and icons. The document shows code examples of displaying message boxes with these additional features. It also demonstrates how to handle message box events by checking the dialog result. Finally, it briefly mentions the need for field-level validation when taking user input through text boxes, lists, and other controls.

Uploaded by

Mikiyas Getasew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Message Boxes and Input Boxes

Compiled By Abrham Y. 1
Message Boxes

• One way of C#.net application interact with


the user is by displaying dialog box
• It is possible to design dialog box of your
own and you indeed usually do that

Compiled By Abrham Y. 2
The MessageBox.Show method

• In C#.Net you can use the .Net framework’s


MessageBox.Show method to display
message boxes.
• This method has many overload forms with
a list of arguments.
• You have to pass the following arguments
to this methods

Compiled By Abrham Y. 3
Cont…
arguments Description
methods
Text Display text in the message box
Caption Display text in the title bar of the message box
Button Specifies a messageBox Button enumeration values that
determine which button to display in the message boc
Icon Specifies MessageBoxIcon enumeration values that determine
which icon to display in the message box
DefaultButton

etc etc

Compiled By Abrham Y. 4
You can add a text to a C#.net
Message Box
• We can call MessageBox.Show with just one
argument
MessageBox.Show(“My First Message”);
Example1 :
Step1:Design and create the user interface

Compiled By Abrham Y. 5
Cont..
Step2:write code
The application should respond to Show
Message Box click event by display a
message box with text My First Message

Compiled By Abrham Y.
6
You can add a Title to a C#.net
Message Box
• Let's add a second argument to our Show
method call
MessageBox.Show(“My First
Message”,Message”);
Example 2 :
Step2:write code
The application should respond to Show Message
Box ( example1 )click event by display a
message box with text My First Message and
7
title Message Compiled By Abrham Y.
Cont..

Compiled By Abrham Y. 8
You can add a button like Yes, No and
Cancel to a C#.net Message Box
• Sometimes we want to ask a question. The question is answered with Yes or
No. We can provide the MessageBoxButtons. YesNo enum argument for this
• A MessageBox can have different button combinations such as YesNo and
OKCancel.
• The MessageBoxButtons enumeration represents the buttons to be displayed
on a MessageBox and has following values.
• OK
• OKCancel
• AbortRetryIgnore
• YesNoCancel
• YesNo
• RetryCancel

Compiled By Abrham Y. 9
Cont..
MessageBox.Show(“My First
Message”,Message”,MessageBoxButton.Yes
No);
Example 3 :
Step2:write code
The application should respond to Show
Message Box ( example1 )click event by
display a message box with text My First
Message , title Message and yes No cancel
buttons Compiled By Abrham Y. 10
Cont..

Compiled By Abrham Y. 11
Adding Icon to a C#.net Message Box

MessageBox.Show(“My First
Message”,Message”,MessageBoxButton.YesNo,Messa
geBoxIcon.Exclamation);
Example 4 :
Step2:write code
The application should respond to Show Message Box (
example1 )click event by display a message box with
text My First Message , title Message , yes No cancel
buttons and stop icon

Compiled By Abrham Y. 12
Cont..

Compiled By Abrham Y. 13
Handling MessageBox events
• The show method returns a DialogResult
• DialogResult: We assign a variable to the
result of MessageBox.Show. We can later
test r1 to find out which button was clicked.

Compiled By Abrham Y. 14
Cont…
DialogResult r=MessageBox.Show(“My First
Message”,Message”,MessageBoxButton.Ye
sNo,MessageBoxIcon.Exclamation);
Example 5: write a code that respond to
yesno click event by display a message box
you click yes for yes button and you click
no for no buttons

Compiled By Abrham Y. 15
Cont..

If(r==DialogResult.Yes)
MessageBox.show(“you click yes”);
If(r==DialogResult.No)
MessageBox.show(“you click No”);

Compiled By Abrham Y. 16
Validation

Compiled By Abrham Y. 17
Validation

• In the above example code will work fine with out


any problem but there are some bugs available to
be solved are call field level validation
18
Compiled By Abrham Y.
List of validations to be implemented to above example

1. With textbox1
 User should be allowed to enter only digits
 Entering data into textbox1 is mandatory
2. Withtextbox2
 User should be allowed to enter only digits
 Entering data into textbox2 is mandatory
3. With button divide
 Textbox2 data should be zero
Compiled By Abrham Y. 19
Char structure
• This structure provide various function that allows the programmer to
work with single character
• Functions in char structure
 Char.IsLetter(“charactr”)
 Char.IsDigit(“charactr”)
 Char.IsSymbol(“charactr”)
 Char.IsLetterOrDigit(“charactr”)
 Char.IsLower(“charactr”)
 Char.IsUpper(“charactr”)
 Char.ToLower(“charactr”)
 Char.IsUpper(“charactr”)

Compiled By Abrham Y. 20
Naming Controls
Compiled By Abrham Y. 21
Naming Controls
Purpose
1. To understand real time naming conventions
2. To understand and implementation function or field level
validation
• In general in real time programming programmers is not
supposed to assign the name of the controls rather project
leaders /system analyst will design the form ,report and the
control to be present in those , what name to be given to the
control with in the design document
• Programmers should use the same name given in the design
document
Compiled By Abrham Y. 22
Cont..
• Programmers should use the same name given in the design documents
• In general control name can be divided in to two parts
– Control identification
– Purpose of the control
Control identification
– TextBox ---> txt
– Button------btn/cmd
– Label------lbl
– ListBox--lst
– Combobox-cmb
– RadioButton-opt
– CheckBox---chk

Compiled By Abrham Y. 23
Cont…
Purpose of the control
– For accepting ac no in bank application---Acno
– For accepting ac holder name in bank application---ACHName
Example of some sample control naming are like
– txtAcno
– txtACHName
– btnAccept
– btnSearch

Compiled By Abrham Y. 24
Next: controls
RadioButton,
ListBox,
CheekBox and
ComboBox Compiled By Abrham Y. 25

You might also like