Results 1 to 3 of 3

Thread: VB.NET get variable from Function

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    191

    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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2021
    Posts
    191

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width