Steuerelemente und Komponenten

  • Allgemein

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von faxe1008.

    Steuerelemente und Komponenten

    Hi Leute,

    kleine Frage.

    Gibt es eine Möglichkeit, meiner Form ein bestimmtes "Layout" zu hinterlegen?
    Gibt es Steuerelemente und oder auch Komponenten die man sich irgendwo beziehen kann,
    um mal etwas vom Standard abzuweichen?

    ...ich hoffe ihr versteht meine Frage.
    (Zum Beispiel möchte ich nicht das Standard TabControl nehmen, sondern etwas modifiziertes, wenn so etwas vorhanden ist)

    Grüße
    Confuzi Us

    Was hat das mit einem Tutorial zu tun? Lies die Boardbeschreibung bevor du postest. Verschoben. ~fufu

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

    Du kannst eine Form oder ein Projekt designen und als Vorlage für neue Formen und Projekte speichern.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Du kannst dir diverse WPF-Themes bzw. Layouts ansehen oder Windows Forms Controls wie:
    [Release] MetroSuite [UPDATE 02.06.2013]- Holt euch den modernen Windows 8 Style.
    Mfg: Gather
    Private Nachrichten bezüglich VB-Fragen werden Ignoriert!


    Spoiler anzeigen

    VB.NET-Quellcode

    1. Option Strict Off
    2. Imports System.Drawing.Drawing2D
    3. Imports System.Drawing.Imaging
    4. Imports System.Windows.Forms
    5. Imports System.Drawing
    6. Namespace UI
    7. Public Class SideTab
    8. Inherits TabControl
    9. Private State As New MouseState
    10. Private Structure MouseState
    11. Dim Hover As Boolean
    12. Dim Coordinates As Point
    13. End Structure
    14. #Region "Constructor"
    15. Sub New()
    16. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
    17. DoubleBuffered = True
    18. SizeMode = TabSizeMode.Fixed
    19. ItemSize = New Size(44, 136)
    20. End Sub
    21. #End Region
    22. #Region "Properties"
    23. Private _InactiveIconOpacity As Integer = 50
    24. Public Property InactiveIconOpacity As Integer
    25. Get
    26. Return _InactiveIconOpacity
    27. End Get
    28. Set(ByVal value As Integer)
    29. If IsNothing(value) Then value = 50
    30. If value < 0 Then value = 0
    31. If value > 100 Then value = 100
    32. _InactiveIconOpacity = value
    33. End Set
    34. End Property
    35. #End Region
    36. #Region "Methods"
    37. Private Function ToPen(ByVal color As Color) As Pen
    38. Return New Pen(color)
    39. End Function
    40. Private Function ToBrush(ByVal color As Color) As Brush
    41. Return New SolidBrush(color)
    42. End Function
    43. Private Function ImageOpacity(ByVal Image As Bitmap, ByVal Opacity As Single) As Image
    44. Dim Result As New Bitmap(Image.Width, Image.Height, Imaging.PixelFormat.Format32bppArgb)
    45. With Image
    46. Opacity = System.Math.Min(Opacity, 100)
    47. Using Attributes As New Imaging.ImageAttributes
    48. Dim Matrix As New Imaging.ColorMatrix
    49. Matrix.Matrix33 = Opacity / 100.0F
    50. Attributes.SetColorMatrix(Matrix)
    51. Dim Points() As PointF = {New Point(0, 0), New Point(.Width, 0), New Point(0, .Height)}
    52. Using g As Graphics = Graphics.FromImage(Result)
    53. g.Clear(Color.Transparent)
    54. g.DrawImage(Image, Points, New RectangleF(Point.Empty, .Size), GraphicsUnit.Pixel, Attributes)
    55. End Using
    56. End Using
    57. End With
    58. Return Result
    59. End Function
    60. #End Region
    61. #Region "Override Methods"
    62. Protected Overrides Sub CreateHandle()
    63. MyBase.CreateHandle()
    64. MyBase.DoubleBuffered = True
    65. SizeMode = TabSizeMode.Fixed
    66. Alignment = TabAlignment.Left
    67. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
    68. End Sub
    69. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
    70. State.Hover = True
    71. MyBase.OnMouseHover(e)
    72. End Sub
    73. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
    74. State.Hover = False
    75. For Each t As TabPage In MyBase.TabPages
    76. If t.DisplayRectangle.Contains(State.Coordinates) Then
    77. MyBase.Invalidate()
    78. Exit For
    79. End If
    80. Next
    81. MyBase.OnMouseHover(e)
    82. End Sub
    83. Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
    84. State.Coordinates = e.Location
    85. For Each t As TabPage In MyBase.TabPages
    86. If t.DisplayRectangle.Contains(e.Location) Then
    87. MyBase.Invalidate()
    88. Exit For
    89. End If
    90. Next
    91. MyBase.OnMouseMove(e)
    92. End Sub
    93. Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    94. Dim B As New Bitmap(Width, Height)
    95. Dim G As Graphics = Graphics.FromImage(B)
    96. With G
    97. Try : SelectedTab.BackColor = Color.White : Catch : End Try
    98. .Clear(Color.White)
    99. .FillRectangle(New SolidBrush(Color.FromArgb(39, 39, 39)), New Rectangle(0, 0, ItemSize.Height + 4, Height)) ' Background
    100. .DrawLine(New Pen(Color.FromArgb(39, 39, 39)), New Point(ItemSize.Height + 3, 0), New Point(ItemSize.Height + 3, 999)) ' Background border
    101. For TabIndex As Integer = 0 To TabCount - 1
    102. If TabIndex = SelectedIndex Then
    103. ' Selected tab area
    104. Dim TabRect As Rectangle = New Rectangle(New Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 2), New Size(GetTabRect(TabIndex).Width + 3, GetTabRect(TabIndex).Height - 1))
    105. ' Background
    106. .FillRectangle(New SolidBrush(Color.FromArgb(28, 28, 28)), TabRect.X, TabRect.Y, TabRect.Width + 1, TabRect.Height + 3)
    107. ' Highlight
    108. If Not TabIndex = 0 Then .DrawLine(New Pen(Color.FromArgb(60, 60, 60)), New Point(TabRect.Location.X - 1, TabRect.Top + 1), New Point(TabRect.Width, TabRect.Top + 1))
    109. ' Selected marker
    110. Dim Selected As Rectangle = New Rectangle(New Point(GetTabRect(TabIndex).Width, GetTabRect(TabIndex).Location.Y - IIf(TabIndex = 0, 1, 0)), New Size(4, GetTabRect(TabIndex).Height - IIf(TabIndex = 0, 1, 2)))
    111. .FillRectangle(New SolidBrush(Color.Red), Selected)
    112. ' Icon & Text
    113. Dim SetIcon As Boolean = False
    114. Try
    115. If Not IsNothing(ImageList) Then
    116. Dim Index As Integer = TabPages(TabIndex).ImageIndex
    117. If Not Index = -1 Then
    118. ' Icon
    119. .DrawImage(ImageList.Images(TabPages(TabIndex).ImageIndex), New Point(TabRect.Location.X + 6, TabRect.Location.Y + 8))
    120. SetIcon = True
    121. End If
    122. End If
    123. Catch ex As Exception
    124. Finally
    125. ' Text
    126. .DrawString(IIf(SetIcon, IIf(TabPages(TabIndex).Text.Length >= 11, " ", String.Empty), String.Empty) & TabPages(TabIndex).Text, New Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.White, TabRect, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
    127. End Try
    128. Else
    129. ' Deselected tab area
    130. Dim TabRect As Rectangle = New Rectangle(New Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 2), New Size(GetTabRect(TabIndex).Width + 3, GetTabRect(TabIndex).Height + 1))
    131. If State.Hover AndAlso TabRect.Contains(State.Coordinates) Then
    132. ' Background
    133. .FillRectangle(New SolidBrush(Color.FromArgb(28, 28, 28)), TabRect.X, TabRect.Y, TabRect.Width + 1, TabRect.Height)
    134. Else
    135. ' Gradient
    136. Dim GradientInfo As New ColorBlend()
    137. With GradientInfo
    138. .Colors = {Color.FromArgb(51, 51, 51), Color.FromArgb(39, 39, 39), Color.FromArgb(37, 37, 37)}
    139. .Positions = {0.0F, 0.5F, 1.0F}
    140. End With
    141. Dim GradientArea As Rectangle = New Rectangle(New Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 1), New Size(GetTabRect(TabIndex).Width + 4, GetTabRect(TabIndex).Height))
    142. Dim Gradient As New LinearGradientBrush(GradientArea, Color.Black, Color.Black, 90.0F)
    143. Gradient.InterpolationColors = GradientInfo
    144. .FillRectangle(Gradient, GradientArea)
    145. End If
    146. ' Hightlight
    147. .DrawLine(New Pen(Color.FromArgb(60, 60, 60)), New Point(TabRect.Location.X - 1, TabRect.Top + 1), New Point(TabRect.Width, TabRect.Top + 1))
    148. ' Shadow
    149. .DrawLine(New Pen(Color.FromArgb(27, 27, 27)), New Point(TabRect.Location.X - 1, TabRect.Bottom - 1), New Point(TabRect.Location.X + TabRect.Right, TabRect.Bottom - 1))
    150. If State.Hover AndAlso TabRect.Contains(State.Coordinates) Then
    151. ' Hover marker
    152. Dim Hover As Rectangle = New Rectangle(New Point(GetTabRect(TabIndex).Width, GetTabRect(TabIndex).Location.Y), New Size(4, GetTabRect(TabIndex).Height - 2))
    153. .FillRectangle(New SolidBrush(Color.FromArgb(102, 102, 102)), Hover)
    154. End If
    155. ' Icon & Text
    156. Dim SetIcon As Boolean = False
    157. Try
    158. If Not IsNothing(ImageList) Then
    159. Dim Index As Integer = TabPages(TabIndex).ImageIndex
    160. If Not Index = -1 Then
    161. ' Icon
    162. .DrawImage(ImageOpacity(ImageList.Images(TabPages(TabIndex).ImageIndex), InactiveIconOpacity), New Point(TabRect.Location.X + 6, TabRect.Location.Y + 8))
    163. SetIcon = True
    164. End If
    165. End If
    166. Catch ex As Exception
    167. Finally
    168. ' Text
    169. .DrawString(IIf(SetIcon, IIf(TabPages(TabIndex).Text.Length >= 11, " ", String.Empty), String.Empty) & TabPages(TabIndex).Text, Font, ToBrush(Color.FromArgb(153, 153, 153)), TabRect, New StringFormat With {.LineAlignment = StringAlignment.Center, .Alignment = StringAlignment.Center})
    170. End Try
    171. End If
    172. Next
    173. e.Graphics.CompositingQuality = CompositingQuality.HighQuality
    174. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
    175. e.Graphics.SmoothingMode = SmoothingMode.HighQuality
    176. e.Graphics.DrawImage(B.Clone, 0, 0)
    177. .Dispose() : B.Dispose()
    178. End With
    179. End Sub
    180. #End Region
    181. End Class
    182. End Namespace


    Hier ein Tabcontrol. Ansehen, Verstehen, Anpassen, Option Strict on konform umarbeiten.

    8-) faxe1008 8-)