Benutzer mit den meisten Antworten
Auf TabItem ein Dreieck zeichnen

Frage
-
Hallo Leute,
in einem Datagridview kann ich mit nachfolgender Funktion ein Dreick-Flag, wie z. B. in Excel, zeichnen. Das klappt absolut einwandfrei.
Private Sub DataGridView1_CellPainting(sender As Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting If e.ColumnIndex = 0 AndAlso e.RowIndex >= 0 Then 'nur Spalte 1 If dicTasklist.ContainsKey(e.Value) = True Then Try e.PaintBackground(e.ClipBounds, True) Dim path As New System.Drawing.Drawing2D.GraphicsPath() path.AddLine(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.X + 9, e.CellBounds.Y) path.AddLine(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.X, e.CellBounds.Y + 9) path.AddLine(e.CellBounds.X, e.CellBounds.Y + 9, e.CellBounds.X + 9, e.CellBounds.Y) e.Graphics.FillPath(Brushes.Red, path) e.Paint(e.CellBounds, DataGridViewPaintParts.Border Or DataGridViewPaintParts.ContentForeground) e.Handled = True Finally End Try End If End If End Sub
Nun möchte ich im Grunde die gleiche Funktion für ein TabItem einrichten.
Ich habe aber leider überhaupt keine Vorstellung wie das geht.
Ich hoffe jemand kann mir hier einen Denkanstoß geben.
Vielen Dank im Voraus.
Gruß Ahmed
Antworten
-
Hi Ahmed,
ohne die weiteren Forderungen zu kennen, hier mal eine Demo, wie man das machen kann:Public Class Form15 Private WithEvents tc As New TabControl With {.Dock = DockStyle.Fill, .DrawMode = TabDrawMode.OwnerDrawFixed} Private Sub Form15_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Controls.Add(tc) For i = 1 To 5 tc.Controls.Add(New TabPage With {.Text = $"Reiter {i}", .Width = 70}) Next End Sub Private Sub tc_DrawItem(sender As Object, e As DrawItemEventArgs) Handles tc.DrawItem Dim tc = TryCast(sender, TabControl) If tc Is Nothing Then Exit Sub Dim gr = e.Graphics Dim left = e.Bounds.X Dim top = e.Bounds.Y Dim size = 12 Dim path As New System.Drawing.Drawing2D.GraphicsPath() path.AddLine(left + 1, top + 1, left + size, top + 1) path.AddLine(left + 1, top + 1, left + 1, top + size) path.AddLine(left + 1, top + size, left + size, top + 1) gr.FillPath(Brushes.Red, path) gr.DrawString(tc.TabPages(e.Index).Text, tc.TabPages(e.Index).Font, Brushes.Black, left, top + 3) End Sub End Class
--
Viele Grüsse
Peter Fleischer (ehem. MVP)
Meine Homepage mit Tipps und Tricks- Als Antwort vorgeschlagen Peter Fleischer Mittwoch, 27. September 2017 07:14
- Als Antwort markiert Ahmed Martens Mittwoch, 27. September 2017 08:46
Alle Antworten
-
Hi Ahmed,
ohne die weiteren Forderungen zu kennen, hier mal eine Demo, wie man das machen kann:Public Class Form15 Private WithEvents tc As New TabControl With {.Dock = DockStyle.Fill, .DrawMode = TabDrawMode.OwnerDrawFixed} Private Sub Form15_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Controls.Add(tc) For i = 1 To 5 tc.Controls.Add(New TabPage With {.Text = $"Reiter {i}", .Width = 70}) Next End Sub Private Sub tc_DrawItem(sender As Object, e As DrawItemEventArgs) Handles tc.DrawItem Dim tc = TryCast(sender, TabControl) If tc Is Nothing Then Exit Sub Dim gr = e.Graphics Dim left = e.Bounds.X Dim top = e.Bounds.Y Dim size = 12 Dim path As New System.Drawing.Drawing2D.GraphicsPath() path.AddLine(left + 1, top + 1, left + size, top + 1) path.AddLine(left + 1, top + 1, left + 1, top + size) path.AddLine(left + 1, top + size, left + size, top + 1) gr.FillPath(Brushes.Red, path) gr.DrawString(tc.TabPages(e.Index).Text, tc.TabPages(e.Index).Font, Brushes.Black, left, top + 3) End Sub End Class
--
Viele Grüsse
Peter Fleischer (ehem. MVP)
Meine Homepage mit Tipps und Tricks- Als Antwort vorgeschlagen Peter Fleischer Mittwoch, 27. September 2017 07:14
- Als Antwort markiert Ahmed Martens Mittwoch, 27. September 2017 08:46
-
Hi Ahmed,
wenn Du das Windows-Design mit TabDrawMode.OwnerDrawFixed ausschaltest, musst Du ein eigenes Design selbst malen.--
Viele Grüsse
Peter Fleischer (ehem. MVP)
Meine Homepage mit Tipps und Tricks -
Hi Ahmed,
wenn Du wirklich flexibel gestalten willst, dann solltest Du auf WPF umsteigen.--
Viele Grüsse
Peter Fleischer (ehem. MVP)
Meine Homepage mit Tipps und Tricks -