📄 快速动态创建menuitem.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Welcome to Delphi Tips !</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<link rel="stylesheet" href="../tips.css"></head>
<body bgcolor="#D8D0C8" text="#675350">
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="579" height="63" bordercolorlight="#784400" bordercolordark="#D8D0C8">
<tr>
<td width="194" height="86"><img src="../images/title.gif" width="340" height="85"></td>
<td width="377" height="86" valign="top"><img src="../images/dong.jpg" width="251" height="85">
</td>
</tr>
</table>
<br>
</div>
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="578" height="18" bordercolorlight="#784400" bordercolordark="#CCCCCC" class="p2">
<tr bgcolor="#B0A498">
<td width="574" height="18"> ><a href="../index.htm">DelphiTips首页</a>
> <a href="main.htm">控件应用</a></td>
</tr>
</table>
<br>
<table width="96%" border="1" bordercolorlight="#784400" cellspacing="0" bordercolordark="#D8D0C8">
<tr bgcolor="#B0A498" class="p1">
<td colspan="3">
<div align="center">快速动态创建MenuItem</div>
</td>
<td width="12%" class="p2"><<<a href="008.htm">上一篇</a></td>
<td width="13%" class="p2"><a href="010.htm">下一篇</a>>></td>
</tr>
<tr class="p2">
<td colspan="5">
<table width="100%" border="0" class="p2">
<tr>
<td width="3%"> </td>
<td width="94%"><span class="p2">在设计程序时,有时我们需要动态地创建菜单, 通常我们使用以下的语句</span>
<p><span class="p2"> PopupMenu1 := TPopupMenu.Create(Self);<br>
Item := TMenuItem.Create(PopupMenu1);<br>
Item.Caption := 'First Menu';<br>
Item.OnClick := MenuItem1Click;<br>
PopupMenu1.Items.Add(Item);<br>
Item := TMenuItem.Create(PopupMenu1);<br>
Item.Caption := 'Second Menu';<br>
Item.OnClick := MenuItem2Click;<br>
PopupMenu1.Items.Add(Item);<br>
Item := TMenuItem.Create(PopupMenu1);<br>
Item.Caption := 'Third Menu';<br>
Item.OnClick := MenuItem3Click;<br>
PopupMenu1.Items.Add(Item);</span></p>
<p><span class="p2"> Item := TMenuItem.Create(PopupMenu1);<br>
Item.Caption := '-';<br>
PopupMenu1.Items.Add(Item);<br>
Item := TMenuItem.Create(PopupMenu1);<br>
Item.Caption := 'Fourth Menu';<br>
Item.OnClick := MenuItem4Click;<br>
PopupMenu1.Items.Add(Item);<br>
其实我们可以使用一种更快的方法达到同样的功能, 但使用很少的代码, 那就是用NewLine和NewItem,
看看下面的例子, 是不是很简单?<br>
PopupMenu1 := TPopupMenu.Create(Self);<br>
with PopUpMenu1.Items do<br>
begin<br>
Add(NewItem('First
Menu',0,False,True,MenuItem1Click,0,'MenuItem1'));<br>
Add(NewItem('Second
Menu',0,False,True,MenuItem2Click,0,'MenuItem2'));<br>
Add(NewItem('Third
Menu',0,False,True,MenuItem3Click,0,'MenuItem3'));<br>
Add(NewLine);
// 增加一个分割棒<br>
Add(NewItem('Fourth
Menu',0,False,True,MenuItem4Click,0,'MenuItem4'));</span>
</td>
<td width="3%"> </td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#B0A498" class="p2">
<td height="22" width="61%" colspan="2"> <marquee behavior="alternate">如果你有什么好的资料,可以寄给我哟:)</marquee></td>
<td height="22" width="14%"><a href="../index.htm"><<回到首页</a></td>
<td height="22" width="12%"><<<a href="008.htm">上一篇</a></td>
<td height="22" width="13%"><a href="010.htm">下一篇</a>>></td>
</tr>
</table>
<br>
<br>
<hr size=1 noshade width=500>
<table width="75%" border="0" align="center" class="p2">
<tr>
<td colspan="2"> </td>
<td width="24%">
<table width="95%" border="1" bordercolorlight="#663300" bordercolordark="#CCCCCC" cellspacing="0" class="p2">
<tr>
<td>
<div align="center">Delphi 技巧集</div>
</td>
</tr>
</table>
</td>
<td width="38%"> </td>
</tr>
<tr>
<td width="16%"> </td>
<td colspan="2">Copyright 1999.11 by 东子</td>
<td width="38%"><a href="../jintongbao@188.net">Mail to me!</a></td>
</tr>
<tr>
<td colspan="4">
<div align="center">感谢广州视窗提供主页空间</div>
</td>
</tr>
</table>
<br>
</div><div align="center"><center>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -