|
-
Dec 20th, 2009, 07:57 PM
#1
Thread Starter
Lively Member
-
Dec 20th, 2009, 10:05 PM
#2
Thread Starter
Lively Member
Re: Displaying Text in the Y-axis (UPDATE)
-
Dec 21st, 2009, 12:41 AM
#3
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.
-
Dec 21st, 2009, 12:47 AM
#4
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
-
Dec 21st, 2009, 08:28 PM
#5
Thread Starter
Lively Member
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
-
Dec 21st, 2009, 08:30 PM
#6
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.
-
Dec 21st, 2009, 08:59 PM
#7
Thread Starter
Lively Member
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.
-
Dec 21st, 2009, 09:18 PM
#8
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.
-
Dec 21st, 2009, 10:04 PM
#9
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|