473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

on button click-context menu strip

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();
form.ShowDialog();

if (frmAddText.IsTextMod)
{
return;
}
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)
{
colorDialog1.ShowDialog();
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
1 15496
tlhintoq
3,525 Expert 2GB
@uday1302
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

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

Similar topics

6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
2
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived...
4
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
7
by: code100579 | last post by:
Hi there, sorry if this is a really simple question. I need to write code for: If a button is pushed and then one variety of other buttons is pushed then certain options on the program will...
2
by: dunderhead | last post by:
Hello, I am having a problem with function and class syntax. I have one class (MakePanel1) that creates a button and label. The button-click event of the button is linked to a function...
7
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, I create button in the code ( Dim Button as new Button), not using button web component (means not drap button and drop it ont he webform), after that I try to use button_click event,...
3
by: GauravGupta | last post by:
i want to know that is it posible to call button click event before page load event on post back.... please help me....
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.