C# drawing a line weird bug

Discussion in 'Software' started by mastermosley, Dec 11, 2010.

  1. mastermosley

    mastermosley Sergeant

    Okay I have this code after a button click:
    Code:
                System.Drawing.Pen mypen;
                mypen = new System.Drawing.Pen(System.Drawing.Color.Red);
                System.Drawing.Graphics gf = this.picMap.CreateGraphics();
                gf.DrawLine(mypen, 0, 15, 100, 15);
    
    The horizontal line is drawn over a picturebox and I see it fine.
    *Note I have this image in a panel and the image has horzontal and vertical scrolls and when I click it to move it down the line drawn over the image disapears. (it shouldnt disappear untill it has moved out of view)

    In another example, I made a project with the exact same code to test this and the line drawn the same, I click down and the line is still there. I no that I have to have the draw image in the Paint event but it wasnt working in it and thats why I simplified it to try and find the error.

    When it was drawn in the Paint event it would disapear when I click down on the scroll button, but if I click down or up fast enough you can see it flicker. I almost simply copyed and pasted my code as I was updating my project. Code wise this is the exact same code but would there be some sort of setting that would effect this...
     
    Last edited: Dec 11, 2010
  2. mastermosley

    mastermosley Sergeant

    Solved used the PaintEventArgs e.Graphics instead of creating a new Graphics via CreateGraphic. Although I am unsure why the CreateGraphics didnt work in my application because I tested the same code in a different one project using the same controls and it worked...
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds