VB.NET get variable from Function
Hi All, I found some code for painting rotated text on my form. Code seems to work great and I am using this text basically as labels. My question is, how can I get the 'TEXT' in the code and assign it to a variable that I can use elsewhere?
From this line, I need "ATE 500" assigned to a variable. I will end up using this method several times to create multiple text strings. Here I have only two so far.
Code:
DrawRotateText(e.Graphics, -50, "ATE 500", x1, y1, rotatedFont, Brushes.Firebrick)
Code:
Code:
Public Class Form1
Dim rotatedFont As New Font("Segoe UI", 14)
Private Sub RotateText_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
' Label 1
Dim lb1 As Integer = 40, x1 As Integer = -25, y1 As Integer = 170
DrawRotateText(e.Graphics, -50, "ATE 500", x1, y1, rotatedFont, Brushes.Firebrick)
x1 += lb1
' Label 2
Dim lb2 As Integer = 40, x2 As Integer = 60, y2 As Integer = 170
DrawRotateText(e.Graphics, -50, "ATE 800", x2, y2, rotatedFont, Brushes.Firebrick)
x2 += lb2
End Sub
Function DrawRotateText(ByVal gr As Graphics, ByVal angle As Decimal, ByVal txt As String, ByVal x As Integer, ByVal y As Integer, ByVal rotatedFont As Font, ByVal thebrush As Brush)
Dim state As GraphicsState = gr.Save
gr.ResetTransform()
gr.RotateTransform(angle)
gr.TranslateTransform(x, y, MatrixOrder.Append)
gr.DrawString(txt, rotatedFont, thebrush, 70, -10)
gr.Restore(state)
End Function
End Class
Re: VB.NET get variable from Function
Well... where does it come from to begin with? User Input? File? Or is it just hard-coded and doesn't change?
Code:
Const ATE_500 as String = "ATE 500"
Const ATE_800 as String = "ATE 800"
Then you can use ATE-500 or ATE_800 in your code as needed...
-tg
Re: VB.NET get variable from Function
Thanks techgnome. I think this will get me what I need. Somehow I was thinking something else with how to get this, but this will work perfect.