1

You can use this to quickly instantiate class' properties with values you'd like:

Form myform = new Form
{
    Width = 500,
    Height = 150,
    FormBorderStyle = FormBorderStyle.FixedDialog,
    Text = "Hello world!",
    StartPosition = FormStartPosition.CenterScreen
};

But this below is an invalid syntax:

class MyForm: Form
{
    public MyForm(string caption) : base() {
            Width = 500,
            Height = 150,
            FormBorderStyle = FormBorderStyle.FixedDialog,
            Text = caption,
            StartPosition = FormStartPosition.CenterScreen}
    {

    }
}

So I wonder if there's a way to do it, or if I just have to do it old-school, like this:

class MyForm: Form
{
    public MyForm(string caption) : base()
    {
        Width = 500;
        Height = 150;
        FormBorderStyle = FormBorderStyle.FixedDialog;
        Text = caption;
        StartPosition = FormStartPosition.CenterScreen;
    }
}

I admit it's not such a terrible difference, but still I'm interested for the sake of knowledge.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

0 Answers0