Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows form application(done on VISUAL STUDIO 2008 ). I make use of a flow layout panel and buttons. I have a problem on the buttons after copying and pasting it.
after double clicking the buttons , it'll lead to another form , but I got no idea how come after double-clicking to edit the original copy of the button it pops out the number of times(eg frm.showdialog()) I pasted onto the panel. well I tried setting the copied button name to a new name after getting pasted but that problem still happens.However if I go through the context menu and select edit it'll work fine (form opens only once).
well I place the code from the edit toolstrip into the condition
if(e.clicks==2)

which is wrong. (DURING RUN-TIME)

Is there something to do with parent and child relation?
anyone knows whats the problem here?
part of the code
pardon me if i didnt explain clearly
it goes something like this
public void newbutton_MouseDown(object sender, MouseEventArgs e)

 {
            prebutton = (Button)sender;
            Point p = new Point(e.X, e.Y);

                if (e.Button == MouseButtons.Right && count < 2)
                    cm_rightclick.Show(prebutton, p);//user supposedly right click ,then click onto edit to edit the moves on the button

             if (e.Button == MouseButtons.Left && e.Clicks == 2)
             editToolStripMenuItem_Click(sender,e);

 }
public void editToolStripMenuItem_Click(object sender, EventArgs e)
  {
            bool bFound = false;

            //Initiating an instance of Move Category.cs form
            moveCatergory frm = new moveCatergory();
            //Using the FindSingleMovement FUNCTION
            SingleMovement sm = FindSingleMovement(ref  bFound);
            frm.sm =  sm;
           frm.ShowDialog(); //when it comes here , dialog appears more than once for the copied button and the original button that is being copied
            for (int i = 0; i < allMovements.Count; i++)
            {
                if (sm.button_action == allMovements[i].button_action)
                    break;

            }
            //FOR LOOP used for checking which dancestep is selected
            int k = 0;

            //After the checking is done, the selected dancestep list will be removed and the edited dancestep will be added
            if (k < allMovements.Count)
            {
                allMovements.Remove(allMovements[k]);
                frm.sm.button_action.Text = frm.sm.dance_action.nametxt;
                allMovements.Insert(k, frm.sm);
            }

        }


anyone knows what's the problem here?
Posted
Updated 16-Nov-10 18:03pm
v2

1 solution

It seems that your editToolStripMenuItem_Click event is being triggered twice when called from the button. A couple things you can look at:

1.) Since the button will fire off all mouse/click events each time the mouse button is clicked, you might check to see if the editToolStripMenuItem_Click is being called from more than one event in the mouse clicking life cycle(MouseDown, MouseClick, MouseUp, Click).

2.) Check to ensure that the newbutton_MouseDown is not hooked more than once to the button's MouseDown event or it will be treated as a separate consumer of the event and will get triggered twice during each click.
 
Share this answer
 
Comments
hotkick 17-Nov-10 8:27am    
hmm i don't really get what you mean? I'll try my best to find out more details. Btw any good reference to follow?
JOAT-MON 17-Nov-10 15:10pm    
1.) Whenever you click the button it fires a series of events including the MouseDown. If you double-click the button it will fire the events twice, because it does not inherently support the DoubleClick event. I would check to see if you have more than just the MouseDown event hooked(i.e. MouseClick, Click, or MouseUp). If any of these events are being handled in your code, they will also be called twice when you double-click. If they are being handled, look to see if they call the editToolStripMenuItem_Click event as well.
2.) Search your code for the places that you hook to the event (syntax will look something like: newbutton.MouseDown += new System.EventHandler(newbutton_MouseDown) ) and make sure that it does not register more than one handler to the MouseDown event.

Suggested Google search terms: C# DoubleClick Button, C# events
hotkick 22-Nov-10 10:01am    
okay thanks for enlightening me ! it worked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900