J
jcrouse
I have a program that is an external viewer. It is launched with a hotkey
from within another application. The program has 30 labels that can be
displayed. Since the labels may not always be oriented the same as the
Operating System I needed to use the Label_Paint event to PAINT the labels
text if it not oriented the same as the operating system. I am trying to
figure out a way to make this event happen faster or optimize it if
possible. I am new to this code. I think the idea was Herfreid's, can't even
remember. Here is the code:
Public Sub myPaint1(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim strLabelName As String
Select Case myPLabel.Name
Case "lblP1JoyUp"
strLabelName = Label1.Text
Case "lblP1JoyLeft"
strLabelName = Label2.Text
Case "lblP1JoyDown"
strLabelName = Label3.Text
Case "lblP1JoyRight"
strLabelName = Label4.Text
Case "lblP1B1"
strLabelName = Label5.Text
Case "lblP1B2"
strLabelName = Label6.Text
Case "lblP1B3"
strLabelName = Label7.Text
Case "lblP1B4"
strLabelName = Label8.Text
Case "lblP1B5"
strLabelName = Label9.Text
Case "lblP1B6"
strLabelName = Label10.Text
Case "lblP1B7"
strLabelName = Label11.Text
Case "lblP1B8"
strLabelName = Label12.Text
Case "lblP1JoyType"
strLabelName = Label25.Text
Case "lblGameName"
strLabelName = Label27.Text
Case "lblNumPlayers"
strLabelName = Label28.Text
Case "lblHistory"
strLabelName = Label29.Text
Case "lblUndocumented"
strLabelName = Label30.Text
End Select
If myPLabel.Visible = True Then
Dim myFontBrush As New SolidBrush(myPLabel.ForeColor)
If frm1.intPriHP1 = frm1.intPriVP1 Then
If strLay1RotAngle = "0" Then
myPLabel.Text = strLabelName
ElseIf strLay1RotAngle = "90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width
+ x) \ 2, (myPLabel.ClientSize.Height + y) \ 2)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
ElseIf strLay1RotAngle = "180" Then
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
myPLabel.Text = ""
e.Graphics.TranslateTransform(myPLabel.ClientSize.Width,
myPLabel.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, RectangleF.op_Implicit(myPLabel.ClientRectangle), sf)
ElseIf strLay1RotAngle = "-90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
lblP1JoyUp.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width -
x) \ 2, (myPLabel.ClientSize.Height - y) \ 2)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
End If
ElseIf frm1.intPriHP1 <> frm1.intPriVP1 Then
If strGameO = "h" Then
If strLay1RotAngle = "0" Then
myPLabel.Text = strLabelName
ElseIf strLay1RotAngle = "90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width + x) \ 2,
(myPLabel.ClientSize.Height + y) \ 2)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
ElseIf strLay1RotAngle = "180" Then
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
myPLabel.Text = ""
e.Graphics.TranslateTransform(myPLabel.ClientSize.Width,
myPLabel.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, RectangleF.op_Implicit(myPLabel.ClientRectangle), sf)
ElseIf strLay1RotAngle = "-90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width - x) \ 2,
(myPLabel.ClientSize.Height - y) \ 2)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
End If
ElseIf strGameO = "v" Then
If strLay2RotAngle = "0" Then
myPLabel.Text = strLabelName
ElseIf strLay2RotAngle = "90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width + x) \ 2,
(myPLabel.ClientSize.Height + y) \ 2)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
ElseIf strLay2RotAngle = "180" Then
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
myPLabel.Text = ""
e.Graphics.TranslateTransform(myPLabel.ClientSize.Width,
myPLabel.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, RectangleF.op_Implicit(myPLabel.ClientRectangle), sf)
ElseIf strLay2RotAngle = "-90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width - x) \ 2,
(myPLabel.ClientSize.Height - y) \ 2)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
End If
End If
End If
myFontBrush.Dispose()
End If
End Sub
Any ides how I might speed this up? Currently, if then user is displaying
all 30 labels I need am calling this code 30 times.
Thnaks,
John
from within another application. The program has 30 labels that can be
displayed. Since the labels may not always be oriented the same as the
Operating System I needed to use the Label_Paint event to PAINT the labels
text if it not oriented the same as the operating system. I am trying to
figure out a way to make this event happen faster or optimize it if
possible. I am new to this code. I think the idea was Herfreid's, can't even
remember. Here is the code:
Public Sub myPaint1(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim strLabelName As String
Select Case myPLabel.Name
Case "lblP1JoyUp"
strLabelName = Label1.Text
Case "lblP1JoyLeft"
strLabelName = Label2.Text
Case "lblP1JoyDown"
strLabelName = Label3.Text
Case "lblP1JoyRight"
strLabelName = Label4.Text
Case "lblP1B1"
strLabelName = Label5.Text
Case "lblP1B2"
strLabelName = Label6.Text
Case "lblP1B3"
strLabelName = Label7.Text
Case "lblP1B4"
strLabelName = Label8.Text
Case "lblP1B5"
strLabelName = Label9.Text
Case "lblP1B6"
strLabelName = Label10.Text
Case "lblP1B7"
strLabelName = Label11.Text
Case "lblP1B8"
strLabelName = Label12.Text
Case "lblP1JoyType"
strLabelName = Label25.Text
Case "lblGameName"
strLabelName = Label27.Text
Case "lblNumPlayers"
strLabelName = Label28.Text
Case "lblHistory"
strLabelName = Label29.Text
Case "lblUndocumented"
strLabelName = Label30.Text
End Select
If myPLabel.Visible = True Then
Dim myFontBrush As New SolidBrush(myPLabel.ForeColor)
If frm1.intPriHP1 = frm1.intPriVP1 Then
If strLay1RotAngle = "0" Then
myPLabel.Text = strLabelName
ElseIf strLay1RotAngle = "90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width
+ x) \ 2, (myPLabel.ClientSize.Height + y) \ 2)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
ElseIf strLay1RotAngle = "180" Then
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
myPLabel.Text = ""
e.Graphics.TranslateTransform(myPLabel.ClientSize.Width,
myPLabel.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, RectangleF.op_Implicit(myPLabel.ClientRectangle), sf)
ElseIf strLay1RotAngle = "-90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
lblP1JoyUp.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width -
x) \ 2, (myPLabel.ClientSize.Height - y) \ 2)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
End If
ElseIf frm1.intPriHP1 <> frm1.intPriVP1 Then
If strGameO = "h" Then
If strLay1RotAngle = "0" Then
myPLabel.Text = strLabelName
ElseIf strLay1RotAngle = "90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width + x) \ 2,
(myPLabel.ClientSize.Height + y) \ 2)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
ElseIf strLay1RotAngle = "180" Then
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
myPLabel.Text = ""
e.Graphics.TranslateTransform(myPLabel.ClientSize.Width,
myPLabel.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, RectangleF.op_Implicit(myPLabel.ClientRectangle), sf)
ElseIf strLay1RotAngle = "-90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width - x) \ 2,
(myPLabel.ClientSize.Height - y) \ 2)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
End If
ElseIf strGameO = "v" Then
If strLay2RotAngle = "0" Then
myPLabel.Text = strLabelName
ElseIf strLay2RotAngle = "90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width + x) \ 2,
(myPLabel.ClientSize.Height + y) \ 2)
e.Graphics.RotateTransform(90)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
ElseIf strLay2RotAngle = "180" Then
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
myPLabel.Text = ""
e.Graphics.TranslateTransform(myPLabel.ClientSize.Width,
myPLabel.ClientSize.Height)
e.Graphics.RotateTransform(180)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, RectangleF.op_Implicit(myPLabel.ClientRectangle), sf)
ElseIf strLay2RotAngle = "-90" Then
Dim y As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Width)
Dim x As Integer =
CInt(e.Graphics.MeasureString(strLabelName, myPLabel.Font).Height)
myPLabel.Text = ""
e.Graphics.TranslateTransform((myPLabel.ClientSize.Width - x) \ 2,
(myPLabel.ClientSize.Height - y) \ 2)
e.Graphics.RotateTransform(270)
e.Graphics.DrawString(strLabelName, myPLabel.Font,
myFontBrush, -y, 0)
End If
End If
End If
myFontBrush.Dispose()
End If
End Sub
Any ides how I might speed this up? Currently, if then user is displaying
all 30 labels I need am calling this code 30 times.
Thnaks,
John