📄 c++ builder 程序设计实用教程 - 3_2_1 菜单及其概述 - 张晋 - 17xie.htm
字号:
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN
lang=EN-US>3-15<SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">放置了“主菜单设计器“的窗体</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">虽然在窗体上放置了“主菜单设计器”,但是只有激活了“主菜单设计器”才能够对主菜单进行设计等操作,激活“主菜单设计器”的方法也有两种:</SPAN></P>
<P class=MsoNormalIndent
style="MARGIN-LEFT: 42.5pt; TEXT-INDENT: -21.25pt; tab-stops: list 21.25pt; mso-list: l0 level1 lfo2"><SPAN
lang=EN-US
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN
style="mso-list: Ignore">n<SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用鼠标的左键在“主菜单设计器”上双击,在屏幕上就会弹出一个空白的主菜单设计窗口;</SPAN></P>
<P class=MsoNormalIndent
style="MARGIN-LEFT: 42.5pt; TEXT-INDENT: -21.25pt; tab-stops: list 21.25pt; mso-list: l0 level1 lfo2"><SPAN
lang=EN-US
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN
style="mso-list: Ignore">n<SPAN
style="FONT: 7pt 'Times New Roman'">
</SPAN></SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在控件的属性列表中用鼠标的左键单击</SPAN><SPAN
lang=EN-US>Items</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性右侧属性输入框中的</SPAN><SPAN
lang=EN-US style="mso-font-kerning: 0pt; mso-no-proof: yes"><IMG height=15
src="C++ Builder 程序设计实用教程 - 3_2_1 菜单及其概述 - 张晋 - 17xie.files/4e92d9c803.jpg"
width=15 v:shapes="_x0000_i1026"></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt; mso-no-proof: yes">按钮也可以打开主菜单设计器。</SPAN></P>
<H4><SPAN lang=EN-US>3</SPAN><SPAN
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.添加菜单项</SPAN></H4>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在刚添加的“主菜单设计器”上双击鼠标的左键,就会弹出一个如图</SPAN><SPAN
lang=EN-US>3-16</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示的主菜单设计窗口。</SPAN></P>
<P class=a><SPAN lang=EN-US><IMG height=181
src="C++ Builder 程序设计实用教程 - 3_2_1 菜单及其概述 - 张晋 - 17xie.files/45fbfddf58.jpg"
width=284 v:shapes="_x0000_i1027"></SPAN></P>
<P class=MsoCaption><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN
lang=EN-US>3-16<SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开的主菜单设计器</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在主菜单设计器中对主菜单及其子菜单项的属性设置如下所示,读者可以打开项目文件所对应的窗体文件(以</SPAN><SPAN
lang=EN-US>*.dfm</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为文件后缀)来观察程序中对窗体及各个控件的属性设置,由于“主菜单设计器”也属于控件类,所以相应菜单项的属性设置也可以在窗体文件中观察到。</SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">object
Form1: TForm1<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Left = 192<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Top = 107<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Width = 544<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Height = 375<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Caption = 'Form1'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Menu = MainMenu1<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object MainMenu1:
TMainMenu<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Left =
464<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Top =
264<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object File1:
TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>Caption =
'File'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object New1:
TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>Caption = 'New'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object Open1:
TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>Caption = 'Open'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object Close1:
TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>Caption = 'Close'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object Save1:
TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>Caption = 'Save'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>object Exit1:
TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>Caption = 'Exit'<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>end<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">end<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">经过以上设置的菜单如图</SPAN><SPAN
lang=EN-US>3-17</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示。</SPAN></P>
<P class=a><SPAN lang=EN-US><IMG height=220
src="C++ Builder 程序设计实用教程 - 3_2_1 菜单及其概述 - 张晋 - 17xie.files/380e8f160e.jpg"
width=320 v:shapes="_x0000_i1028"></SPAN></P>
<P class=MsoCaption><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN
lang=EN-US>3-17<SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置属性值后的主菜单</SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">经过这样设置的“主菜单设计器”拥有一个主菜单项“</SPAN><SPAN
lang=EN-US>File</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”,在这个菜单项下有</SPAN><SPAN
lang=EN-US>5</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个子菜单项——“</SPAN><SPAN
lang=EN-US>New</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN-US>Open</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN-US>Close</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN-US>Save</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN
lang=EN-US>Exit</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”。</SPAN></P>
<H4><SPAN lang=EN-US>4</SPAN><SPAN
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.修改菜单项</SPAN></H4>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值得注意的是,以上的设计菜单的方法只是一种通用的方法,我们也可以通过在程序设计过程中修改项目文件的窗体文件来达到设计菜单的目的,如上例所示,在主菜单“</SPAN><SPAN
lang=EN-US>File</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”下有</SPAN><SPAN
lang=EN-US>5</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">个子菜单项,我们可以首先打开程序的窗体文件,然后在子菜单项</SPAN><SPAN
lang=EN-US>Save</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN
lang=EN-US>Exit</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之间添加如下内容:</SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">object
Save2: TMenuItem<o:p></o:p></SPAN></P>
<P class=a0><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">Caption =
'Save as'<o:p></o:p></SPAN></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -