Click here to Skip to main content
15,792,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use GDI functions to render vector data for many years,even after migration to C# and dotNet,I still use GDI libraries because I found GDI much faster than GDI+ in vector rendering.
Now I have stuck in a problem where I have to use GDI+ and face a problem.My vector coordinates are in real world and according to a lot of snippet code in the net,I call some functions of graphics object to make a right transformation but still my form doesn't paint anything.I'm sure there is a problem with my code,so please let me know what's wrong with this code that does not paint a simple's a windows form Paint function which has been overriden.
private void Form1_Paint(object sender, PaintEventArgs e)
    Graphics g = e.Graphics;

    float X_ExtentInRealWorld = 757600-757540;
    float Y_ExtentInRealWorld = 3170320-3170270;

    float clientW = this.ClientRectangle.Width;//520 pixels
    float clientH = this.ClientRectangle.Height;//520 pixels

    float xyScale = Math.Min(clientH / Y_ExtentInRealWorld, clientW / X_ExtentInRealWorld);

    g.TranslateTransform(757540, 3170270);
    g.ScaleTransform(xyScale, xyScale, MatrixOrder.Prepend);

    PointF[] dumy = new PointF[2];
    dumy[0].X = 757541.459335231F;
    dumy[0].Y = 3170320.50846391F;
    dumy[1].X = 757599.892618402F;
    dumy[1].Y = 3170319.99492757F;

    Pen pn = new Pen(Color.Black);
    pn.Width =0;
    g.DrawLines(pn, dumy);

if I use TransformPoints to convert back points from World to page space,I see that converted points are all in client area of form:
g.TransformPoints(CoordinateSpace.World, CoordinateSpace.Page, dumy);

any help or guid lines is highly appreciated
Updated 12-Sep-15 22:10pm
[no name] 13-Sep-15 5:49am    
Maybe pn.Width= 0; This is a very thin line or not?
Richard MacCutchan 13-Sep-15 8:37am    
I have always struggled with transforms, but I wonder if your dx and dy values should be negative?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900