setting form Size - hack at form.designer.cs ?

O

Oli

Hi -

I would like to set some properties to constants (these may ultimately
come from app.config) eg the Size property.

If I do this in my Form constructor - then the values seem not to get
applied in the designer. Also - the "InitializeComponent" call has
already done a Suspend/Resume layout - so I am concerned that changing
properties subsequently might cause flicker etc.

I have taken to changing the .designer.cs file by hand - but this is
surely nasty....

any suggestions?

current code in .designer.cs (yes the project is called "Magnum" -
sorry about that) :

private void InitializeComponent()
{
this.SuspendLayout();
//
// BackOffice
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = DW.Shops.Magnum.Classes.Style.MainPaneSize;
this.Name = "BackOffice";
this.Text = "BackOffice";
this.ResumeLayout(false);

}
 
G

Guest

You can go to the top of the property grid and setup the properies to be
loaded from the config file. this is probably the best bet as it will not
involves hacking the designer file which is repeatedly re-written.
 
O

Oliver Sturm

Hello Oli,
I would like to set some properties to constants (these may ultimately
come from app.config) eg the Size property.

You should be able to bind such properties directly to external settings.
To do this, select your form, then select the entry
ApplicationSetting/PropertyBindings from the properties window. There'll
be a button with an ellipsis on it there for the setting. Click that. Then
find the property you want to bind and create a new setting for it. VS
will automatically make all the necessary changes to add an entry to
app.config for you and bind the property to it.

Now, for the Size property this is apparently impossible... I remember
having seen that before, but I'm not aware of the reason. It's pretty easy
to work around by using the ClientSize property instead.
If I do this in my Form constructor - then the values seem not to get
applied in the designer.

The constructor of the form you're designing is not executed by the VS
designer, only the code in the InitializeComponent method. What's
confusing in the beginning is that the constructors of base classes of
that form *are* actually executed - makes sense when you think about it.

Also - the "InitializeComponent" call has
already done a Suspend/Resume layout - so I am concerned that changing
properties subsequently might cause flicker etc.

Well, there's nothing keeping you from using SuspendLayout/ResumeLayout
yourself. That would certainly be the clean way of doing this.
I have taken to changing the .designer.cs file by hand - but this is
surely nasty....

Yes, that's nasty... I'm wondering: as this is clearly a runtime
customization feature you're trying to implement, why is it so important
to you to have the mechanism working at design time? Wouldn't it suffice
to have some default value at design time and the custom settings at
runtime? This is definitely the hard part of the problem and I'm not sure
there's a graceful solution to it.


Oliver Sturm
 

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