EDN Admin
Well-known member
Would really appreciate your help after many hours of personal unsuccessful attempts to solve my coding problem. The program below works fine except for the problem for which I am seeking your help.
The program below allows input of a volume and value which are both successfully drawn to the screen. I will be adding variables to retain the value of each new Volume and new Value input. However, I need code to delete the volume and value graphic numbers
drawn to screen when new volume and values are input. At present new numbers are drawn on top of the existing graphics rather than replacing them. Every attempt to clear, draw over etc has failed. Can you help me please...from a very grateful member about
to go on holiday and I need this to work for use on hols.
The private sub resetting() does not work but I cannot see why.
Public Class PerudoWindow
Private m_objDrawingSurface As Bitmap
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Create a drawing surface with the same dimensions as the client
area of the form
m_objDrawingSurface = New Bitmap(Me.ClientRectangle.Width, _
Me.ClientRectangle.Height, _
Drawing.Imaging.PixelFormat.Format24bppRgb)
InitializeSurface()
End Sub
Private Sub InitializeSurface()
Dim objGraphics As Graphics
Dim rectBounds As Rectangle
Create a Graphics object that references the bitmap and clears it
objGraphics = Graphics.FromImage(m_objDrawingSurface)
objGraphics.Clear(System.Drawing.SystemColors.Control)
create a rectangle the same size as the bitmap
rectBounds = New Rectangle(0, 0, m_objDrawingSurface.Width, m_objDrawingSurface.Height)
End Sub
Private Sub MainForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim objGraphics As Graphics
you cant modify e. Graphics directly
objGraphics = e.Graphics
draw the contents of the bitmap on the form
objGraphics.DrawImage(m_objDrawingSurface, 0, 0, m_objDrawingSurface.Width, m_objDrawingSurface.Height)
End Sub
BEGIN VOLUME INPUT PROCESSING
Private Sub propvolinput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propvolinput.TextChanged
End Sub
Private Sub propvol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propvol.Click
Dim objGraphics As Graphics
Dim objfont = New System.Drawing.Font("Verdana", 48, FontStyle.Bold)
if no text has been entered, get out
If propvolinput.Text = "" Then Exit Sub
create a graphics object using the memory bitmap
objGraphics = Graphics.FromImage(m_objDrawingSurface)
draw users text
objGraphics.DrawString(propvolinput.Text, objfont, Brushes.Navy, 10, 10)
cleanup
objGraphics.Dispose()
force the form to paint itself. This triggers the paint event
Me.Invalidate()
End Sub
BEGIN VALUE INPUT PROCESSING
Private Sub propvalinput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propvalinput.TextChanged
End Sub
Private Sub propval_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propval.Click
Dim objGraphics As Graphics
Dim objfont = New System.Drawing.Font("Verdana", 48, FontStyle.Bold)
if no text has been entered, get out
If propvalinput.Text = "" Then Exit Sub
create a graphics object using the memory bitmap
objGraphics = Graphics.FromImage(m_objDrawingSurface)
draw users text
objGraphics.DrawString(propvalinput.Text, objfont, Brushes.Navy, 10, 90)
cleanup
objGraphics.Dispose()
force the form to paint itself. This triggers the paint event
Me.Invalidate()
End Sub
Private Sub resetting()
Dim m_objDrawingSurface As New Bitmap(100, 100)
Using g As Graphics = Graphics.FromImage(m_objDrawingSurface)
g.Clear(Color.DarkMagenta)
End Using
End Sub
End Class
View the full article
The program below allows input of a volume and value which are both successfully drawn to the screen. I will be adding variables to retain the value of each new Volume and new Value input. However, I need code to delete the volume and value graphic numbers
drawn to screen when new volume and values are input. At present new numbers are drawn on top of the existing graphics rather than replacing them. Every attempt to clear, draw over etc has failed. Can you help me please...from a very grateful member about
to go on holiday and I need this to work for use on hols.
The private sub resetting() does not work but I cannot see why.
Public Class PerudoWindow
Private m_objDrawingSurface As Bitmap
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Create a drawing surface with the same dimensions as the client
area of the form
m_objDrawingSurface = New Bitmap(Me.ClientRectangle.Width, _
Me.ClientRectangle.Height, _
Drawing.Imaging.PixelFormat.Format24bppRgb)
InitializeSurface()
End Sub
Private Sub InitializeSurface()
Dim objGraphics As Graphics
Dim rectBounds As Rectangle
Create a Graphics object that references the bitmap and clears it
objGraphics = Graphics.FromImage(m_objDrawingSurface)
objGraphics.Clear(System.Drawing.SystemColors.Control)
create a rectangle the same size as the bitmap
rectBounds = New Rectangle(0, 0, m_objDrawingSurface.Width, m_objDrawingSurface.Height)
End Sub
Private Sub MainForm_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim objGraphics As Graphics
you cant modify e. Graphics directly
objGraphics = e.Graphics
draw the contents of the bitmap on the form
objGraphics.DrawImage(m_objDrawingSurface, 0, 0, m_objDrawingSurface.Width, m_objDrawingSurface.Height)
End Sub
BEGIN VOLUME INPUT PROCESSING
Private Sub propvolinput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propvolinput.TextChanged
End Sub
Private Sub propvol_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propvol.Click
Dim objGraphics As Graphics
Dim objfont = New System.Drawing.Font("Verdana", 48, FontStyle.Bold)
if no text has been entered, get out
If propvolinput.Text = "" Then Exit Sub
create a graphics object using the memory bitmap
objGraphics = Graphics.FromImage(m_objDrawingSurface)
draw users text
objGraphics.DrawString(propvolinput.Text, objfont, Brushes.Navy, 10, 10)
cleanup
objGraphics.Dispose()
force the form to paint itself. This triggers the paint event
Me.Invalidate()
End Sub
BEGIN VALUE INPUT PROCESSING
Private Sub propvalinput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propvalinput.TextChanged
End Sub
Private Sub propval_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles propval.Click
Dim objGraphics As Graphics
Dim objfont = New System.Drawing.Font("Verdana", 48, FontStyle.Bold)
if no text has been entered, get out
If propvalinput.Text = "" Then Exit Sub
create a graphics object using the memory bitmap
objGraphics = Graphics.FromImage(m_objDrawingSurface)
draw users text
objGraphics.DrawString(propvalinput.Text, objfont, Brushes.Navy, 10, 90)
cleanup
objGraphics.Dispose()
force the form to paint itself. This triggers the paint event
Me.Invalidate()
End Sub
Private Sub resetting()
Dim m_objDrawingSurface As New Bitmap(100, 100)
Using g As Graphics = Graphics.FromImage(m_objDrawingSurface)
g.Clear(Color.DarkMagenta)
End Using
End Sub
End Class
View the full article