This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// Handler for the File | Exit event



Download 21,46 Mb.
Pdf ko'rish
bet1810/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   1806   1807   1808   1809   1810   1811   1812   1813   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Handler for the File | Exit event.

private void mnuFileExit_Click(object sender, EventArgs e)

{

Application.Exit();



}

}

First off, notice that the MainWindow type now maintains three new member variables. The



MenuStrip type represents the entirety of the menu system, where a given ToolStripMenuItem

represents any given topmost menu item (e.g., File) or submenu item (e.g., Exit) supported by

the host.



Note

If you have programmed with earlier versions of Windows Forms (1.0 or 1.1), you may recall that the

MainMenu

type was used to hold any number of 

MenuItem

objects. The 

MenuStrip

control (introduced with

.NET 2.0) is similar to 

MainMenu


; however,

MenuStrip

is able to contain controls beyond “normal menu items”

(combo boxes, text boxes, etc.).

C H A P T E R   2 7  

P R O G R A M M I N G   W I T H   W I N D O W S   F O R M S



959

8849CH27.qxd  10/16/07  11:59 AM  Page 959




The menu system is configured within our BuildMenuSystem() helper function. Notice that the

text of each ToolStripMenuItem is controlled via the Text property, each of which has been assigned

a string literal containing an embedded ampersand symbol. As you may already know, this syntax

sets the Alt key shortcut, thus selecting Alt+F will activate the File menu, while selecting Alt+X will

activate the Exit menu. Also notice that the File ToolStripMenuItem object (mnuFile) adds subitems

via the DropDownItems property. The MenuStrip object itself adds a topmost menu item via the Items

property.

Once the menu system has been established, it is then added to the controls collection (via the

Controls property), after which we assign our MenuStrip object to the inherited MainMenuStrip

property. While this step may seem redundant, having a specific property such as MainMenuStrip

makes it possible to dynamically establish which menu system to show a user, perhaps due to user

preferences or security settings.

The only other point of interest is the fact that we are

handling the Click event of the File ➤ Exit menu, in

order to capture when the user selects this submenu. The

Click event works in conjunction with a standard dele-

gate type named System.EventHandler. This event can

only call methods that take a System.Object as the first

parameter and a System.EventArgs as the second. Here,

our delegate target (mnuFileExit_Click) has been imple-

mented to terminate the entire Windows application

using the static Application.Exit() method.

Once this application has been recompiled and exe-

cuted, you will now find your simple window sports a

custom menu system (see Figure 27-3).


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   1806   1807   1808   1809   1810   1811   1812   1813   ...   1830




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