Click here to Skip to main content
15,887,411 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
<pre lang="cs">public delegate void buttonclick(object sender, EventArgs e);
        private void button1_Click(object sender, EventArgs e)
        {

            if (button1.InvokeRequired)
                button1.Invoke(new buttonclick(button1_Click));

            if (button1.BackColor == Color.LightGreen)
            {
                move_button(condition.Text.Split(new char[] { &#39; &#39; })[0].ToString(), hold_button, button1);
            }
            else
            {
                Place_Point(button1);
            }
        }</pre>

private void sampleclick()
{
 button1_Click(this,new EventArgs());
}


When i call button_click method from sampleclick it shows an exception "Parameter Count Mismatch" what is the meaning of it and how can i overcome this exception....
Posted
Updated 10-Sep-13 2:08am
v2
Comments
[no name] 10-Sep-13 8:36am    
It means exactly what is says. You are trying to invoke a method with the wrong number of parameters.
Sergey Alexandrovich Kryukov 10-Sep-13 11:58am    
First of all, do you call it from both UI and some other thread?
—SA

The buttonclick method takes two parameters wich you're not supplying in your call.

C#
if (button1.InvokeRequired)
      button1.Invoke(new buttonclick(button1_Click) ??????? );


Rewrite it like this:

C#
if (button1.InvokeRequired) 
      button1.Invoke(new buttonclick(button1_Click), sender, e);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Sep-13 12:03pm    
That is correct and should fix the immediate, but I suspect the whole idea is bad. If something is called from a non-UI thread, some semantic code should normally be called, not the method uses as an event handler for an UI event. Actually, from my CodeProject experience, using "InvokeRequired" is indicative: people using it often don't understand how to use Invoke. More usually, in a better designed code, the method having Invoke is always called from a non-UI thread.

A little problem with your resolution is: what should be put in "sender" and "e"? Those a bogus parameters, even though they are technically required. Event handler should not be invoked, that's the key.

(I voted 4.)
V.Lorz 10-Sep-13 14:16pm    
I agree with you. It makes a lot of sense and the code should be, in fact, redesigned in the manner your describe. Thanks for the vote and your comments.

Sergey Alexandrovich Kryukov 10-Sep-13 14:33pm    
Great. And you are very welcome.
—SA
You have to check the count of the parameters in your functions what you call in your code.
I think the problem caused by your move_button or Place_Point functions.
 
Share this answer
 

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