red_ghost
Member
I'm writing a screen for a program to design labels. When you click on the panel where you wish to place text, I open a form I created displaying Text, Font, and Direction. Direction will be in degrees for rotation. It works fine when I put in 0, but otherwise nothing happens. Nothing will be redrawn, not even any of the other graphics. How I am doing this is I have a class for each object type and a collection. When I draw them on screen in the click event I add them to the collection and let the paint method draw it. But when I have something rotated it doesn't draw anything. If I enter 180, it will alternate drawing the rectangle I use to display the limits of the label and the text. Here's the code:
Mouse Down:
Paint event:
Mouse Down:
VB.NET:
Private Sub pnlprv_Mousedown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles pnlprv.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Select Case mode
Case ""
Case "drawtext"
Dim ftext As New frmText
ftext.ShowDialog()
If ftext.cncl = False Then
Dim f As Font
Select Case ftext.cboFont.Text
Case "D"
f = New Font("Courier New", 19 / num, FontStyle.Regular, GraphicsUnit.Pixel)
End Select
Dim sfmat As New StringFormat
sfmat.Trimming = StringTrimming.Character
myGraphics.RotateTransform(ftext.rotate)
myGraphics.DrawString(ftext.txtText.Text, f, Brushes.Black, e.X, e.Y, sfmat)
Dim dt As New drawntext(e.X, e.Y, f, ftext.txtText.Text, Brushes.Black, sfmat, ftext.Rotate)
textcol.Add(dt)
myGraphics.RotateTransform(0)
Dim dir As String
If ftext.Rotate = 0 Then
dir = "N"
ElseIf ftext.Rotate = 90 Then
dir = "R"
ElseIf ftext.Rotate = 180 Then
dir = "I"
Else
dir = "B"
End If
Dim fontstring As String = vbCrLf & "^FO" & e.X * num & "," & e.Y * num & "^A0" & dir & ",0,0^FD " & dt.Text & "^FS" & vbCrLf & vbCrLf
txtCode.Text = txtCode.Text.Replace(vbCrLf & vbCrLf, fontstring)
End If
mode = ""
Me.Cursor = Cursors.Arrow
End Select
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
mode = ""
Me.Cursor = Cursors.Arrow
End If
End Sub
Paint event:
VB.NET:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim x As Integer = 0
RECTANGLEFORM = e.ClipRectangle
For x = 1 To rectcol.Count
Dim recta As drawnrect = rectcol.Item(x)
Dim rec As New Rectangle(recta.x, recta.y, recta.width, recta.height)
myGraphics.DrawRectangle(recta.pen, rec)
Dim recs() As Rectangle = {rec}
myGraphics.FillRectangles(recta.fill, recs)
Next
For x = 1 To textcol.Count
Dim dt As drawntext = textcol.Item(x)
myGraphics.RotateTransform(dt.Rotate)
myGraphics.DrawString(dt.Text, dt.Font, dt.Brush, dt.x, dt.y, dt.SFmat)
myGraphics.RotateTransform(0)
Next
End Sub