By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

on button click-context menu strip

P: 18
I have 30 buttons and I am trying to implement context menu on each button click by using following method.
void OnButtonClick(object sender, EventArgs e)
Button btn = (Button)sender;
btn.ContextMenuStrip.Show(btn, new System.Drawing.Point(0, btn.Height));
I have 2 context menu strip items, Add text Label and Add colour
private void addTextLabelToolStripMenuItem_Click(object sender, EventArgs e)
foreach (Control item in panel2.Controls)
Button btn = (Button)item;
if (string.IsNullOrEmpty(btn.Text.Trim()))
frmAddText form = new frmAddText();

if (frmAddText.IsTextMod)
btn.Text = form.TextInfo;
btn.Tag = 0;
} } }
Wen i try to do this it is implementing on last button itself. Here Ia m returning
Here foreach is not acceptable.

private void addColourToolStripMenuItem_Click(object sender, EventArgs e)
DialogResult dResult = colorDialog1.ShowDialog();
foreach (Control item in panel2.Controls)
Button btn = (Button)item;
string strBtnName = btn.Name;
if (string.Equals(btn.Name, strBtnName, StringComparison.OrdinalIgnoreCase))
if (dResult == DialogResult.OK)
btn.BackColor = colorDialog1.Color;
} } }
It is applying color to all buttos. But it should apply for only specific clicked button. Here foreach is not acceptable.
Feb 12 '09 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 3,525
Was there a question you wanted to ask? Your post is a series of statements with no question and no mention of an error you are getting.
Feb 13 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.