Search code examples
c#winformssystem.drawing

What is the difference between System.Drawing.Point and System.Drawing.PointF


What is the difference between System.Drawing.Point and System.Drawing.PointF. Can you give an example between this two.

Thanks in advance.


Solution

  • I think PointF exists partly because System.Drawing.Graphics class supports transformation and anti-aliasing. For example, you can draw a line between discrete pixelx in anti-aliasing mode.

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Pen pen = Pens.Red;
            // draw two vertical line
            e.Graphics.DrawLine(pen, new Point(100, 100), new Point(100, 200));
            e.Graphics.DrawLine(pen, new Point(103, 100), new Point(103, 200));
            // draw a line exactly in the middle of those two lines
            e.Graphics.DrawLine(pen, new PointF(101.5f, 200.0f), new PointF(101.5f, 300.0f)); ;
        }
    

    and it will look like

    this

    without PointF those functionalities will be limited.