Cannot implicitly convert type 'System.Windows.Forms.MouseEventHandler' to 'System.EventHandler'

Cannot implicitly convert type 'System.Windows.Forms.MouseEventHandler' to 'System.EventHandler'

Post by Le » Tue, 04 Dec 2001 11:08:53



I'm using Beta2 and am trying to pass MouseClick arguments rather than
the default arguements for the ListBox_Click event.  I think my code
is correct, but it throws this error:

Cannot implicitly convert type
'System.Windows.Forms.MouseEventHandler' to 'System.EventHandler'

Here is my code:

// I contruct the event in the Forms contructor area...
this.listBox.Click += new System.Windows.Forms.MouseEventHandler
this.listBox_Click);

//Ultimately, I want to use the event here:
private void listBox_Click(object sender,
System.Windows.Forms.MouseEventArgs e)
   {
      if (e.Button == MouseButtons.Right)
        {
           System.Windows.Forms.Control control = new
System.Windows.Forms.Control();
           control.CreateControl();
           this.contextMenu1.Show(control,Cursor.Position);
        }
   }

THANKS in advance for any help with this!  I'm thinking this is a bug
in Beta2???

 
 
 

Cannot implicitly convert type 'System.Windows.Forms.MouseEventHandler' to 'System.EventHandler'

Post by Jay B. Harlow [MVP - Outlook » Tue, 04 Dec 2001 11:58:02


Lee,
Why would you think that would work?

MouseEventHandler does not derive from EventHandler. ListBox_Click needs to
match the signature of EventHandler which is 'void EventHandler(object
sender, EventArgs e)'.

MouseEventHandler has a signature of 'MouseEventHandler(object sender,
MouseEventArgs e)'

If you need to know if its right mouse click or not, you can use
Control.MouseButtons == MouseButtons.Right

Hope this helps
Jay


Quote:> I'm using Beta2 and am trying to pass MouseClick arguments rather than
> the default arguements for the ListBox_Click event.  I think my code
> is correct, but it throws this error:

> Cannot implicitly convert type
> 'System.Windows.Forms.MouseEventHandler' to 'System.EventHandler'

> Here is my code:

> // I contruct the event in the Forms contructor area...
> this.listBox.Click += new System.Windows.Forms.MouseEventHandler
> this.listBox_Click);

> file://Ultimately, I want to use the event here:
> private void listBox_Click(object sender,
> System.Windows.Forms.MouseEventArgs e)
>    {
>       if (e.Button == MouseButtons.Right)
> {
>    System.Windows.Forms.Control control = new
> System.Windows.Forms.Control();
>    control.CreateControl();
>    this.contextMenu1.Show(control,Cursor.Position);
> }
>    }

> THANKS in advance for any help with this!  I'm thinking this is a bug
> in Beta2???


 
 
 

1. Cannot implicitly convert type 'object' to 'System.Web.UI.WebControls.TextBox'

Hi

I have an arraylist of textboxes that I can add to my form as follows:

t contains an arraylist called m_TextBoxes

The following code works fine:
foreach(TextBox s in t)
{
Form1.Controls.Add(s);

however, when I try the foolwing:
for (int i = 0; i == 2; i++)
{
TextBox s = new TextBox();
s = t.m_TextBoxes[i];

I get the error: Cannot implicitly convert type 'object' to
'System.Web.UI.WebControls.TextBox'

What am I doing wrong?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

2. Anyone use ZDnet CE hotfile of the day?

3. Value of type 'String' cannot be converted to 'System.Drawing.Color'

4. How to disable compression with PPP 2.3.3 on SunOS

5. An unhandled exception of type 'System.ExecutionEngineException' occurred in system.windows.forms.dll

6. insert xml data in html tag

7. A first chance exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

8. command line switches for Money

9. System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid

10. 'System.ExecutionEngineException' in system.windows.forms.dll

11. BC30002: Type 'System.Windows.Forms.ProgressBar' is not defined

12. Cannot perform 'Like' operation on System.Guid and System.String