By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,041 Members | 1,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,041 IT Pros & Developers. It's quick & easy.

VB 2005 graphics concepts

P: n/a
AWW
XP VB 2005 drawing line graphics in a PictureBox - from a simple
minded former FORTRAN programmer.
The help examples have the graphics drawing code (lines & rectangles)
in the PictureBox paint event handler - making it a static display.
But I don't want a static display - I want to draw dynamic data so how
do I get the data to the event handler - if I need to do that.
I have also done line drawings on the Form but those drawings have an
annoying habit of vanishing sometimes.
Is VB 2005 just not intended for line graphics - or am I as dense as a
lead baloon? Thanks for info or Internet references.
Nov 14 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
<AWWschrieb
XP VB 2005 drawing line graphics in a PictureBox - from a simple
minded former FORTRAN programmer.
The help examples have the graphics drawing code (lines &
rectangles) in the PictureBox paint event handler - making it a
static display. But I don't want a static display - I want to draw
dynamic data so how do I get the data to the event handler - if I
need to do that. I have also done line drawings on the Form but
those drawings have an annoying habit of vanishing sometimes.
Is VB 2005 just not intended for line graphics - or am I as dense as
a lead baloon? Thanks for info or Internet references.
I don't see the problem. You don't have to draw the same each time you draw.
If you want to update the display, call the control's Invalidate method. The
paint event will be raised. I suggest deriving your control from Picturebox,
or directly from Control, add a property that represents the data to be
painted, and each time the property changes, your control can call it's own
Invalidate method. Or you can still call Invalidate from outside. Depends on
what and when you want to paint.
Armin

Nov 14 '08 #2

P: n/a
On Nov 14, 12:16 am, AWW <wrote:
XP VB 2005 drawing line graphics in a PictureBox - from a simple
minded former FORTRAN programmer.
The help examples have the graphics drawing code (lines & rectangles)
in the PictureBox paint event handler - making it a static display.
But I don't want a static display - I want to draw dynamic data so how
do I get the data to the event handler - if I need to do that.
I have also done line drawings on the Form but those drawings have an
annoying habit of vanishing sometimes.
Is VB 2005 just not intended for line graphics - or am I as dense as a
lead baloon? Thanks for info or Internet references.
See this site:

www.bobpowell.net
Nov 14 '08 #3

P: n/a
On Thu, 13 Nov 2008 22:16:51 -0800, AWW <wrote:
>XP VB 2005 drawing line graphics in a PictureBox - from a simple
minded former FORTRAN programmer.
The help examples have the graphics drawing code (lines & rectangles)
in the PictureBox paint event handler - making it a static display.
But I don't want a static display - I want to draw dynamic data so how
do I get the data to the event handler - if I need to do that.
I have also done line drawings on the Form but those drawings have an
annoying habit of vanishing sometimes.
Is VB 2005 just not intended for line graphics - or am I as dense as a
lead baloon? Thanks for info or Internet references.
This is not a VB 2005 thing, it is a Windows thing. Windows (at least
pre-Vista) does not have a bitmap for what is displayed in a window.
Whenever Windows needs to repaint a window, for example when part or
all of a window is uncovered, it invalidates part or all of the window
and sends a Paint message. It is then up to the application to redraw
the window.

You need to draw everything in the Paint event. If you draw outside
of Paint, then at some time later when Windows redraws your window
what you drew will be overwritten.

When you make a change that affects the screen, Invalidate that part
of the window which will result in a Paint event. This means you need
to keep all of the information that will allow your Paint event
handler to redraw the window.
Nov 14 '08 #4

P: n/a
AWW
On Fri, 14 Nov 2008 13:17:40 +0100, "Armin Zingler"
<az*******@freenet.dewrote:
><AWWschrieb
>XP VB 2005 drawing line graphics in a PictureBox - from a simple
minded former FORTRAN programmer.
The help examples have the graphics drawing code (lines &
rectangles) in the PictureBox paint event handler - making it a
static display. But I don't want a static display - I want to draw
dynamic data so how do I get the data to the event handler - if I
need to do that. I have also done line drawings on the Form but
those drawings have an annoying habit of vanishing sometimes.
Is VB 2005 just not intended for line graphics - or am I as dense as
a lead baloon? Thanks for info or Internet references.

I don't see the problem. You don't have to draw the same each time you draw.
If you want to update the display, call the control's Invalidate method. The
paint event will be raised. I suggest deriving your control from Picturebox,
or directly from Control, add a property that represents the data to be
painted, and each time the property changes, your control can call it's own
Invalidate method. Or you can still call Invalidate from outside. Depends on
what and when you want to paint.
Armin
OK several dumb (outdated programmer) questions:
by derive - you mean - Dim Box1 as New PictureBox - right?
I have no clue how to add a property to a Control and nothing in help
that I can find (likely not knowing where to look) - can you explain?

the following example works:
Inports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Private sub Form1_Load(ByVal sender as Object, ByVal e as
System.EventArgs) Handles MyBase.Load
DrawEllipse()
End Sub

Private Sub DrawEllipse()
Dim myPen as New Pen(Color.Red)
Dim g as Graphics
g = Me.CreateGraphics()
g.DrawEllipse(myPen, New Rectangle(0, 0, 200, 300))
myPen.Dispose()
g.Dispose()
End Sub
End Class
Question: If I have no dragging or overlapping - just drawing in
various separate parts of the Form - do I need to worry about the
paint event? or OnPaint?
Since it works - why would some of my graphics vanish seemingly at
random? because I did not dispose the pen and g/Graphics properly? or
because Windows does a repaint at random?
Thanks for anything you may add.
Nov 17 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.