C# -> two buttons same code

A

Al Biheiri

i forgot how to do this someone help

how do i make this into one


private void mnuTray_Click(object sender, System.EventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}

private void lnkTray_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}


I remember I had to change it to something
like --------------------------------

private void mnuTray_Click(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs , System.EventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}
 
R

rossum

i forgot how to do this someone help

how do i make this into one


private void mnuTray_Click(object sender, System.EventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}

private void lnkTray_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}
Have you tried:

private void lnkTray_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
mnuTray_Click(sender, e);
}

to call the first button click action when the second button is
clicked?

rossum
 
Z

zacks

i forgot how to do this someone help

how do i make this into one

private void mnuTray_Click(object sender, System.EventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}

private void lnkTray_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}

I remember I had to change it to something
like --------------------------------

private void mnuTray_Click(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs , System.EventArgs e)
{
notifyIcon1.Visible = true; WindowState =
FormWindowState.Minimized; Hide();
}

Typo in my last. Should be:

In the mnuTray_Click event handler, substitute the following code for
what is there:

InkTray.PerformClick();
 
N

Nicholas Paldino [.NET/C# MVP]

The neater way would be to refactor this into a single method, like so:

private void LinkClickedEventHandler()
{
notifyIcon1.Visible = true;
WindowState = FormWindowStateMinimized;
Hide();
}

And then call that from each event handler.
 
A

Al Biheiri

yea that works...should of thought about that,,,, woops

Nicholas Paldino said:
The neater way would be to refactor this into a single method, like so:

private void LinkClickedEventHandler()
{
notifyIcon1.Visible = true;
WindowState = FormWindowStateMinimized;
Hide();
}

And then call that from each event handler.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

rossum said:
Have you tried:

private void lnkTray_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
mnuTray_Click(sender, e);
}

to call the first button click action when the second button is
clicked?

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top