The app is very simply. Create a form with a picturebox
called picMain and add the following code.
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
DrawLine()
End Sub
Private Sub DrawLine()
Dim g As Graphics
Dim oPen As New Pen(Color.Black)
Try
g = picMain.CreateGraphics
g.DrawLine(oPen, 0, 0, 200, 200)
Finally
oPen.Dispose()
oPen = Nothing
g.Dispose()
g = Nothing
End Try
End Sub
Private Sub picMain_Paint(ByVal sender As Object,
ByVal e As System.Windows.Forms.PaintEventArgs) Handles
picMain.Paint
DrawLine()
End Sub
Do not create a new graphics in your line drawing routine, pass the Graphics
object from the PaintEventArgs to the DrawLine routine and use it instead.
Bob.
--
Have you thought about buying my book?
http://www.amazon.com/exec/obidos/ASIN/067232153X/bobpowelnet
Visit NetEdge Software to find out about the Web Service Enabler.
Enable all your legacy VB6 applications to seamlessly connect to .NET
web-services.
http://www.netedgesoftware.com
"Chris Wallis" <c.wallis@nospam> wrote in message
news:14ed601c22263$f3d7ad60$39ef2ecf@TKMSFTNGXA08...
I have however discovered that if I draw on either the
form or a panel instead of a picturebox, then it works
fine. What is so different about a picturebox?
>.
>
I beg your pardon, my mistake. It does work passing the
graphics with a picturebox. I am still curious about why
it works the other way with forms and panels though.
>.
>
"Chris Wallis" <chris.wallis@nospam> wrote in message
news:12d0701c22281$063271d0$2ae2...@hosting.microsoft.com...
"Chris Wallis" <chris.wallis@nospam> wrote in message
news:12d0701c22281$063271d0$2ae2...@hosting.microsoft.com...
Just replace the picturebox in the original code with a
panel. Passing the control to the DrawLine funtion rather
than the graphics object works for the panel but not the
picturebox...
In both cases the controls (picturebox and panel) have all
their default properties.
Could this be something to do with how pictureboxes and
panels handle the creation and destruction of Device
Contexts?
>.
>
Enjoy.
Bob.
--
Have you thought about buying my book?
http://www.amazon.com/exec/obidos/ASIN/067232153X/bobpowelnet
Visit NetEdge Software to find out about the Web Service Enabler.
Enable all your legacy VB6 applications to seamlessly connect to .NET
web-services.
http://www.netedgesoftware.com
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Panel1 As System.Windows.Forms.Panel
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(192, 16)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(88, 96)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Panel1
'
Me.Panel1.Location = New System.Drawing.Point(16, 160)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(96, 104)
Me.Panel1.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1,
Me.PictureBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
drawabigx(CType(sender, Control), e)
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
drawabigx(CType(sender, Control), e)
End Sub
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
drawabigx(CType(sender, Control), e)
End Sub
Private Sub drawabigx(ByVal c As Control, ByVal e As PaintEventArgs)
Dim p As Pen = New Pen(Color.Red, 10)
e.Graphics.DrawLine(p, 5, 5, c.Width - 10, c.Height - 10)
e.Graphics.DrawLine(p, 5, c.Height - 10, c.Width - 10, 5)
p.Dispose()
End Sub
End Class
"Chris Wallis" <chris.wallis@nospam> wrote in message
news:1324001c22334$6cc8dd90$36ef2ecf@tkmsftngxa12...
Don't use paint method at all
call your Draw() function at form load or any other event
and in Draw()
do something like pictureBox.Refresh()
I took this route for one of my applications.
Deepak Kapoor
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.SizeChanged
Dim c As Control
For Each c In Me.Controls
c.Refresh()
Next
End Sub
This works with the X program I sent you Chris...
Bob.
"Deepak Kapoor" <letsd...@hotmail.com> wrote in message
news:uw8p4yAJCHA.1876@tkmsftngp12...