|
-
December 13th, 2010, 02:48 AM
#1
c# Drawing a Line in picturebox..weird
Okay I am trying to draw a horzontal and vertical line through a point on the map.
Code:
public partial class PaintBox : System.Windows.Forms.PictureBox
{
public PaintBox()
{
this.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint | System.Windows.Forms.ControlStyles.UserPaint | System.Windows.Forms.ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
}
public PaintBox(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
System.Drawing.Pen mypen;
mypen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics gra = this.CreateGraphics();
gra.DrawLine(mypen, 0, Program.mainForm.CurrentPoint.Y, this.Width, Program.mainForm.CurrentPoint.Y);
gra.DrawLine(mypen, Program.mainForm.CurrentPoint.X, 0, Program.mainForm.CurrentPoint.X, this.Height);
mypen.Dispose();
gra.Dispose();
base.OnPaint(pe);
}
}
I call an invalidate via a button link which passes the coordinates to the global points and displays the line although here is the problem. (I have a giant 6000 by 5500 picturebox with a map in it, located inside a panel and i am utilizing the scroll bars) As soon as I click the scrollbar to shift the picture the line disappears, although if I click the scroll bars fast you can see the lines properly but as soon as I stop clicking it disappears again.
I have absoulutely no Idea whats going on seing how I created a new project copied and pasted the same code and it works fine...any ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|