L
Les2011
Guest
Hi my name is Les. I have been trying to learn about the various parameters that are in some objects and the events that are available within them. I am making progress but have a lack of a full understanding about what I would like to do. I have enclosed my code snippet which in fact is what I want to do but want it on a picturebox. Because I don't have a full understanding as to how it all gets tied together I come humbly here. I have tried Barnes & Nobel for some good books on this subject and believe it or not they have none that are available and that I have to just buy and hope it has what I need. If by chance someone can mention a good book on the various things we can do with graphics like I am looking to do I would appreciate it. Ok I have enclosed my code.
Private Sub form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
' Make the font. Use Pixels as the unit.
Dim FONT_SIZE As Integer
FONT_SIZE = 100
Dim the_font As New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel)
' Make the text origin and StringFormat.
Dim sf As New StringFormat
Dim origin As New PointF(100, 200)
origin.X = 100
origin.Y = 200
' Add the text to the GraphicsPath.
Dim text_path As New GraphicsPath
Dim a As SizeF
Dim t As String
Dim text_rectf As RectangleF = text_path.GetBounds()
Dim text_rect As Rectangle = Rectangle.Round(text_rectf)
t = "f(x)=12x"
FONT_SIZE = 100
a = e.Graphics.MeasureString(t, New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel))
origin.X = 0
text_path.AddString(t, the_font.FontFamily, CInt(FontStyle.Regular), FONT_SIZE, origin, sf)
' Draw the text.
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(Brushes.Black, text_path)
e.Graphics.DrawPath(Pens.Black, text_path)
' Draw the bounding rectangle.
text_rectf = text_path.GetBounds()
text_rect = Rectangle.Round(text_rectf)
e.Graphics.DrawRectangle(Pens.Red, text_rect)
origin.X = text_rect.Width + 15
t = "2"
FONT_SIZE = 50
a = e.Graphics.MeasureString(t, New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel))
text_path.AddString(t, the_font.FontFamily, CInt(FontStyle.Regular), FONT_SIZE, origin, sf)
' Draw the text.
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(Brushes.Black, text_path)
e.Graphics.DrawPath(Pens.Black, text_path)
' Draw the bounding rectangle.
text_rectf = text_path.GetBounds()
text_rect = Rectangle.Round(text_rectf)
e.Graphics.DrawRectangle(Pens.Red, text_rect)
t = "-5x+3"
FONT_SIZE = 100
a = e.Graphics.MeasureString(t, New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel))
origin.X = text_rect.Width
text_path.AddString(t, the_font.FontFamily, CInt(FontStyle.Regular), FONT_SIZE, origin, sf)
' Draw the text.
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(Brushes.Black, text_path)
e.Graphics.DrawPath(Pens.Black, text_path)
' Draw the bounding rectangle.
text_rectf = text_path.GetBounds()
text_rect = Rectangle.Round(text_rectf)
e.Graphics.DrawRectangle(Pens.Red, text_rect)
' Cleanup.
sf.Dispose()
the_font.Dispose()
End Sub
What this code does at the moment is it draws what I want but it goes onto the form and not the picturebox since the code is in that form object. Now I can get it into the picturebox successfully but what I want to do is be able to write my code in lets say some command button and have it send the graphics to the paint event within the picturebox. Can someone get me started here so that I can get an understanding how to do this?
Thank you for your help in advance,
Les
Continue reading...
Private Sub form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
' Make the font. Use Pixels as the unit.
Dim FONT_SIZE As Integer
FONT_SIZE = 100
Dim the_font As New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel)
' Make the text origin and StringFormat.
Dim sf As New StringFormat
Dim origin As New PointF(100, 200)
origin.X = 100
origin.Y = 200
' Add the text to the GraphicsPath.
Dim text_path As New GraphicsPath
Dim a As SizeF
Dim t As String
Dim text_rectf As RectangleF = text_path.GetBounds()
Dim text_rect As Rectangle = Rectangle.Round(text_rectf)
t = "f(x)=12x"
FONT_SIZE = 100
a = e.Graphics.MeasureString(t, New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel))
origin.X = 0
text_path.AddString(t, the_font.FontFamily, CInt(FontStyle.Regular), FONT_SIZE, origin, sf)
' Draw the text.
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(Brushes.Black, text_path)
e.Graphics.DrawPath(Pens.Black, text_path)
' Draw the bounding rectangle.
text_rectf = text_path.GetBounds()
text_rect = Rectangle.Round(text_rectf)
e.Graphics.DrawRectangle(Pens.Red, text_rect)
origin.X = text_rect.Width + 15
t = "2"
FONT_SIZE = 50
a = e.Graphics.MeasureString(t, New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel))
text_path.AddString(t, the_font.FontFamily, CInt(FontStyle.Regular), FONT_SIZE, origin, sf)
' Draw the text.
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(Brushes.Black, text_path)
e.Graphics.DrawPath(Pens.Black, text_path)
' Draw the bounding rectangle.
text_rectf = text_path.GetBounds()
text_rect = Rectangle.Round(text_rectf)
e.Graphics.DrawRectangle(Pens.Red, text_rect)
t = "-5x+3"
FONT_SIZE = 100
a = e.Graphics.MeasureString(t, New Font("Times New Roman", FONT_SIZE, FontStyle.Regular, GraphicsUnit.Pixel))
origin.X = text_rect.Width
text_path.AddString(t, the_font.FontFamily, CInt(FontStyle.Regular), FONT_SIZE, origin, sf)
' Draw the text.
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(Brushes.Black, text_path)
e.Graphics.DrawPath(Pens.Black, text_path)
' Draw the bounding rectangle.
text_rectf = text_path.GetBounds()
text_rect = Rectangle.Round(text_rectf)
e.Graphics.DrawRectangle(Pens.Red, text_rect)
' Cleanup.
sf.Dispose()
the_font.Dispose()
End Sub
What this code does at the moment is it draws what I want but it goes onto the form and not the picturebox since the code is in that form object. Now I can get it into the picturebox successfully but what I want to do is be able to write my code in lets say some command button and have it send the graphics to the paint event within the picturebox. Can someone get me started here so that I can get an understanding how to do this?
Thank you for your help in advance,
Les
Continue reading...