| |
VB.NET - FortgeschritteneComboBox in FlatStyle | | | Autor: Fritz | Datum: 06.01.05 15:44 |
| Ich habe alle Controls auf meiner Form in FlatStyle - bis auf die ComboBoxen. Kann mir jemand sagen, ob und wie ich die ebenfalls flach machen kann? | |
Re: ComboBox in FlatStyle | | | Autor: Fritz | Datum: 06.01.05 17:54 |
| Danke Dave
Das ist immerhin schonmal etwas. Aber noch nicht ganz was ich suche. Es ist zwar schön flach, aber der BorderStyle ist viel zu knallig. Ich möchte es einfach als FixedSingle.
Hab ein wenig dran rumgebastelt, doch ich krieg es nicht hin. Und beim DropDown verschwindet der Pfeil. Mich dünkt eigentlich das Ding wäre ganz gut, aber der Typ, der es gemacht hat, hat fast zuviel des Guten getan. Der DropDown-Teil hingegen ist ok.
Ich hab absolut keine Erfahrung mit Draw-Technik. Kannst du mir sagen, wie ich das Ding so reduzieren kann, dass es nur einfach die Borders FixedSingle macht und den Text nur markiert, wenn er den Focus hat. So wie die normale Combo eben.
Fritz | |
Re: ComboBox in FlatStyle | | | Autor: DaveS (Moderator) | Datum: 06.01.05 20:21 |
| Wenn ich mir das anschaue..naja, ist ziemlich schlampig programmiert und da könnte man noch einiges verbessern, leider habe ich nur Zeit für einen schnellen Fix, was aber vielleicht eher das ist was du willst
Public Class FlatCombo
Inherits ComboBox
Private BorderPen = New Pen(SystemColors.ControlDarkDark, 1)
Private BorderBrush As Brush = New SolidBrush(SystemColors.Window)
Private ArrowBrush As Brush = New SolidBrush(SystemColors.ControlText)
Private DropButtonBrush As Brush = New SolidBrush(SystemColors.Control)
Private _ButtonColor As Color = SystemColors.Control
Public Property ButtonColor() As Color
Get
Return _ButtonColor
End Get
Set(ByVal Value As Color)
_ButtonColor = Value
DropButtonBrush = New SolidBrush(Me.ButtonColor)
Me.Invalidate()
End Set
End Property
Dim borderWidth As Integer = 1
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case &HF
'Paint the background. Only the borders
'will show up because the edit
'box will be overlayed
Dim g As Graphics = Me.CreateGraphics
'Dim p As Pen = New Pen(Color.White, 2)
g.FillRectangle(BorderBrush, Me.ClientRectangle)
' Draw the border
Debug.WriteLine(Me.ClientRectangle.ToString())
g.DrawRectangle(BorderPen, 0, 0, Me.ClientRectangle.Width - 1, _
Me.ClientRectangle.Height - 1)
'Draw the background of the dropdown button
Dim rect As Rectangle = New Rectangle(Me.Width - 15, 1, 14, _
Me.Height - 2)
g.FillRectangle(DropButtonBrush, rect)
'Create the path for the arrow
Dim pth As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath
Dim TopLeft As PointF = New PointF(Me.Width - 13, (Me.Height - _
5) / 2)
Dim TopRight As PointF = New PointF(Me.Width - 6, (Me.Height - _
5) / 2)
Dim Bottom As PointF = New PointF(Me.Width - 9, (Me.Height + 2) _
/ 2)
pth.AddLine(TopLeft, TopRight)
pth.AddLine(TopRight, Bottom)
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
'Determine the arrow's color.
If Me.DroppedDown Then
ArrowBrush = New SolidBrush(SystemColors.HighlightText)
Else
ArrowBrush = New SolidBrush(SystemColors.ControlText)
End If
'Draw the arrow
g.FillPath(ArrowBrush, pth)
Case Else
Exit Select
End Select
End Sub
'Override mouse and focus events to draw
'proper borders. Basically, set the color and Invalidate(),
'In general, Invalidate causes a control to redraw itself.
#Region "Mouse and focus Overrides"
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
MyBase.OnMouseEnter(e)
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
If Me.Focused Then Exit Sub
Me.Invalidate()
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
MyBase.OnLostFocus(e)
Me.Invalidate()
End Sub
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
MyBase.OnSelectedIndexChanged(e)
Me.Invalidate()
End Sub
#End Region
End Class ________
Alle Angaben ohne Gewähr. Keine Haftung für Vorschläge, Tipps oder sonstige Hilfe, falls es schiefgeht, nur Zeit verschwendet oder man sonst nicht zufrieden ist | |
Re: ComboBox in FlatStyle | | | Autor: Fritz | Datum: 06.01.05 20:59 |
| Ja, das ist schon sehr viel besser. Ich hatte es gerade geschafft, dass wenigstens der Pfeil beim Droppen sichtbar bleibt.
Jetzt seh ich noch 2 Probleme:
1) bleibt der Text immer markiert, auch wenn die Box den Focus nicht mehr hat.
2) funktioniert die Datenbindung im DropDownList-Modus nicht.
Wozu braucht es übrigens die #Region? Ich sehe keinen Unterschied, wenn ich die einfach auskommentiere.
Ich bin ja kein Profi, aber wie schon gesagt, ich habe den Eindruck, das sollte irgendwie einfacher gehen, denn die DropDownListe etwa, an der wird ja praktisch nichts verändert. Würde es nicht reichen, wenn man lediglich den Borderstyle neu definierte und den Rest möglichst so belässt, wie er ist? | |
Re: ComboBox in FlatStyle | | | Autor: Fritz | Datum: 06.01.05 21:05 |
| Tschuldigung - der Focus ist schon richtig. | |
Re: ComboBox in FlatStyle | | | Autor: Fritz | Datum: 06.01.05 21:38 |
| Ja, das sehe ich schon, ich dachte an den Arrow und die Region. Kann man die nicht übernehmen? Resp. einfach weglassen, weil sie ja in der regulären Combo sowieso schon drin sind.
Aber Hauptsache die Box funktioniert, und das tut sie ja so weit. Mit der Zeit komm ich dann schon dahinter, wie dieses OOP läuft... Von den dynamischen Panels, die du mir vor einiger Zeit mal rübergeschoben hast, habe ich inzwischen schon einige Variationen hingekriegt.
Danke schonmal und nochmal.
Fritz | |
Re: ComboBox in FlatStyle | | | Autor: Fritz | Datum: 06.01.05 22:00 |
| Na ist ja gut so. Bleibt noch das seltsame Verhalten beim DropDownList-Modus. Das kann ich mir gar nicht erklären.
Ich frage mich übrigens wirklich, wieso die da bei der standardmässigen Combo kein Borderstyle.FixedSingle eingebaut haben. | |
Re: ComboBox in FlatStyle | | | Autor: Deckelmaho | Datum: 09.11.20 09:45 |
| Nochmal aufgewärmt...
Leider gibt es auch in VS2019 noch keine brauchbare FlatComboBox, den Code von hier habe ich auch probiert, leider wurde im DropDownList-Modus das ausgewählte Item nicht angezeigt. Auch wenn der Thread schon älter ist, ist euer Forum weit oben in der Google suche.
Daher hier der Code den ich nun verwende:
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Namespace DrawFlat
<ToolboxBitmap(GetType(System.Windows.Forms.ComboBox))>
Public Class FlatComboBox
Inherits ComboBox
#Region "ComboInfoHelper"
Friend Class ComboInfoHelper
<DllImport("user32")>
Private Shared Function GetComboBoxInfo(ByVal hwndCombo As IntPtr, _
ByRef info As ComboBoxInfo) As Boolean
End Function
#Region "RECT struct"
<StructLayout(LayoutKind.Sequential)>
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
#End Region
#Region "ComboBoxInfo Struct"
<StructLayout(LayoutKind.Sequential)>
Private Structure ComboBoxInfo
Public cbSize As Integer
Public rcItem As RECT
Public rcButton As RECT
Public stateButton As IntPtr
Public hwndCombo As IntPtr
Public hwndEdit As IntPtr
Public hwndList As IntPtr
End Structure
#End Region
Public Shared Function GetComboDropDownWidth() As Integer
Dim cb As ComboBox = New ComboBox()
Dim width As Integer = GetComboDropDownWidth(cb.Handle)
cb.Dispose()
Return width
End Function
Public Shared Function GetComboDropDownWidth(ByVal handle As _
IntPtr) As Integer
Dim cbi As ComboBoxInfo = New ComboBoxInfo()
cbi.cbSize = Marshal.SizeOf(cbi)
GetComboBoxInfo(handle, cbi)
Dim width As Integer = cbi.rcButton.Right - cbi.rcButton.Left
Return width
End Function
End Class
#End Region
Public Const WM_ERASEBKGND As Integer = &H14
Public Const WM_PAINT As Integer = &HF
Public Const WM_NC_PAINT As Integer = &H85
Public Const WM_PRINTCLIENT As Integer = &H318
Private Shared DropDownButtonWidth As Integer = 17 ... Leider war ich auf 5Kb begrenzt, daher noch der Link zum Code, wer mag kann auch gleich die DLL verwenden
https://github.com/flammeseeker/FlatCombobox.git
Beste Grüße
Kevin | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
sevISDN 1.0
Überwachung aller eingehender Anrufe!
Die DLL erkennt alle über die CAPI-Schnittstelle eingehenden Anrufe und teilt Ihnen sogar mit, aus welchem Ortsbereich der Anruf stammt. Weitere Highlights: Online-Rufident, Erkennung der Anrufbehandlung u.v.m. Weitere InfosTipp des Monats Neu! sevCoolbar 3.0
Professionelle Toolbars im modernen Design!
Mit sevCoolbar erstellen Sie in wenigen Minuten ansprechende und moderne Toolbars und passen diese optimal an das Layout Ihrer Anwendung an (inkl. große Symbolbibliothek) - für VB und MS-Access Weitere Infos
|