Hallo.
Ich habe eine Klassenbibliothek, in der ich mir gerade selbst ein paar Controls am erstellen bin. Soweit so gut.
In einer Windows-Forms Anwendung erbe ich die Controls aus der Klassenbibliothek (u.A. auch die Form).
Jetzt sieht im Designer alles wirklich super aus - wenn ich das Programm starte
jedoch nicht. Alles wirkt unscharf, schlecht gezeichnet. Selbst die "originalen" mit dem .Net Framework
mitgelieferten Controls sehen auf der Form beim gestarteten Programm unscharf aus.
Ich habe mir bereits einige Threads angesehen zu diesem Thema, denke jedoch, dass
irgendwie mein Code noch optimierung benötigt.
Kann mir da jemand was zu sagen?
Mein Code:
Ich habe eine Klassenbibliothek, in der ich mir gerade selbst ein paar Controls am erstellen bin. Soweit so gut.
In einer Windows-Forms Anwendung erbe ich die Controls aus der Klassenbibliothek (u.A. auch die Form).
Jetzt sieht im Designer alles wirklich super aus - wenn ich das Programm starte
jedoch nicht. Alles wirkt unscharf, schlecht gezeichnet. Selbst die "originalen" mit dem .Net Framework
mitgelieferten Controls sehen auf der Form beim gestarteten Programm unscharf aus.
Ich habe mir bereits einige Threads angesehen zu diesem Thema, denke jedoch, dass
irgendwie mein Code noch optimierung benötigt.
Kann mir da jemand was zu sagen?
Mein Code:
VB.NET-Quellcode
- Public Class SiriContainer : Inherits ContainerControl
- Private moveHeight As Integer = 38
- Private formCanMove As Boolean = False
- Private mouseX, mouseY As Integer
- Private overExit, overMin As Boolean
- Public Overrides Property Text() As String
- Get
- Return MyBase.Text
- End Get
- Set(value As String)
- MyBase.Text = value
- Invalidate()
- End Set
- End Property
- Sub New()
- SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or
- ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor Or ControlStyles.FixedHeight, True)
- MyBase.Update()
- Dock = DockStyle.Fill
- Font = New Font("Arial", 9, FontStyle.Bold)
- BackColor = Color.FromArgb(15, 15, 15)
- End Sub
- Protected Overrides Sub CreateHandle()
- MyBase.CreateHandle()
- FindForm.FormBorderStyle = FormBorderStyle.None
- If FindForm.TransparencyKey = Nothing Then FindForm.TransparencyKey = Color.Fuchsia
- End Sub
- Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
- MyBase.OnPaint(e)
- Dim G As Graphics = e.Graphics
- G.SmoothingMode = SmoothingMode.HighSpeed
- G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
- G.Clear(FindForm.TransparencyKey)
- Dim slope As Integer = 8
- Dim mainRect As New Rectangle(0, 0, Width - 1, Height - 1)
- Dim mainPath As GraphicsPath = DrawIt.RoundRect(mainRect, slope)
- G.FillPath(New SolidBrush(BackColor), mainPath)
- G.DrawPath(New Pen(Color.FromArgb(30, 35, 45)), mainPath)
- G.FillPath(New SolidBrush(Color.FromArgb(30, 30, 40)), DrawIt.RoundRect(New Rectangle(0, 0, Width - 1, moveHeight - slope), slope))
- G.FillRectangle(New SolidBrush(Color.FromArgb(30, 30, 40)), New Rectangle(0, moveHeight - (slope * 2), Width - 1, slope * 2))
- G.DrawLine(New Pen(Color.FromArgb(60, 60, 60)), New Point(1, moveHeight), New Point(Width - 2, moveHeight))
- G.SmoothingMode = SmoothingMode.HighQuality
- Dim textX As Integer = 6
- Dim textY As Integer = CInt((moveHeight / 2) - (G.MeasureString(Text, Font).Height / 2) + 1)
- Dim textSize As SizeF = G.MeasureString(Text, Font)
- Dim textRect As New Rectangle(textX, textY, CInt(textSize.Width), CInt(textSize.Height))
- Dim textBrush As New LinearGradientBrush(textRect, Color.FromArgb(185, 190, 195), Color.FromArgb(125, 125, 125), 90.0F)
- G.DrawString(Text, Font, textBrush, New Point(textX, textY))
- If overExit Then
- G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(253, 96, 96)), New Point(Width - 27, 11))
- Else
- G.DrawString("r", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 27, 11))
- End If
- If overMin Then
- G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(25, 100, 140)), New Point(Width - 47, 10))
- Else
- G.DrawString("0", New Font("Marlett", 12, FontStyle.Bold), New SolidBrush(Color.FromArgb(205, 210, 215)), New Point(Width - 47, 10))
- End If
- End Sub
- Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseMove(e)
- If formCanMove Then
- FindForm.Location = New Point(MousePosition.X - mouseX, MousePosition.Y - mouseY)
- End If
- overExit = (e.Y > 11 AndAlso e.Y < 24) AndAlso (e.X > Width - 23 AndAlso e.X < Width - 10)
- overMin = (e.Y > 11 AndAlso e.Y < 24) AndAlso (e.X > Width - 44 AndAlso e.X < Width - 31)
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseDown(e)
- mouseX = e.X
- mouseY = e.Y
- If e.Y <= moveHeight AndAlso overExit = False AndAlso overMin = False Then formCanMove = True
- If overExit Then
- FindForm.Close()
- ElseIf overMin Then
- FindForm.WindowState = FormWindowState.Minimized
- overExit = False
- overMin = False
- Else
- Focus()
- End If
- Invalidate()
- End Sub
- Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseUp(e)
- formCanMove = False
- End Sub
- End Class