C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet1072/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   1068   1069   1070   1071   1072   1073   1074   1075   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

ToolStripMenuItem

, which is the modern equivalent of 



MenuItem

, also described in 

the previous section.

Using


MenuStrip

 and 


ToolStripMenuItem

 is similar to using a 



MainMenu

 and 


MenuItem

 as described in the previous section. Here is one way to create and use a 



MenuStrip

:

 1. 



Create 



MenuStrip

control.

 2. 


To 

the 


MenuStrip

 control, add 



ToolStripMenuItem

s that describe the top-level 

categories. This is done by calling 

Add( )

 on the collection referred to by the 



Items

property provided by 



MenuStrip

.

 



3.  To each top-level 

ToolStripMenuItem

, add the list of 



ToolStripMenuItem

s that 


defines the drop-down menu associated with that top-level entry. This is done by 

calling


Add( )

 on the collection referred to by the 



DropDownItems

 property.

 

4.  Add the event handlers for each selection.



 5. 

Add 


the 

MenuStrip

 to the list of controls for the form by calling 



Add( )

 on the 


Controls

 property.

 6. 

Assign 


the 

MenuStrip

 control to the 



MainMenuStrip

 property associated with the 

form.

Pay special attention to Steps 2 and 3 because they differ from the parallel steps used 



with

MainMenu

. First, in Step 2, top-level menu items that represent submenus are added 

to the collection referred to by 

Items

. Second, in Step 3, individual menu items are added to 

the collection referred to by the 

DropDownItems

 property. (Both 



MainMenu

 and 


MenuItem

use the 


MenuItems

 property for this purpose.) Other than those differences, the two 

procedures are essentially the same.

The following program demonstrates 



MenuStrip

 by reworking the program shown in 

the previous section. Sample output is shown in Figure 26-5. Notice that the menu now has 

a modern look.

// Use a MenuStrip.

using System;

using System.Windows.Forms;

class MenuForm : Form {

  MenuStrip MyMenu; // use a MenuStrip

  public MenuForm() {

    Text = "Use a MenuStrip";

    // Create a main menu object.

    MyMenu  = new MenuStrip();

    // Add top-level menu items to the menu.

    ToolStripMenuItem m1 = new ToolStripMenuItem("File");

    MyMenu.Items.Add(m1);

    ToolStripMenuItem m2 = new ToolStripMenuItem("Tools");

    MyMenu.Items.Add(m2);

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   1068   1069   1070   1071   1072   1073   1074   1075   ...   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