3

I am working on a WinForms application using Visual Studio 2008 (C#). The user interface of the concerning form consists of several SplitContainers. When I tested the application after setting the Windows font size to 125%, the form didn't look any more as it should. There obviously was a problem with scaling. Therefore I've searched for a solution and found one here. The two following lines did the job for me:

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

As explained in the other question (in one of the answers, respectively), they have to be included for every container in the designer file. It works and scaling performs correctly. But on the other hand, I have to manually edit the designer file and that's something one actually shouldn't do. The added lines get lost every time I use the layout designer. EDIT: Just to clarify: These two properties are not shown in the designer gui.

Now finally, my question is: What can I do? How or where can I add the code for correct scaling without dirty manipulation of the designer file?

I have already tried to simply put these two lines for every container in the constructor after the InitializeComponent() method call, but at this position, they don't have the desired effect.

So, maybe you have an idea how it has to be done.

Thanks in advance,
Alex

Community
  • 1
  • 1
Alex
  • 51
  • 6
  • 1
    Can't you set these properties in the Designer itself? For each of your SplitContainer? – Josh L. Apr 28 '15 at 22:28
  • No, unfortunately not. That would be great. :) – Alex Apr 28 '15 at 22:42
  • Have you tried to set in the designer the AutoScaleMode and then after the InitializeComponents set the AutoScaleDimensions? – Gusman Apr 28 '15 at 23:23
  • No, both properties do not appear in the designer. – Alex May 01 '15 at 13:21
  • If you create a brand new form, then resize it, do you see those two properties set for the form in InitializeComponent()? – cokeman19 May 06 '15 at 03:35
  • @cokeman19 Yes, for the form, everything works as expected. The properties can be set in the gui and the changes are written to the designer file. – Alex May 07 '15 at 07:37

1 Answers1

1

I've finally found a way to solve the problem. It isn't really what I intended originally, but it has the same effect.

The concerning two properties don't show in the designer gui, so why not make them appear? Therefore I created a custom control and added some attributes to both scaling properties, so that they appear in the designer.

public class ScalableSplitContainer : SplitContainer
{
    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [Bindable(true)]
    public new AutoScaleMode AutoScaleMode
    {
        get { return base.AutoScaleMode; }
        set { base.AutoScaleMode = value; }
    }

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [Bindable(true)]
    public new SizeF AutoScaleDimensions
    {
        get { return base.AutoScaleDimensions; }
        set { base.AutoScaleDimensions = value; }
    }
}

Using this specialized SplitContainer, scaling behaviour can easily be set in the gui and the code lines are included in the generated designer file.

Alex
  • 51
  • 6