[英]TabControl OnPaint calling
I have a custom TabControl
control. 我有一个自定义的
TabControl
控件。 Here's the OnPaint
method: 这是
OnPaint
方法:
Protected Overrides Sub OnPaint(e As PaintEventArgs)
G = e.Graphics
G.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
G.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
MyBase.OnPaint(e)
G.Clear(ColorFromHex("#343843"))
For I As Integer = 0 To TabPages.Count - 1
Rect = GetTabRect(I)
Dim Data As AccountData = DirectCast(TabPages(I).Tag, AccountData)
If Data IsNot Nothing Then
TabPages(I).ImageIndex = Data.Icon / 2
End If
If SelectedIndex = I Then
Using B1 As New SolidBrush(ColorFromHex("#3A3E49"))
G.FillRectangle(B1, New Rectangle(Rect.X - 4, Rect.Y + 1, Rect.Width + 6, Rect.Height))
End Using
End If
Using B1 As New SolidBrush(ColorFromHex("#737A8A"))
If UpperText Then
Using F1 As New Font("Segoe UI", 7.75, FontStyle.Bold)
G.DrawString(TabPages(I).Text.ToUpper, F1, B1, New Point(Rect.X + 70, Rect.Y + 10))
If Data Is Nothing Then
G.DrawString("Idle", F1, B1, New Point(Rect.X + 70, Rect.Y + 20))
Else
G.DrawString(Data.Status, F1, B1, New Point(Rect.X + 70, Rect.Y + 20))
G.DrawString("Lv. " & Data.Level, F1, B1, New Point(Rect.X + 70, Rect.Y + 30))
G.DrawString(Data.IP & " IP / " & Data.RP & " RP", F1, B1, New Point(Rect.X + 70, Rect.Y + 40))
End If
End Using
Else
Using F1 As New Font("Segoe UI semibold", 9)
G.DrawString(TabPages(I).Text, F1, B1, New Point(Rect.X + 50, Rect.Y + 11))
End Using
End If
End Using
If Not I = 0 Then
Using P1 As New Pen(ColorFromHex("#3B3D49")), P2 As New Pen(ColorFromHex("#2F323C"))
G.DrawLine(P1, New Point(Rect.X - 4, Rect.Y + 1), New Point(Rect.Width + 4, Rect.Y + 1))
G.DrawLine(P2, New Point(Rect.X - 4, Rect.Y + 2), New Point(Rect.Width + 4, Rect.Y + 2))
End Using
End If
If Not IsNothing(ImageList) Then
If Not TabPages(I).ImageIndex < 0 Then
G.DrawImage(ImageList.Images(TabPages(I).ImageIndex), New Rectangle(Rect.X + 10, Rect.Y + 10, 48, 48))
End If
End If
Next
End Sub
As you can see, it checks for the tag. 如您所见,它将检查标签。 If the tag is not null, it draws the
Status
property, the Level
property and the IP
/ RP
properties. 如果标记不为null,则将绘制
Status
属性, Level
属性和IP
/ RP
属性。 Each tab is associated with a player, so when the player logs in the tag is set to the appropriate AccountData
value and then I call the following to update it: 每个选项卡都与一个播放器相关联,因此当播放器登录时,将标记设置为适当的
AccountData
值,然后调用以下命令对其进行更新:
public void UpdateAccountData(int index, AccountData data)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => this.UpdateAccountData(index, data)));
return;
}
this.aetherTabControl1.TabPages[index].Tag = data;
this.aetherTabControl1.TabPages[index].Invalidate(true);
this.aetherTabControl1.TabPages[index].Update();
this.aetherTabControl1.TabPages[index].Refresh();
}
I know this is bad, but I'm not sure how to redraw it everytime I update a property of AccountData
. 我知道这很不好,但是我不确定每次更新
AccountData
的属性时如何重绘它。 Is there a better way to do this instead of repainting it everytime? 有没有比每次都重新粉刷更好的方法了?
Thanks. 谢谢。
Yes there is a better way. 是的,有更好的方法。
Way 1:Your AccountData
properties are reflected in the screen via labels or textboxes or other controls, right?!? 方式1:您的
AccountData
属性通过标签或文本框或其他控件反映在屏幕上,对吗? if, upon AccountData
update, you reset the values of such controls, they will automatically repaint... 如果在
AccountData
更新时重置了此类控件的值,它们将自动重新绘制...
Way 2: sticking with your "repaint by myself" approach, you can buffer up a bunch of stuff, such as Brusher
s, Color
s and perhaps turn the images in a sprite dynamically, so in the end of the repaint, you only need to paint a different part of the sprite, instead of the whole thing... 方法2:坚持使用“自己重
Brusher
”方法,可以缓冲一堆东西,例如Brusher
, Color
并且可以动态地将图像变成精灵,因此在重Brusher
结束时,您只需要绘制精灵的不同部分,而不是整个对象...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.