展开全部
你可以先在设计器里手动添加,然后在Designer.cs里找到相应代码剪切过来就行,如下
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton toolStripButton1;
private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem aAAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cCCToolStripMenuItem;
public Form1()
{
InitializeComponent();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.aAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bBBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cCCToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aAAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.Controls.Add(toolStrip1);
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(617, 25);
this.toolStrip1.TabIndex = 3;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripButton1
//
this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem,
this.bBBToolStripMenuItem,
this.cCCToolStripMenuItem});
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Size = new System.Drawing.Size(29, 22);
this.toolStripButton1.Text = "toolStripButton1";
//
// aAAToolStripMenuItem
//
this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAAToolStripMenuItem});
this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem";
this.aAAToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aAAToolStripMenuItem.Text = "AAA";
//
// bBBToolStripMenuItem
//
this.bBBToolStripMenuItem.Name = "bBBToolStripMenuItem";
this.bBBToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.bBBToolStripMenuItem.Text = "BBB";
//
// cCCToolStripMenuItem
//
this.cCCToolStripMenuItem.Name = "cCCToolStripMenuItem";
this.cCCToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.cCCToolStripMenuItem.Text = "CCC";
//
// aAAAToolStripMenuItem
//
this.aAAAToolStripMenuItem.Name = "aAAAToolStripMenuItem";
this.aAAAToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aAAAToolStripMenuItem.Text = "AAAA";
}
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton toolStripButton1;
private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem aAAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cCCToolStripMenuItem;
public Form1()
{
InitializeComponent();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.aAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bBBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cCCToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aAAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.Controls.Add(toolStrip1);
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(617, 25);
this.toolStrip1.TabIndex = 3;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripButton1
//
this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem,
this.bBBToolStripMenuItem,
this.cCCToolStripMenuItem});
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Size = new System.Drawing.Size(29, 22);
this.toolStripButton1.Text = "toolStripButton1";
//
// aAAToolStripMenuItem
//
this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAAToolStripMenuItem});
this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem";
this.aAAToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aAAToolStripMenuItem.Text = "AAA";
//
// bBBToolStripMenuItem
//
this.bBBToolStripMenuItem.Name = "bBBToolStripMenuItem";
this.bBBToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.bBBToolStripMenuItem.Text = "BBB";
//
// cCCToolStripMenuItem
//
this.cCCToolStripMenuItem.Name = "cCCToolStripMenuItem";
this.cCCToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.cCCToolStripMenuItem.Text = "CCC";
//
// aAAAToolStripMenuItem
//
this.aAAAToolStripMenuItem.Name = "aAAAToolStripMenuItem";
this.aAAAToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aAAAToolStripMenuItem.Text = "AAAA";
}
展开全部
比如说一个下拉菜单是cmbSelect
为它添加Items的代码是:
cmbSelect.Items.Add("Item1");
cmbSelect.Items.Add("Item2");
cmbSelect.Items.Add("Item3");
cmbSelect.Items.Add("Item4");
这样就有这样的4个item在下拉菜单中出现了。
另外可以到vs2008中的property中去查找你想添加的内容,然后那里呈现的关键字一般来讲就是你要在代码中添加的内容的关键字
比如,Property中Text一栏就是comboBox中的文本,而它对应的代码就是
cmbSelect.Text = "Item1";
为它添加Items的代码是:
cmbSelect.Items.Add("Item1");
cmbSelect.Items.Add("Item2");
cmbSelect.Items.Add("Item3");
cmbSelect.Items.Add("Item4");
这样就有这样的4个item在下拉菜单中出现了。
另外可以到vs2008中的property中去查找你想添加的内容,然后那里呈现的关键字一般来讲就是你要在代码中添加的内容的关键字
比如,Property中Text一栏就是comboBox中的文本,而它对应的代码就是
cmbSelect.Text = "Item1";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询