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

Jules

In my program it is possible to draw a LinkLabel with the text which is defined before. When the LinkLabel is visible, I want to open a new form when I double click the LinkLabel

this is the code I have so far:

private Graphics g;

        private int punt1 = 0;
        private int punt2 = 0;

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            g = this.CreateGraphics();

            if (e.X > 20 && e.Y > 100)
            {
                ...

                if (rbTekst.Checked && MousePosition.X > 1000)
                {
                    string naam = tbUseCaseName.Text;
                    LinkLabel lb = new LinkLabel();
                    UseCase uc = new UseCase();
                    lb.MouseDoubleClick += uc.Show();
                    lb.Location = e.Location;
                    lb.Text = naam;
                    this.Controls.Add(lb);
                }

Everything works great except the DoubleClick event. I get the following error message:

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

Does this error occurs because Form1_MouseUp has MouseEventsArgs e?

Thanks in advance!

petelids

You are trying to assign the result of calling uc.Show(); as the event handler for the MouseDoubleClick event. That method returns void which results in the error message you see.

If the signature** of UseCase.Show matches the expected signature of the event handler you can just assign the method itself:

lb.MouseDoubleClick += uc.Show;

Given your comments though it would appear that the signature doesn't match. In that case you could create an anonymous event handler that simply calls the method you want to call:

lb.MouseDoubleClick += (sender, e) =>  uc.Show();

Personally I prefer to enclose the method body in curly braces but it's not required:

lb.MouseDoubleClick += (sender, e) => { uc.Show(); };

You could also create a method to handle the click and call show from within there:

lb.MouseDoubleClick += lb_MouseDoubleClick;
...
void lb_MouseDoubleClick(object sender, MouseEventArgs e)
{
    uc.Show();
}

** The signature of a method is what the method looks like in terms of access modifiers, the return value and any parameters it accepts. I guess that uc is a Form in which case the Show method returns void and accepts no parameters. The MouseDoubleClick event expects a method that takes an object and a MouseEventArgs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

From Dev

Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

From Dev

Cannot implicitly convert type 'void' to 'System.Net.CookieContainer'

From Dev

Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task'

From Dev

c# Error: Cannot implicitly convert type 'string' to 'System.Windows.Forms.Control' (CS0029)

From Dev

cannot implicitly convert type void to object

From Dev

Cannot implicitly convert type 'void' to 'int'?

From Dev

Cannot implicitly convert type 'float' to 'void'

From Dev

Cannot implicitly convert type 'float' to 'void'

From Dev

Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>'

From Dev

Cannot implicitly convert type 'void' to 'System.Collections.Generic.Dictionary<string,bool>

From Dev

cannot implicitly convert System.Type to object

From Dev

c# Cannot implicitly convert type 'double' to System.Window.Forms.Textbox

From Dev

Cannot implicitly convert type 'System.EventHandler' to 'System.Windows.RoutedEventHandler' in c#

From Dev

Cannot implicitly convert type 'void' to 'object' MVC cshtml method call

From Dev

public bool method Cannot implicitly convert type `bool' to `void'

From Dev

list.AddRange Cannot implicitly convert type 'void'

From Dev

Error cannot implicitly convert type 'void' to 'string' on string filepath

From Dev

Cannot implicitly convert type void with no input params to string c#

From Dev

Unity3d "Cannot implicitly convert type `void' to `bool'"

From Dev

cannot implicitly convert type 'void' to 'object' asp.net.MVC

From Dev

async/await: Cannot implicitly convert type 'void' to 'int[]'

From Dev

Cannot implicitly convert type 'frmRemote.RemoteClickHandler' to 'System.EventHandler'

From Dev

Cannot implicitly convert type to 'System.Collections.Generic.List

From Dev

Cannot implicitly convert type 'System.Linq.IQueryable?

From Dev

Cannot implicitly convert type 'int' to 'System.Data.DataTable'

From Dev

Cannot implicitly convert type 'System.Collections.Generic.List

From Dev

Cannot implicitly convert to type string to System.Net.Mail.MailAddress

From Dev

Cannot implicitly convert type System.Collections.Generic.List

Related Related

  1. 1

    Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

  2. 2

    Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

  3. 3

    Cannot implicitly convert type 'void' to 'System.Net.CookieContainer'

  4. 4

    Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task'

  5. 5

    c# Error: Cannot implicitly convert type 'string' to 'System.Windows.Forms.Control' (CS0029)

  6. 6

    cannot implicitly convert type void to object

  7. 7

    Cannot implicitly convert type 'void' to 'int'?

  8. 8

    Cannot implicitly convert type 'float' to 'void'

  9. 9

    Cannot implicitly convert type 'float' to 'void'

  10. 10

    Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>'

  11. 11

    Cannot implicitly convert type 'void' to 'System.Collections.Generic.Dictionary<string,bool>

  12. 12

    cannot implicitly convert System.Type to object

  13. 13

    c# Cannot implicitly convert type 'double' to System.Window.Forms.Textbox

  14. 14

    Cannot implicitly convert type 'System.EventHandler' to 'System.Windows.RoutedEventHandler' in c#

  15. 15

    Cannot implicitly convert type 'void' to 'object' MVC cshtml method call

  16. 16

    public bool method Cannot implicitly convert type `bool' to `void'

  17. 17

    list.AddRange Cannot implicitly convert type 'void'

  18. 18

    Error cannot implicitly convert type 'void' to 'string' on string filepath

  19. 19

    Cannot implicitly convert type void with no input params to string c#

  20. 20

    Unity3d "Cannot implicitly convert type `void' to `bool'"

  21. 21

    cannot implicitly convert type 'void' to 'object' asp.net.MVC

  22. 22

    async/await: Cannot implicitly convert type 'void' to 'int[]'

  23. 23

    Cannot implicitly convert type 'frmRemote.RemoteClickHandler' to 'System.EventHandler'

  24. 24

    Cannot implicitly convert type to 'System.Collections.Generic.List

  25. 25

    Cannot implicitly convert type 'System.Linq.IQueryable?

  26. 26

    Cannot implicitly convert type 'int' to 'System.Data.DataTable'

  27. 27

    Cannot implicitly convert type 'System.Collections.Generic.List

  28. 28

    Cannot implicitly convert to type string to System.Net.Mail.MailAddress

  29. 29

    Cannot implicitly convert type System.Collections.Generic.List

HotTag

Archive