0

now i have the current code o MainUC.cs:

private void tsbNoviRacun_Click(object sender, EventArgs e)
{
    if (racunuc == null)
    {
        racunuc = new RacunUC();
        racunuc.Dock = DockStyle.Fill;
        Controls.Add(racunuc);
    }
    racunuc.BringToFront();

The thing i want to do is clean the code from main page/form. I have 2 taskbar and 2 toolbar buttons that are calling the same form (this one above), so i don't want to write the code 4 times. I tried to make new class.cs with properties and do it with return value, but it didn't work. Can someone help me with it, or, is there possiblity to call the same code on current page/form. Something like

private void tsbStariRacuni_Click(object sender, EventArgs e)
{
    call tsbNoviRacun();
}

"( this isn't working, i know :p)

EDiT: Oh damn me, thanks guys!

2 Answers 2

3

In c# there is no "call" keyword for invoking functions. You just type the name and all required arguments in round brackets.

private void tsbStariRacuni_Click(object sender, EventArgs e)
{
    tsbNoviRacun_Click(sender, e);
}
Sign up to request clarification or add additional context in comments.

Comments

2

This should do it:

public void tsbNoviRacun()
{
    if (racunuc == null)
    {
        racunuc = new RacunUC();
        racunuc.Dock = DockStyle.Fill;
        Controls.Add(racunuc);
    }
    racunuc.BringToFront();
}

private void tsbNoviRacun_Click(object sender, EventArgs e)
{
    tsbNoviRacun();
}

You can call that method from all the event handlers you want it to run on. Obviously this function is depended on Controls and DockStyle so you must put it within scope of this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.