I know that I can set it up in the property window but I need to do it in code. How?

Recommended Answers

All 7 Replies

this.whateverAttributeYouWantToSet = whateverValueMakesSense

Why do you want to use Lock?
To prevent user can resize form?
If so, you use form`s properties like: MaximizeBox, MinimizeBox, like:

//on form1:
Form2 form2 =new Forms();
form2.MaximizeBox = false;
form2.MinimizeBox = false;

Or is there anything else you want to use Lock?

commented: thanks! got it +1

there's no this.Locked.

I need to prevent the user for resizing the form

Try this:

private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.FormBorderStyle = FormBorderStyle.Fixed3D;
            form2.MaximizeBox = false;
            form2.MinimizeBox = false;
            form2.Show(this);
        }

The Locked property is a design type only property that only affects if you can move/resize the form inside the designer. To prevent resizing set FormBorderStyle to one of FormBorderStyle.Fixed3D, FormBorderStyle.FixedDialog, FormBorderStyle.Single, FormBorderStyle.ToolWindow. If you want to prevent min/max, then set MaximizeBox to false and MinimizeBox to false.

commented: thanks! got it +1

Ok. I got it. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.