Can't graphics to display

H

Harley

I am trying to build graphic charts in a vb.net module callable from another
form. I have translated this code from VB6 where it worked well. I can
make the code work to bring up and display the form and its command buttons.
I can track the code execution with debug. However, I cannot change the
background color of the form or see any of the drawline or drawtext
functions. Here are a few relevant lines of code:

Module SMPLOT3

Dim f As New Market_Charts.Form2()

Dim g As Graphics = f.CreateGraphics

f.BackColor = System.Drawing.Color.Black

g.DrawString(ymn1, myFont, New SolidBrush(Color.Yellow), currentx, currenty)

Any ideas?

Harley
 
C

Chris Dunaway

I am trying to build graphic charts in a vb.net module callable from another
form. I have translated this code from VB6 where it worked well. I can
make the code work to bring up and display the form and its command buttons.
I can track the code execution with debug. However, I cannot change the
background color of the form or see any of the drawline or drawtext
functions. Here are a few relevant lines of code:

Module SMPLOT3

Dim f As New Market_Charts.Form2()

Dim g As Graphics = f.CreateGraphics

f.BackColor = System.Drawing.Color.Black

g.DrawString(ymn1, myFont, New SolidBrush(Color.Yellow), currentx, currenty)

Any ideas?

Harley

Yes, don't use CreateGraphics to grab a drawing handle from your
form. Instead, override the OnPaint method of the form and do you
painting there using the graphics object supplied.

See this website for additional information: www.bobpowell.net

Chris
 
H

Harley

Chris,

Thanks for the input, and I understand what you are saying. However, not
being a VB.net wizard, I am still struggling to make my code work. The
major issue is that while the main code is executing under Form2, I am
calling a module with the actual plotting routines. How do I set up the
main routine and the plotting module for the Paint Event Handler? Every
example that I see has the graphics code in the same modulke as the form. I
can do this, but I perfer not to.

Thanks,

Harley
 
C

Chris Dunaway

Chris,

Thanks for the input, and I understand what you are saying. However, not
being a VB.net wizard, I am still struggling to make my code work. The
major issue is that while the main code is executing under Form2, I am
calling a module with the actual plotting routines. How do I set up the
main routine and the plotting module for the Paint Event Handler? Every
example that I see has the graphics code in the same modulke as the form. I
can do this, but I perfer not to.

Thanks,

Harley

If you want to keep your graphics routines in a separate module, then
pass the items you need from the paint event to the method in the
module. For example:

'Paint event in the form class
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Using f As New Font("Arial", 30, FontStyle.Bold,
GraphicsUnit.Pixel)
GraphicsMethods.DoSomeDrawing(e.Graphics, "Draw Me", f, New
PointF(22, 450))
End Using
End Sub

'Module called GraphicsMethods

Imports System.Drawing

Module GraphicsMethods

Public Sub DoSomeDrawing(ByVal g As Graphics, ByVal textToDraw As
String, ByVal fnt As Font, ByVal location As PointF)
g.DrawString(textToDraw, fnt, Brushes.Black, location)
End Sub

End Module
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top