Hallo.
Ich habe ein Problem und zwar verschwindet das Control,
wenn die Maus nicht in der nähe bzw. auf dem Control ist.
Code (nicht von mir):
Kann mir jemand sagen, woran das liegt?
Ich habe ein Problem und zwar verschwindet das Control,
wenn die Maus nicht in der nähe bzw. auf dem Control ist.
Code (nicht von mir):
VB.NET-Quellcode
- Public Class Test : Inherits TrackBar
- Public Enum Stater As Short
- normal = 0
- press = 1
- hover = 2
- End Enum
- Public stat As Stater = stater.normal
- Public Sub New()
- MyBase.New()
- MyBase.SetStyle(ControlStyles.DoubleBuffer, True)
- MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
- SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
- UpdateStyles()
- End Sub
- Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
- MyBase.OnPaintBackground(pevent)
- End Sub
- Protected Overrides ReadOnly Property CreateParams() As CreateParams
- Get
- Dim cp As CreateParams = MyBase.CreateParams
- cp.ExStyle = cp.ExStyle Or &H20
- 'WS_EX_TRANSPARENT
- Return cp
- End Get
- End Property
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- MyBase.OnPaint(e)
- MyBase.OnPaintBackground(e)
- With (e.Graphics)
- .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
- .PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
- .InterpolationMode = Drawing2D.InterpolationMode.HighQualityBilinear
- .CompositingQuality = Drawing2D.CompositingQuality.HighQuality
- e.Graphics.DrawLine(New Pen(New SolidBrush(NonValueLine), 3), New Point(0 + 12, CInt(Height / 2)), New Point(Width - 12, CInt(Height / 2)))
- Dim spektrum As Integer = Maximum - Minimum
- spectre = spektrum
- Dim pixel As Double = (((Math.Abs(Minimum) + Value) / spektrum) * (Width - 24)) + 12
- Dim CurrSi As Integer = CInt(Me.Height / 2)
- Dim größe As New Rectangle(CInt(pixel - 12), CurrSi - 12, 24, 24)
- Dim größe1 As New Rectangle(CInt(pixel - 5), CurrSi - 5, 10, 10)
- where = größe
- If stat = Stater.normal Then
- e.Graphics.FillEllipse(New SolidBrush(OutherCircleColor), größe)
- e.Graphics.FillEllipse(New SolidBrush(LineColor), größe1)
- e.Graphics.DrawLine(New Pen(New SolidBrush(LineColor), 3), New Point(0 + 12, CInt(Height / 2)), New Point(CInt(pixel), CInt(Height / 2)))
- ElseIf stat = Stater.hover Then
- e.Graphics.FillEllipse(New SolidBrush(Dark_Color(OutherCircleColor, 0.75)), größe)
- e.Graphics.FillEllipse(New SolidBrush(LineColor), größe1)
- e.Graphics.DrawLine(New Pen(New SolidBrush(LineColor), 3), New Point(0 + 12, CInt(Height / 2)), New Point(CInt(pixel), CInt(Height / 2)))
- End If
- End With
- e.Graphics.DrawString(MyBase.Value.ToString, New Font("Segoe UI", CSng(7)), Brushes.Black, New Point(20, 24))
- End Sub
- Dim where As Rectangle
- Dim drin As Boolean
- Dim x, y As Integer
- Dim spectre As Integer
- Private Sub DroidTrackbar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
- If x > where.X AndAlso x < (where.Width + where.X) Then
- If y > where.Y AndAlso y < (where.Height + where.Y) Then
- drin = True
- stat = Stater.normal
- End If
- End If
- End Sub
- Private Sub DroidTrackbar_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
- Try
- x = e.X
- y = e.Y
- If drin Then
- where.X = e.X
- Value = CInt((((e.X) / (Width)) * spectre) - Math.Abs(Minimum))
- If Value > Maximum Then Value = Maximum
- If Value < Minimum Then Value = Minimum
- Else
- If x > where.X AndAlso x < (where.Width + where.X) Then
- If y > where.Y AndAlso y < (where.Height + where.Y) Then
- stat = Stater.hover
- Else : stat = Stater.normal
- End If
- Else : stat = Stater.normal
- End If
- End If
- Me.Invalidate()
- Catch ex As Exception
- End Try
- End Sub
- Private Function Dark_Color(ByVal Col As Color, ByVal percent As Double) As Color
- If (percent = 0.5) Then
- Return Col
- ElseIf (percent > 0.5) Then
- Return Color.FromArgb(Col.A, CInt((255 - Col.R) * ((percent - 0.5) * 2) + Col.R), CInt((255 - Col.G) * ((percent - 0.5) * 2) + Col.G), CInt((255 - Col.B) * ((percent - 0.5) * 2) + Col.B))
- Else
- Return Color.FromArgb(Col.A, CInt(Col.R * percent * 2), CInt(Col.G * percent * 2), CInt(Col.B * percent * 2))
- End If
- End Function
- Private Sub DroidTrackbar_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
- drin = False
- End Sub
- Dim lin As Color = Color.FromArgb(70, 151, 196)
- Public Property LineColor As Color
- Get
- Return lin
- End Get
- Set(ByVal value As Color)
- lin = value
- End Set
- End Property
- Dim out As Color = Color.FromArgb(119, 206, 234)
- Public Property OutherCircleColor As Color
- Get
- Return out
- End Get
- Set(ByVal value As Color)
- out = value
- End Set
- End Property
- Dim non As Color = Color.FromArgb(229, 229, 229)
- Public Property NonValueLine As Color
- Get
- Return non
- End Get
- Set(ByVal value As Color)
- non = value
- End Set
- End Property
- Private Sub DroidTrackbar_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Scroll
- Invalidate()
- End Sub
- End Class
Kann mir jemand sagen, woran das liegt?