110,535
社区成员
发帖
与我相关
我的任务
分享
//生成Button按钮
public void AddButton()
{
int x = 0;
int y = 101;
int z = 0;
for (int i = 0; i < 10; i++)
{
Button bn = new Button();
bn.Height = 50;
bn.Width = 80;
bn.Text = y.ToString();
if (x > 1000)
{
x = 0;
z += 80;
}
bn.Location = new Point(10 + x, 20 + z);
tabControlPanel1.Controls.Add(bn);
x += 100;
y += 1;
bn.BackColor = Color.Red;
bn.ContextMenuStrip = contextMenuStrip1;
//contextMenuStrip1.Enabled = false;
foreach (ToolStripItem info in this.contextMenuStrip1.Items)
{
if(bn.Text=="101")
{
info.Enabled = false;
}
}
//宾客结帐ToolStripMenuItem.Enabled = true;
//contextMenuStrip1.Click += new EventHandler(在ToolStripMenuItem_Click);
//if (bn.BackColor == Color.Red) {
}
}
[/quote]
你还少了个opening事件,针对不同的button 设置不同的效果
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
Button btn = (Button)contextMenuStrip1.SourceControl;
if (btn.Text == "button1")
{
toolStripMenuItem2.Enabled = false;
}
if (btn.Text == "aspose")
{
toolStripMenuItem3.Enabled = false;
}
}
//生成Button按钮
public void AddButton()
{
int x = 0;
int y = 101;
int z = 0;
for (int i = 0; i < 10; i++)
{
Button bn = new Button();
bn.Height = 50;
bn.Width = 80;
bn.Text = y.ToString();
if (x > 1000)
{
x = 0;
z += 80;
}
bn.Location = new Point(10 + x, 20 + z);
tabControlPanel1.Controls.Add(bn);
x += 100;
y += 1;
bn.BackColor = Color.Red;
bn.ContextMenuStrip = contextMenuStrip1;
//contextMenuStrip1.Enabled = false;
foreach (ToolStripItem info in this.contextMenuStrip1.Items)
{
if(bn.Text=="101")
{
info.Enabled = false;
}
}
//宾客结帐ToolStripMenuItem.Enabled = true;
//contextMenuStrip1.Click += new EventHandler(在ToolStripMenuItem_Click);
//if (bn.BackColor == Color.Red) {
}
}
ContextMenuStrip strip = new ContextMenuStrip();
strip.Opening += new CancelEventHandler(strip_Opening);
void strip_Opening(object sender, CancelEventArgs e)
{
(sender as ContextMenuStrip).Items[0].Enabled = false;
}