Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oli - 12 Feb 2007 17:05 GMT
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);

        }
Ciaran O''Donnell - 13 Feb 2007 15:28 GMT
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.

Signature

Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com

> Hi -
>
[quoted text clipped - 28 lines]
>
>         }
Oliver Sturm - 13 Feb 2007 17:58 GMT
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
Signature

http://www.sturmnet.org/blog


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.