C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet1063/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   1059   1060   1061   1062   1063   1064   1065   1066   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

MyButtonClick( )

 is called.



An Alternative Implementation

As a point of interest, 



MyButtonClick( )

 could have been written in a slightly different way. 

Recall that the 

who

 parameter of an event handler receives a reference to the object that 

generated the call. In the case of a button click event, this is the button that was clicked. 

Thus,


MyButtonClick( )

 could have been written like this:

// An Alternative button handler.

void MyButtonClick(object who, EventArgs e) {

  Button b = (Button) who;

  if(b.Top == 200)

    b.Location = new Point(10, 10);

  else


    b.Location = new Point(100, 200);

}

In this version, 



who

 is cast to 



Button

, and this reference (rather than the 



MyButton

field) is used to access the button object. Although there is no advantage to this approach in 

this case, it is easy to imagine situations in which it would be quite valuable. For example, 

such an approach allows a button event handler to be written independently of any specific 

button.

Using a Message Box

One of the most used built-in features of Windows is the 



message box.

 A message box is a 

predefined window that lets you display a message. You can also obtain simple responses 

from the user, such as Yes, No, or OK. In a form-based program, a message box is supported 

by the 

MessageBox

 class. You don’t create an object of that class, however. Instead, to 

display a message box, call the 

static

 method 


Show( )

, which is defined by 



MessageBox

.

The



Show( )

 method has several forms. The one we will be using is shown here:

public static DialogResult Show(string 

msg

, string 



caption

,

                                                         MessageBoxButtons 



mbb

)

The string passed through 



msg

 is displayed in the body of the box. The caption of the 

message box window is passed in 

caption.

 The buttons that will be displayed are specified 

by

mbb.

 The user’s response is returned.



MessageBoxButtons

 is an enumeration that defines the following values:

Abor tRetr yIgnore

OK

OKCancel



Retr yCancel

YesNo


YesNoCancel

Each of these values describes the buttons that will be included in a message box. For example, 

if

mbb

 contains 



YesNo

, then the Yes and No buttons are included in the message box.

The value returned by 

Show( )

 indicates which button was pressed. It will be one of 

these values, defined by the 

DialogResult

 enumeration:

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   1059   1060   1061   1062   1063   1064   1065   1066   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish