Pete-
New member
Hi all
Im trying to add coloured text at X, Y coords on the form. I have 4 text string and each string will be a differant colour.
I want it to display the text together in one line as abcedfghijklmnopqrstuvwx.
The problem Im having is when the text is displayed there are spaces or overlapping between each string abcedf ghijkl mnopstuvwx and I dont know how to solve it.
Any help or if anyone got a better idea on how to do it would be nice
Thanks
Im trying to add coloured text at X, Y coords on the form. I have 4 text string and each string will be a differant colour.
I want it to display the text together in one line as abcedfghijklmnopqrstuvwx.
The problem Im having is when the text is displayed there are spaces or overlapping between each string abcedf ghijkl mnopstuvwx and I dont know how to solve it.
Any help or if anyone got a better idea on how to do it would be nice
Thanks
Code:
Sample Code..
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim myFontBold As New Font("Verdana", 15, FontStyle.Bold)
Dim Ycoord As Integer = 40
Dim Xcoord As Integer = 0
Dim StringSizeA As Double
Dim StringSizeB As Double
Dim StringSizeC As Double
Dim StringSizeD As Double
Dim TextA As String = "acdebf"
Dim TextB As String = "ghijkl"
Dim TextC As String = "mnopqr"
Dim TextD As String = "stuvwx"
StringSizeA = Me.CreateGraphics.MeasureString(TextA, myFontBold).Width
StringSizeB = Me.CreateGraphics.MeasureString(TextB, myFontBold).Width
StringSizeC = Me.CreateGraphics.MeasureString(TextB, myFontBold).Width
StringSizeD = Me.CreateGraphics.MeasureString(TextD, myFontBold).Width
Me.CreateGraphics.DrawString(TextA, myFontBold, System.Drawing.Brushes.Blue, Xcoord, Ycoord)
Me.CreateGraphics.DrawString(TextB, myFontBold, System.Drawing.Brushes.Red, Xcoord + StringSizeA, Ycoord)
Me.CreateGraphics.DrawString(TextC, myFontBold, System.Drawing.Brushes.Green, Xcoord + StringSizeA + StringSizeB, Ycoord)
Me.CreateGraphics.DrawString(TextD, myFontBold, System.Drawing.Brushes.Yellow, Xcoord + StringSizeA + StringSizeB + StringSizeC, Ycoord)
Me.CreateGraphics.Dispose()
End Sub