Results 1 to 9 of 9

Thread: [RESOLVED] Displaying Text in the Y-axis

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Resolved [RESOLVED] Displaying Text in the Y-axis

    I would like to display the word " Volts(V) " in the Y axis, just like the one you see from the attached image.
    But that image is crop from elsewhere and placed into a picturebox, which to me, doesnt look nice. I would prefer if the words are type in manually into a label and then rotate.

    I did some research through the forums and websites, and came across this:
    > http://www.vbforums.com/showthread.p...ight=Axis+Text
    from there, i have a brief idea on it , tried out but it didnt work though. Or i may not have done it correctly.
    So I hope to receive some guidance on this. Thanks in advance.

    And an advance Merry X'mas to everyone.
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Displaying Text in the Y-axis (UPDATE)

    As for now, i just figured out and manage to display the text this way (see new attached image), but i hope to rotate it to the other way like the older image i've attached in the 1st post.

    Following is the code i figured out..
    Code:
    e.Graphics.DrawString("Volts (V)", Font, _
                                  Brushes.Black, 16, 111, New StringFormat(StringFormatFlags.DirectionVertical))
    Came across a few code on rotating the text but it couldnt work.

    Hope to receive some suggestions and guidance on how to rotate the text and also to display the text in bold ?

    Thanks in advance once again.
    Attached Images Attached Images  

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Text in the Y-axis

    Check out my examples here:

    http://www.vbforums.com/showthread.p...otateTransform

    You can call TranslateTransform first to move the origin to the exact bottom-left of where you want the text drawn, then call RotateTransform to rotate the world by 180 degrees.
    Last edited by jmcilhinney; Dec 21st, 2009 at 12:45 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Text in the Y-axis

    Alternatively, you might consider using the Microsoft .NET Chart control, which I'm sure would let you label an axis.

    http://www.microsoft.com/downloads/d...displaylang=en
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Displaying Text in the Y-axis

    The following shows the code to display the ruler markings and one portion of the code high-lighted in blue, is the code to display the word "Volts(V)" in the y-axis but i want it to rotate and display the other way.

    I tried inputing the code >jmcilhinney< suggested ( the new code i input is not shown in this thread as it couldnt work), but instead the whole ruler markings plus the word rotates and disappears.

    Hmm, could you explain to me why ? I think i input the wrong code or in the wrong place? Hmm.. ?

    Code:
    Private Sub PictureBox2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
    
            Dim g As Graphics = e.Graphics
            Dim vertFont As New Font("Verdana", 10, FontStyle.Bold)
            Dim horzFont As New Font("Verdana", 10, FontStyle.Bold)
            Dim vertBrush As New SolidBrush(Color.Blue)
            Dim horzBrush As New SolidBrush(Color.Blue)
            Dim horzBrush1 As New SolidBrush(Color.Red)
    
            Dim bluePen As New Pen(Color.Blue)
            Dim redPen As New Pen(Color.Red, 2)
    
            ' Drawing a vertical and a horizontal line 
            g.DrawLine(bluePen, 50, 220, 50, 15)   'vertical line
            g.DrawLine(bluePen, 50, 220, 260, 220)  'horizontal line
    
    
            ' Horizontal line which will vary according to voltage level
            Dim voltsY As Integer = 220 - CInt(volts * 50)
            g.DrawLine(redPen, 50, voltsY, 260, voltsY)
    
            
            Dim Font1 As New Font("Comic Sans MS", 10, FontStyle.Bold)
            g.DrawString("Volts (V)", Font1, _
                               Brushes.Black, 16, 111, New StringFormat(StringFormatFlags.DirectionVertical))      
            
    
            'Draw vertical strings 
            Dim vertStrFormat As New StringFormat()
            vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical
            g.DrawString("-", horzFont, horzBrush, 49, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 49, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 59, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 69, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 79, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 89, 205, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 99, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 109, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 119, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 129, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 139, 205, vertStrFormat)
    
            g.DrawString("-", horzFont, horzBrush, 149, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 159, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 169, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 179, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 189, 205, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 199, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 209, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 219, 212, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 229, 212, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 239, 205, vertStrFormat)
    
    
            ' y-axis drawing 
    
            g.DrawString("  4 --", vertFont, vertBrush, 25, 12)
            g.DrawString("    --", vertFont, vertBrush, 25, 12)
            g.DrawString("     -", vertFont, vertBrush, 25, 22)
            g.DrawString("     -", vertFont, vertBrush, 25, 32)
            g.DrawString("     -", vertFont, vertBrush, 25, 42)
            g.DrawString("     -", vertFont, vertBrush, 25, 52)
    
            g.DrawString("  3 --", vertFont, vertBrush, 25, 62)
            g.DrawString("    --", vertFont, vertBrush, 25, 62)
            g.DrawString("     -", vertFont, vertBrush, 25, 72)
            g.DrawString("     -", vertFont, vertBrush, 25, 82)
            g.DrawString("     -", vertFont, vertBrush, 25, 92)
            g.DrawString("     -", vertFont, vertBrush, 25, 102)
    
            g.DrawString("  2 --", vertFont, vertBrush, 25, 112)
            g.DrawString("    --", vertFont, vertBrush, 25, 112)
            g.DrawString("     -", vertFont, vertBrush, 25, 122)
            g.DrawString("     -", vertFont, vertBrush, 25, 132)
            g.DrawString("     -", vertFont, vertBrush, 25, 142)
            g.DrawString("     -", vertFont, vertBrush, 25, 152)
    
            g.DrawString("  1 --", vertFont, vertBrush, 25, 162)
            g.DrawString("    --", vertFont, vertBrush, 25, 162)
            g.DrawString("     -", vertFont, vertBrush, 25, 172)
            g.DrawString("     -", vertFont, vertBrush, 25, 182)
            g.DrawString("     -", vertFont, vertBrush, 25, 192)
            g.DrawString("     -", vertFont, vertBrush, 25, 202)
            g.DrawString("  0", vertFont, vertBrush, 25, 212)
    
    
            
    
            ' Dispose of objects 
            vertFont.Dispose()
            horzFont.Dispose()
            vertBrush.Dispose()
            horzBrush.Dispose()
            bluePen.Dispose()
            redPen.Dispose()
    
        End Sub

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Text in the Y-axis

    You don't want to rotate anything but the text, so you need to draw everything else, then apply the translations, then draw the text.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Displaying Text in the Y-axis

    Hello. Thanks for your prompt reply.
    I understand what you meant. =)

    But.. is it correct to input the following code :

    Code:
    Private Sub PictureBox2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
    ... 
    ..
    ..
    ..
     Dim Font1 As New Font("Comic Sans MS", 10, FontStyle.Bold)
            g.TranslateTransform(16, 111)
            g.DrawString("Volts (V)", Font1, _
                          Brushes.Black, 16, 111, New StringFormat(StringFormatFlags.DirectionVertical))
    16, 111 is the final position that i want the text to be.
    I believe theres a mistake with "g.TranslateTransform(16, 111)", but i've got no idea what to replace it with. It seems easy, but i'm in the midst of learning vb. =) Hope to receive your guidance on that.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Text in the Y-axis

    When you call TranslateTransform you specify the coordinates you want to shift the origin to. Specify the bottom-left corner of the text, then specify draw the text at the origin, i.e. specify 0 and 0 for the X and Y coordinates when you call DrawString.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: Displaying Text in the Y-axis

    Understood what u meant.
    It works!!

    Thanks !

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