WinForms Control.Scale Method

The code below shows a small WinForms application that includes a simple control that draws a circle. I am trying to understand the behavior of a method Control.Scale.

If I call the Scale method on the Main control, as shown in the code, it will scale correctly. But if I instead call Scale from the Circle constructor, scaling will not happen.

My perplexity here, no doubt, indicates a gross misunderstanding on my part about what the Scale should do. Can anyone enlighten me?

using System;
using System.Windows.Forms;
using System.Drawing;

class Program
{
    [STAThread]
    public static void Main()
    {
        var circle = new Circle(Color.Orange)
        {
            Size = new Size(23, 23),
            Location = new Point(50, 50)
        };
        circle.Scale(new SizeF(3.0f, 3.0f));      //  <-- scaling here works

        var form = new Form();
        form.Controls.Add(circle);

        Application.Run(form);
    }
}

class Circle : Control
{
    public Circle(Color color)
    {
        ForeColor = color;
        // Scale(new SizeF(3.0f, 3.0f));     //  <-- scaling here DOESN'T work
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.FillEllipse(new SolidBrush(ForeColor), ClientRectangle);
    }
}
+3
source share
1 answer

Scale() . AutoScaleMode. InitializeComponent(), SuspendLayout(). . AutoScaleMode . , .

, e.Graphics.ScaleTransform() OnPaint. , . , "".

+4

All Articles