0

Me again, and it's another problem with my plugin parser for my c# browser, I'm trying to add a eventhandler to make it to where when you hit the plugin button it does something. The reason i am having to do this in code is because it is loading the plugins from files, and they are not hard-coded. Here's my code, It will look pretty familar to the last one if you saw it

toolStrip1.Items.Add( pluginButton );
pluginButton.Image = Simple_Browse.Properties.Resources.plugin;
pluginButton.Alignment = ToolStripItemAlignment.Right;
pluginButton.ToolTipText = TitlePlugin;
pluginButton.Click += StartPlugin();
private EventHandler StartPlugin()
{

    PluginPage plgp = new PluginPage();
    plgp.Show();
    plgp.Text = PlgTitle2;

}

So the code is pretty basic, but im getting an error at private EventHandler StartPlugin() The error is not all code paths return a value Please help!

Joyesh
  • 27
  • 7

3 Answers3

2

You probably meant to do this instead:

pluginButton.Click += StartPlugin; // not StartPlugin()
private void StartPlugin(object sender, EventArgs e)
{
    PluginPage plgp = new PluginPage();
    plgp.Show();
    plgp.Text = PlgTitle2;
}

It looks like you may need to read a bit more on how delegates and event handlers work.

sstan
  • 35,425
  • 6
  • 48
  • 66
1

You're requesting an EventHandler which means you have to return an EventHandler. In your handler there is no return, so this error is thrown.

You could use private void StartPlugin(). void doesn't request anything to return.

So your code will look like this:

pluginButton.Click += StartPlugin;

private void StartPlugin(object sender, EventArgs e)
{
    PluginPage plgp = new PluginPage();
    plgp.Show();
    plgp.Text = PlgTitle2;
}
roemel
  • 3,247
  • 4
  • 29
  • 52
  • Cannot implicitly convert type void to System.EventHandler, please help! – Joyesh Jul 06 '15 at 14:48
  • Please change `pluginButton.Click += StartPlugin();` to `pluginButton.Click += StartPlugin;` (remove the brackets). Have a look at my edit. – roemel Jul 06 '15 at 14:49
  • you also need to change it to StartPlugin(object sender, EventArgs e) at line 3. – Joyesh Jul 06 '15 at 14:53
0
private EventHandler StartPlugin()

This line, specifically "EventHandler", means you're returning an EventHandler. Your code does not do this. To link the EventHandler with the button click, you dont just use a line, you also need a return, (e.x return button1.Click;) because if i used return null; it would just do the action once you binded it.

Joyesh
  • 27
  • 7
oppassum
  • 1,746
  • 13
  • 22
  • I figured it out, To make it less vague for people who need help, i edited it to explain more – Joyesh Jul 06 '15 at 14:44