views:

96

answers:

4

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

Thanks in advance.

+10  A: 

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

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

Jon Skeet
Thanks for the response. But where can I use `PointF`?
Rye
In almost all the methods on `System.Drawing.Graphics`. For example, `Graphics.DrawLine` can take either `Point` or `PointF` parameters.
Timwi
@Timwi thanks, so PointF cannot be use on user control properties? for example `Location`?
Rye
@Rye: I believe most of Windows Forms uses an integer coordinate system, whereas most of WPF uses a `double`-based coordinate system.
Jon Skeet
A: 

Check msdn for Point and PointF and especially compare the datatype of the X and Y properties.

Hans Kesting
Why the downvote? The question sounded like something the OP could figure out himself, at least the "difference" part.
Hans Kesting
A: 

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

Smart_Joe
+1  A: 

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
@tia This is a good example. Thanks tia
Rye