Meine Controls (Source)

    • VB.NET

    Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von ExtremProgrammierer.

      Meine Controls (Source)

      Hallööle..
      Ich arbeite seit 2-3 tagen an ein paar kleinen Controls..
      (Das standarddesign ist blau, aber man kann alle farben ändern - per propertys)

      #Edit
      Jetzt mit Option Strict On!

      Button.vb
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Option Strict On
      2. Imports System.ComponentModel
      3. Public Enum MouseState As Byte
      4. None
      5. Hover
      6. Pressed
      7. End Enum
      8. Public Class Button
      9. Inherits System.Windows.Forms.Button
      10. Private _Color1 As System.Drawing.Color
      11. <Category("Button")> _
      12. Public Property Color1 As System.Drawing.Color
      13. Get
      14. Return Me._Color1
      15. End Get
      16. Set(ByVal value As System.Drawing.Color)
      17. Me._Color1 = value
      18. Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
      19. Me.Invalidate()
      20. End Set
      21. End Property
      22. Private _Color2 As System.Drawing.Color
      23. <Category("Button")> _
      24. Public Property Color2 As System.Drawing.Color
      25. Get
      26. Return Me._Color2
      27. End Get
      28. Set(ByVal value As System.Drawing.Color)
      29. Me._Color2 = value
      30. Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
      31. Me.Invalidate()
      32. End Set
      33. End Property
      34. Private _Color1H As System.Drawing.Color
      35. Private _Color2H As System.Drawing.Color
      36. Private _MouseState As MouseState
      37. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
      38. MyBase.OnMouseEnter(e)
      39. Me._MouseState = MouseState.Hover
      40. Me.Invalidate()
      41. End Sub
      42. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
      43. MyBase.OnMouseEnter(e)
      44. Me._MouseState = MouseState.None
      45. Me.Invalidate()
      46. End Sub
      47. Protected Overrides Sub OnMouseDown(ByVal mevent As System.Windows.Forms.MouseEventArgs)
      48. MyBase.OnMouseDown(mevent)
      49. Me._MouseState = MouseState.Pressed
      50. Me.Invalidate()
      51. End Sub
      52. Protected Overrides Sub OnMouseUp(ByVal mevent As System.Windows.Forms.MouseEventArgs)
      53. MyBase.OnMouseUp(mevent)
      54. Me._MouseState = MouseState.Hover
      55. Me.Invalidate()
      56. End Sub
      57. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      58. MyBase.OnPaint(e)
      59. e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
      60. Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
      61. If Me._MouseState = MouseState.None Then
      62. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), globalRect)
      63. ElseIf Me._MouseState = MouseState.Hover Then
      64. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1H, Me._Color2H), globalRect)
      65. ElseIf Me._MouseState = MouseState.Pressed Then
      66. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color2H, Me._Color1H), globalRect)
      67. End If
      68. e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), globalRect)
      69. Dim TextSize As Drawing.SizeF = e.Graphics.MeasureString(Me.Text, Me.Font, Me.Width)
      70. e.Graphics.DrawString(Me.Text, Me.Font, New Drawing.SolidBrush(Me.ForeColor), New Drawing.Point(CInt(Me.Width / 2) - CInt(TextSize.Width / 2), CInt(Me.Height / 2) - CInt(TextSize.Height / 2)))
      71. e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
      72. End Sub
      73. Sub New()
      74. Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
      75. Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
      76. Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
      77. Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
      78. Me.Size = New System.Drawing.Size(100, 25)
      79. Me._MouseState = MouseState.None
      80. Me.Cursor = Windows.Forms.Cursors.Hand
      81. End Sub
      82. End Class


      InfoButton.vb
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Option Strict On
      2. Imports System.ComponentModel
      3. Public Class InfoButton
      4. Inherits System.Windows.Forms.Button
      5. Private _Color1 As System.Drawing.Color
      6. <Category("Button")> _
      7. Public Property Color1 As System.Drawing.Color
      8. Get
      9. Return Me._Color1
      10. End Get
      11. Set(ByVal value As System.Drawing.Color)
      12. Me._Color1 = value
      13. Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
      14. Me.Invalidate()
      15. End Set
      16. End Property
      17. Private _Color2 As System.Drawing.Color
      18. <Category("Button")> _
      19. Public Property Color2 As System.Drawing.Color
      20. Get
      21. Return Me._Color2
      22. End Get
      23. Set(ByVal value As System.Drawing.Color)
      24. Me._Color2 = value
      25. Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
      26. Me.Invalidate()
      27. End Set
      28. End Property
      29. Private _TextInfo As String
      30. <Category("Darstellung")> _
      31. Public Property TextInfo As String
      32. Get
      33. Return Me._TextInfo
      34. End Get
      35. Set(value As String)
      36. Me._TextInfo = value
      37. Me.Invalidate()
      38. End Set
      39. End Property
      40. Private _InfoTextFont As Drawing.Font
      41. <Category("Button")> _
      42. Public Property InfoTextFont As Drawing.Font
      43. Get
      44. Return Me._InfoTextFont
      45. End Get
      46. Set(value As Drawing.Font)
      47. Me._InfoTextFont = value
      48. Me.Invalidate()
      49. End Set
      50. End Property
      51. Private _InfoTextColor As Drawing.Color
      52. <Category("Button")> _
      53. Public Property InfoTextColor As Drawing.Color
      54. Get
      55. Return Me._InfoTextColor
      56. End Get
      57. Set(value As Drawing.Color)
      58. Me._InfoTextColor = value
      59. Me.Invalidate()
      60. End Set
      61. End Property
      62. Private _Color1H As System.Drawing.Color
      63. Private _Color2H As System.Drawing.Color
      64. Private _MouseState As MouseState
      65. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
      66. MyBase.OnMouseEnter(e)
      67. Me._MouseState = MouseState.Hover
      68. Me.Invalidate()
      69. End Sub
      70. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
      71. MyBase.OnMouseEnter(e)
      72. Me._MouseState = MouseState.None
      73. Me.Invalidate()
      74. End Sub
      75. Protected Overrides Sub OnMouseDown(ByVal mevent As System.Windows.Forms.MouseEventArgs)
      76. MyBase.OnMouseDown(mevent)
      77. Me._MouseState = MouseState.Pressed
      78. Me.Invalidate()
      79. End Sub
      80. Protected Overrides Sub OnMouseUp(ByVal mevent As System.Windows.Forms.MouseEventArgs)
      81. MyBase.OnMouseUp(mevent)
      82. Me._MouseState = MouseState.Hover
      83. Me.Invalidate()
      84. End Sub
      85. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      86. MyBase.OnPaint(e)
      87. e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
      88. Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
      89. If Me._MouseState = MouseState.None Then
      90. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), globalRect)
      91. ElseIf Me._MouseState = MouseState.Hover Then
      92. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1H, Me._Color2H), globalRect)
      93. ElseIf Me._MouseState = MouseState.Pressed Then
      94. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color2H, Me._Color1H), globalRect)
      95. End If
      96. e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), globalRect)
      97. Dim TextSize As Drawing.SizeF = e.Graphics.MeasureString(Me.Text, Me.Font, Me.Width)
      98. e.Graphics.DrawString(Me.Text, Me.Font, New Drawing.SolidBrush(Me.ForeColor), New Drawing.Point(5, 5))
      99. e.Graphics.DrawString(Me._TextInfo, Me._InfoTextFont, New Drawing.SolidBrush(Me._InfoTextColor), New Drawing.Point(10, CInt(TextSize.Height + 5)))
      100. e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
      101. End Sub
      102. Sub New()
      103. Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
      104. Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
      105. Me._Color1H = System.Drawing.Color.FromArgb(Me._Color1.A, CInt(Me._Color1.R * 0.9), CInt(Me._Color1.G * 0.9), CInt(Me._Color1.B * 0.9))
      106. Me._Color2H = System.Drawing.Color.FromArgb(Me._Color2.A, CInt(Me._Color2.R * 0.9), CInt(Me._Color2.G * 0.9), CInt(Me._Color2.B * 0.9))
      107. Me.Size = New System.Drawing.Size(125, 40)
      108. Me._MouseState = MouseState.None
      109. Me.Cursor = Windows.Forms.Cursors.Hand
      110. Me._InfoTextColor = Drawing.Color.FromArgb(25, 25, 25)
      111. Me._TextInfo = "Information..."
      112. Me._InfoTextFont = New Drawing.Font(Me.Font.FontFamily, 7)
      113. End Sub
      114. End Class


      ProgressBar.vb
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Option Strict On
      2. Imports System.ComponentModel
      3. Public Class ProgressBar
      4. Inherits System.Windows.Forms.Control
      5. Private _Color1 As System.Drawing.Color
      6. <Category("Progressbar")> _
      7. Public Property Color1 As System.Drawing.Color
      8. Get
      9. Return Me._Color1
      10. End Get
      11. Set(ByVal value As System.Drawing.Color)
      12. Me._Color1 = value
      13. Me.Invalidate()
      14. End Set
      15. End Property
      16. Private _Color2 As System.Drawing.Color
      17. <Category("Progressbar")> _
      18. Public Property Color2 As System.Drawing.Color
      19. Get
      20. Return Me._Color2
      21. End Get
      22. Set(ByVal value As System.Drawing.Color)
      23. Me._Color2 = value
      24. Me.Invalidate()
      25. End Set
      26. End Property
      27. Private _Minimum As UInteger
      28. <Category("Progressbar")> _
      29. Public Property Minimum As UInteger
      30. Get
      31. Return Me._Minimum
      32. End Get
      33. Set(ByVal value As UInteger)
      34. If value > Me._Maximum Then Throw New Exception("Minimum value cant be greater than maximum value")
      35. Me._Minimum = value
      36. End Set
      37. End Property
      38. Private _Maximum As UInteger
      39. <Category("Progressbar")> _
      40. Public Property Maximum As UInteger
      41. Get
      42. Return Me._Maximum
      43. End Get
      44. Set(ByVal value As UInteger)
      45. If value < Me._Minimum Then Throw New Exception("Maximum value cant be less than minimum value")
      46. Me._Maximum = value
      47. End Set
      48. End Property
      49. Private _Value As UInteger
      50. <Category("Progressbar")> _
      51. Public Property Value As UInteger
      52. Get
      53. Return Me._Value
      54. End Get
      55. Set(ByVal value As UInteger)
      56. If value < Me._Minimum OrElse value > Me._Maximum Then Throw New Exception("Value must be beteween minimum and maximum value")
      57. Me._Value = value
      58. End Set
      59. End Property
      60. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      61. MyBase.OnPaint(e)
      62. e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
      63. Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
      64. Dim valueRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, (CInt((Me.Width) * Me._Value / Me._Maximum)), Me.Height - 1), 8)
      65. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Drawing.Color.FromArgb(255, 189, 189, 189), Drawing.Color.FromArgb(255, 219, 219, 219)), globalRect)
      66. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), valueRect)
      67. e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), valueRect)
      68. e.Graphics.DrawPath(Drawing.Pens.LightSlateGray, valueRect)
      69. e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
      70. End Sub
      71. Sub New()
      72. Me._Minimum = 0
      73. Me._Maximum = 100
      74. Me._Value = 50
      75. Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
      76. Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
      77. Me.Size = New System.Drawing.Size(200, 10)
      78. Me.Text = ""
      79. End Sub
      80. End Class


      Part 2 kommt demnächst!:)

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „BeefyX“ ()

      ProgressBarRound.vb
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Option Strict On
      2. Imports System.ComponentModel
      3. Public Class ProgressBarRound
      4. Inherits System.Windows.Forms.Control
      5. Private _Color1 As System.Drawing.Color
      6. <Category("Progressbar")> _
      7. Public Property Color1 As System.Drawing.Color
      8. Get
      9. Return Me._Color1
      10. End Get
      11. Set(ByVal value As System.Drawing.Color)
      12. Me._Color1 = value
      13. Me.Invalidate()
      14. End Set
      15. End Property
      16. Private _Color2 As System.Drawing.Color
      17. <Category("Progressbar")> _
      18. Public Property Color2 As System.Drawing.Color
      19. Get
      20. Return Me._Color2
      21. End Get
      22. Set(ByVal value As System.Drawing.Color)
      23. Me._Color2 = value
      24. Me.Invalidate()
      25. End Set
      26. End Property
      27. Private _Minimum As UInteger
      28. <Category("Progressbar")> _
      29. Public Property Minimum As UInteger
      30. Get
      31. Return Me._Minimum
      32. End Get
      33. Set(ByVal value As UInteger)
      34. If value > Me._Maximum Then Throw New Exception("Minimum value cant be greater than maximum value")
      35. Me._Minimum = value
      36. Me.Invalidate()
      37. End Set
      38. End Property
      39. Private _Maximum As UInteger
      40. <Category("Progressbar")> _
      41. Public Property Maximum As UInteger
      42. Get
      43. Return Me._Maximum
      44. End Get
      45. Set(ByVal value As UInteger)
      46. If value < Me._Minimum Then Throw New Exception("Maximum value cant be less than minimum value")
      47. Me._Maximum = value
      48. Me.Invalidate()
      49. End Set
      50. End Property
      51. Private _Value As UInteger
      52. <Category("Progressbar")> _
      53. Public Property Value As UInteger
      54. Get
      55. Return Me._Value
      56. End Get
      57. Set(ByVal value As UInteger)
      58. If value < Me._Minimum OrElse value > Me._Maximum Then Throw New Exception("Value must be beteween minimum and maximum value")
      59. Me._Value = value
      60. Me.Invalidate()
      61. End Set
      62. End Property
      63. Private _RoundedWidth As Integer
      64. <Category("Progressbar")> _
      65. Public Property RoundedWidth As Integer
      66. Get
      67. Return Me._RoundedWidth
      68. End Get
      69. Set(ByVal value As Integer)
      70. Me._RoundedWidth = Value
      71. CheckWidth()
      72. Me.Invalidate()
      73. End Set
      74. End Property
      75. Protected Sub CheckWidth()
      76. If Me._RoundedWidth > Me.Width / 2 Then Me._RoundedWidth = CInt(Me.Width / 2) - 1
      77. End Sub
      78. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      79. MyBase.OnPaint(e)
      80. Try
      81. e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
      82. Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 8)
      83. Dim myPath As New Drawing.Drawing2D.GraphicsPath()
      84. Dim winkel As Single = CSng(360 * Me._Value / Me._Maximum)
      85. myPath.AddArc(New Drawing.Rectangle(0, 0, Me.Width - 1, Me.Height - 1), 270, winkel)
      86. myPath.Reverse()
      87. Dim innerRect As New Drawing.Rectangle(_RoundedWidth, _RoundedWidth, Me.Width - (_RoundedWidth * 2) - 1, Me.Height - (_RoundedWidth * 2) - 1)
      88. myPath.AddArc(innerRect, 270, winkel)
      89. myPath.Reverse()
      90. myPath.CloseFigure()
      91. Dim pathGradient As New Drawing.Drawing2D.PathGradientBrush(myPath)
      92. pathGradient.CenterColor = Me._Color1
      93. pathGradient.SurroundColors = New Drawing.Color() {Me._Color2}
      94. e.Graphics.FillPath(pathGradient, myPath)
      95. e.Graphics.FillPath(New System.Drawing.Drawing2D.HatchBrush(Drawing.Drawing2D.HatchStyle.WideUpwardDiagonal, System.Drawing.Color.FromArgb(&H0), System.Drawing.Color.FromArgb(&HF000000)), myPath)
      96. e.Graphics.DrawPath(New Drawing.Pen(Drawing.Color.FromArgb(75, 75, 75)), myPath)
      97. Catch ex As Exception
      98. e.Graphics.DrawString("ERROR", New Drawing.Font("Arial", 12), Drawing.Brushes.Black, New Drawing.Point(5, 5))
      99. End Try
      100. End Sub
      101. Sub New()
      102. Me._Minimum = 0
      103. Me._Maximum = 100
      104. Me._Value = 50
      105. Me._RoundedWidth = 15
      106. Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
      107. Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
      108. Me.MinimumSize = New Drawing.Size(CInt(Me.Width / 2), CInt(Me.Height / 2))
      109. Me.Size = New System.Drawing.Size(100, 100)
      110. Me.Text = ""
      111. End Sub
      112. End Class


      Slider.vb
      (Noch in Arbeit!)
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Option Strict On
      2. Imports System.ComponentModel
      3. Public Class Slider
      4. Inherits System.Windows.Forms.Control
      5. Protected ReadOnly Property PointRect As System.Drawing.Rectangle
      6. Get
      7. Dim myPoint As New System.Drawing.Point((CInt(Me.Width * Me._Value / Me._Maximum)) - 12, 3)
      8. Dim myRect As New System.Drawing.Rectangle(myPoint, New System.Drawing.Size(13, 13))
      9. Return myRect
      10. End Get
      11. End Property
      12. Private _Color1 As System.Drawing.Color
      13. <Category("Progressbar")> _
      14. Public Property Color1 As System.Drawing.Color
      15. Get
      16. Return Me._Color1
      17. End Get
      18. Set(ByVal value As System.Drawing.Color)
      19. Me._Color1 = value
      20. Me.Invalidate()
      21. End Set
      22. End Property
      23. Private _Color2 As System.Drawing.Color
      24. <Category("Progressbar")> _
      25. Public Property Color2 As System.Drawing.Color
      26. Get
      27. Return Me._Color2
      28. End Get
      29. Set(ByVal value As System.Drawing.Color)
      30. Me._Color2 = value
      31. Me.Invalidate()
      32. End Set
      33. End Property
      34. Private _Minimum As UInteger
      35. <Category("Progressbar")> _
      36. Public Property Minimum As UInteger
      37. Get
      38. Return Me._Minimum
      39. End Get
      40. Set(ByVal value As UInteger)
      41. If value > Me._Maximum Then Throw New Exception("Minimum value cant be greater than maximum value")
      42. Me._Minimum = value
      43. End Set
      44. End Property
      45. Private _Maximum As UInteger
      46. <Category("Progressbar")> _
      47. Public Property Maximum As UInteger
      48. Get
      49. Return Me._Maximum
      50. End Get
      51. Set(ByVal value As UInteger)
      52. If value < Me._Minimum Then Throw New Exception("Maximum value cant be less than minimum value")
      53. Me._Maximum = value
      54. End Set
      55. End Property
      56. Private _Value As UInteger
      57. <Category("Progressbar")> _
      58. Public Property Value As UInteger
      59. Get
      60. Return Me._Value
      61. End Get
      62. Set(ByVal value As UInteger)
      63. If value < Me._Minimum OrElse value > Me._Maximum Then Throw New Exception("Value must be beteween minimum and maximum value")
      64. Me._Value = value
      65. End Set
      66. End Property
      67. Private _SlidingX As Integer
      68. Private _IsSliding As Boolean
      69. Public ReadOnly Property IsSliding As Boolean
      70. Get
      71. Return Me._IsSliding
      72. End Get
      73. End Property
      74. Protected Sub UpdateValue(ByVal v As Integer)
      75. If v >= Me._Minimum AndAlso v <= Me._Maximum Then
      76. Me._Value = CUInt(v) ' / Me._Maximum * Me.Width
      77. Me.Invalidate()
      78. End If
      79. End Sub
      80. Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
      81. MyBase.OnMouseDown(e)
      82. If Me.PointRect().Contains(e.Location) Then
      83. Me._IsSliding = True
      84. Me._SlidingX = e.X - Me.PointRect.Width
      85. UpdateValue(Me._SlidingX)
      86. End If
      87. End Sub
      88. Protected Overrides Sub OnMouseUp(e As System.Windows.Forms.MouseEventArgs)
      89. MyBase.OnMouseUp(e)
      90. Me._IsSliding = False
      91. End Sub
      92. Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)
      93. MyBase.OnMouseMove(e)
      94. If Me._IsSliding Then
      95. Dim truePosition As Integer = e.X - Me._SlidingX
      96. UpdateValue(truePosition)
      97. End If
      98. End Sub
      99. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      100. MyBase.OnPaint(e)
      101. e.Graphics.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
      102. Dim globalRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(5, 5, Me.Width - 11, Me.Height - 11), 8)
      103. Dim valueRect As System.Drawing.Drawing2D.GraphicsPath = GraphicsHelper.DrawRoundedRectangle(New System.Drawing.Rectangle(5, 5, (CInt(Me.Width * Me._Value / Me._Maximum)), Me.Height - 11), 8)
      104. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Drawing.Color.FromArgb(255, 189, 189, 189), Drawing.Color.FromArgb(255, 219, 219, 219)), globalRect)
      105. e.Graphics.FillPath(New System.Drawing.Drawing2D.LinearGradientBrush(New System.Drawing.Point(0, 0), New System.Drawing.Point(0, Me.Height - 1), Me._Color1, Me._Color2), valueRect)
      106. e.Graphics.DrawPath(Drawing.Pens.LightSlateGray, valueRect)
      107. e.Graphics.DrawPath(Drawing.Pens.DimGray, globalRect)
      108. Dim myPoint As System.Drawing.Point = Me.PointRect().Location
      109. e.Graphics.FillEllipse(New System.Drawing.Drawing2D.LinearGradientBrush(myPoint, New System.Drawing.Point(myPoint.X + 13, 13), Drawing.Color.Gray, Drawing.Color.LightGray), Me.PointRect())
      110. e.Graphics.DrawEllipse(Drawing.Pens.DimGray, Me.PointRect())
      111. End Sub
      112. Sub New()
      113. Me._Minimum = 0
      114. Me._Maximum = 100
      115. Me._Value = 50
      116. Me._Color1 = Drawing.Color.FromArgb(255, 45, 142, 232)
      117. Me._Color2 = Drawing.Color.FromArgb(255, 39, 123, 204)
      118. Me.Size = New System.Drawing.Size(200, 20)
      119. Me.Text = ""
      120. End Sub
      121. End Class


      Und zu guter letzt das Modul für die DrawRoundRectangle Funktion (sollte eigentlich anders heißen)
      GraphicsHelper.vb
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Public Class GraphicsHelper
      2. Public Shared Function DrawRoundedRectangle(ByVal Rect As System.Drawing.Rectangle, ByVal Radius As Single) As System.Drawing.Drawing2D.GraphicsPath
      3. Dim retPath As New System.Drawing.Drawing2D.GraphicsPath()
      4. 'Dim g As Graphics
      5. Dim BaseRect As New System.Drawing.RectangleF(Rect.X, Rect.Y, Rect.Width,
      6. Rect.Height)
      7. Dim ArcRect As New System.Drawing.RectangleF(BaseRect.Location,
      8. New System.Drawing.SizeF(Radius, Radius))
      9. 'top left Arc
      10. retPath.AddArc(ArcRect, 180, 90)
      11. retPath.AddLine(Rect.X + CInt(Radius / 2),
      12. Rect.Y,
      13. Rect.X + Rect.Width - CInt(Radius / 2),
      14. Rect.Y)
      15. ' top right arc
      16. ArcRect.X = BaseRect.Right - Radius
      17. retPath.AddArc(ArcRect, 270, 90)
      18. retPath.AddLine(Rect.X + Rect.Width,
      19. Rect.Y + CInt(Radius / 2),
      20. Rect.X + Rect.Width,
      21. Rect.Y + Rect.Height - CInt(Radius / 2))
      22. ' bottom right arc
      23. ArcRect.Y = BaseRect.Bottom - Radius
      24. retPath.AddArc(ArcRect, 0, 90)
      25. retPath.AddLine(Rect.X + CInt(Radius / 2),
      26. Rect.Y + Rect.Height,
      27. Rect.X + Rect.Width - CInt(Radius / 2),
      28. Rect.Y + Rect.Height)
      29. ' bottom left arc
      30. ArcRect.X = BaseRect.Left
      31. retPath.AddArc(ArcRect, 90, 90)
      32. retPath.AddLine(Rect.X, Rect.Y + CInt(Radius / 2),
      33. Rect.X,
      34. Rect.Y + Rect.Height - CInt(Radius / 2))
      35. Return retPath
      36. End Function
      37. End Class


      Viel Spaß! :)

      #Edit
      Hier ein Screenshot

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „BeefyX“ ()

      //Edit: -.-
      "Life isn't about winning the race. Life is about finishing the race and how many people we can help finish the race." ~Marc Mero

      Nun bin ich also auch soweit: Keine VB-Fragen per PM! Es gibt hier ein Forum, verdammt!

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Nikx“ ()

      Grade selbst gemerkt, dass ich den letzten Scheiss geschrieben hab.
      Hatte nen anderes Event im Kopf mit dem sich hier mal jemand nen super Projekt
      versaut hat. Ich gehs gleich mal raussuchen.

      Oh Man, Grüße
      "Life isn't about winning the race. Life is about finishing the race and how many people we can help finish the race." ~Marc Mero

      Nun bin ich also auch soweit: Keine VB-Fragen per PM! Es gibt hier ein Forum, verdammt!