24

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

Thanks in advance.

Rye
  • 2,273
  • 9
  • 34
  • 43
  • 2
    Check msdn for [Point](http://msdn.microsoft.com/en-us/library/system.drawing.point.aspx) and [PointF](http://msdn.microsoft.com/en-us/library/system.drawing.pointf.aspx) and especially compare the datatype of the X and Y properties. – Hans Kesting Sep 17 '10 at 08:30
  • 2
    Why the downvote? The question sounded like something the OP could figure out himself, at least the "difference" part. – Hans Kesting Sep 17 '10 at 08:49

3 Answers3

31

Point uses integer coordinates (int for X and Y).

PointF uses floating points (float for X and Y).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks for the response. But where can I use `PointF`? – Rye Sep 17 '10 at 08:36
  • 1
    In almost all the methods on `System.Drawing.Graphics`. For example, `Graphics.DrawLine` can take either `Point` or `PointF` parameters. – Timwi Sep 17 '10 at 08:39
  • @Timwi thanks, so PointF cannot be use on user control properties? for example `Location`? – Rye Sep 17 '10 at 08:49
  • 2
    @Rye: I believe most of Windows Forms uses an integer coordinate system, whereas most of WPF uses a `double`-based coordinate system. – Jon Skeet Sep 17 '10 at 09:01
  • There is also `System.Windows.Point`, which uses double coordinates. – heltonbiker Mar 12 '13 at 14:13
28

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.

tia
  • 9,518
  • 1
  • 30
  • 44
-1

For Example,In some embedded systems,only support "System.Drawing.Point",you should create "PointF" Type by yourself .

Smart_Joe
  • 63
  • 1
  • 7