Home All Groups Group Topic Archive Search About

Drawing One Simple Little Line

Author
1 May 2007 4:26 AM
Peter
Hi,

I remember in VB6 that one could simply draw a line in a picturebox using
the .Line method. There is no equivalent in .NET; everything I read says it
is necessary to do lots of heavily complicated things to get it to happen.

My question is, most of those new methods (the ones that take 25 lines of
code) require that the drawing takes place in the OnPaint event of the
picture box. This seems to imply that whatever is drawn in there must remain
static for the whole program. How can one dynamically change, add, and erase
lines, circles, and so forth during runtime?

Author
1 May 2007 4:53 AM
Michael C
Show quote Hide quote
"Peter" <star***@hotmail.com> wrote in message
news:bkzZh.2550$296.1235@newsread4.news.pas.earthlink.net...
> Hi,
>
> I remember in VB6 that one could simply draw a line in a picturebox using
> the .Line method. There is no equivalent in .NET; everything I read says
> it is necessary to do lots of heavily complicated things to get it to
> happen.
>
> My question is, most of those new methods (the ones that take 25 lines of
> code) require that the drawing takes place in the OnPaint event of the
> picture box. This seems to imply that whatever is drawn in there must
> remain static for the whole program. How can one dynamically change, add,
> and erase lines, circles, and so forth during runtime?

I don't know how you get 25 lines of code. In the onpaint override just draw
the line using e.Graphics.DrawLine. If you want to change what you're
drawing then just draw a different line in OnPaint.

Michael
Author
1 May 2007 10:34 AM
rowe_newsgroups
On May 1, 12:26 am, "Peter" <star***@hotmail.com> wrote:
> Hi,
>
> I remember in VB6 that one could simply draw a line in a picturebox using
> the .Line method. There is no equivalent in .NET; everything I read says it
> is necessary to do lots of heavily complicated things to get it to happen.
>
> My question is, most of those new methods (the ones that take 25 lines of
> code) require that the drawing takes place in the OnPaint event of the
> picture box. This seems to imply that whatever is drawn in there must remain
> static for the whole program. How can one dynamically change, add, and erase
> lines, circles, and so forth during runtime?

You don't have to use the OnPaint override, you can also get the
Graphics object by doing "Dim g as Graphics =
PictureBox.CreateGraphics." And in reality, once you get used to using
GDI+ to do the drawing you will like it better than the VB6 methods
(or at least I do).

Thanks,

Seth Rowe
Author
1 May 2007 1:05 PM
Chris Dunaway
On May 1, 5:34 am, rowe_newsgroups <rowe_em***@yahoo.com> wrote:

> You don't have to use the OnPaint override, you can also get the
> Graphics object by doing "Dim g as Graphics =
> PictureBox.CreateGraphics." And in reality, once you get used to using
> GDI+ to do the drawing you will like it better than the VB6 methods
> (or at least I do).

Don't do this.  See this article for more information:
http://www.bobpowell.net/picturebox.htm

Also, check out his whole site:

http://www.bobpowell.net

Chris
Author
2 May 2007 12:24 AM
Michael C
"rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message
news:1178015648.971618.206910@l77g2000hsb.googlegroups.com...
> You don't have to use the OnPaint override, you can also get the
> Graphics object by doing "Dim g as Graphics =
> PictureBox.CreateGraphics."

How are you going to paint again when it disappears though?

> And in reality, once you get used to using
> GDI+ to do the drawing you will like it better than the VB6 methods
> (or at least I do).

I totally and utterly agree. Dotnet's drawing is *far far* superior. Only
downside is the speed.

Michael