0

I'm trying to minimize the main form I created within Class1.

My main form is

    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Class1 b1;
        b1 = new Class1();
        //minimizeWindow();
    }

    public void minimizeWindow()
    {
        this.WindowState = FormWindowState.Minimized;
    }
}

my class

public class Class1
{
    // Constructor
    public Class1()
    {
        Form1 form = new Form1();
        form.Show();
        form.minimizeWindow();
    }
}

I have tried to make a static method in my form but I couldn't use "this.form" its saying you coulnd't use this in a static function.

  • Out of curiosity, what research have you done to solve this issue. The process is quite simple. I am pretty sure, with a little bit of finger grease and a whole lot of Google, you will come to a solution that best suits your needs. – James Shaw Dec 11 '14 at 18:39
  • To add. It appears you are attempting to minimize the form as soon as it loads. If this is the intention, there is an accepted answer of another thread that suggests a work around. See http://stackoverflow.com/questions/1730731/how-to-start-winform-app-minimized-to-tray – James Shaw Dec 11 '14 at 18:41
  • Can you please clarify. You have an existing `Form1` showing and you want to launch `Class1` (is it a form?) and minimize `Form1` as soon as `Form1` loads, or on a user event? – John Alexiou Dec 11 '14 at 19:41

1 Answers1

2

You are creating a completely different instance in your class. Instead you need to pass current form instance via your constructor:

Form form;
public Class1(Form f)
{
    form = f;
    form.Show();
    form.minimizeWindow();
}

private void Form1_Load(object sender, EventArgs e)
{
    Class1 b1;
    b1 = new Class1(this);
}
Selman Genç
  • 100,147
  • 13
  • 119
  • 184