|
-
Jun 3rd, 2020, 02:04 PM
#1
Thread Starter
New Member
Custom ComboBox with editable text possible?
Hello, i've been trying to customize the .Net combox and have a good result for DropDownList style of combobox, but i want to be able to write the input of the combobox as in DropDown style. As soon as i change the style, the textbox area stops responding to my OnPaint event.
Is it an impediment from Windows or is there a workaround to have a customized and editable combobox?
This would be my constructor
Code:
Public Sub New()
InitializeComponent()
Me.SetStyle(ControlStyles.UserPaint _
Or ControlStyles.AllPaintingInWmPaint _
Or ControlStyles.Opaque _
Or ControlStyles.ResizeRedraw, True)
Me.DrawMode = DrawMode.OwnerDrawFixed
Me.m_ControlBuffer = New Bitmap(Me.Width, Me.Height)
Me.m_ControlGraphics = Graphics.FromImage(m_ControlBuffer)
Me.m_BackBuffer = New Bitmap(Me.Width, Me.Height)
Me.m_BackGraphics = Graphics.FromImage(m_BackBuffer)
Dim backcolor As Color = If(Enabled, m_UITheme.TextBoxColor, Color.White)
BackgroundBrush = New SolidBrush(backcolor)
End Sub
and this the function i call on my paint method
Code:
Public Sub CustomPaint(screenGraphics As Graphics)
' If there is body to be drawn.
If Me.Width > 0 AndAlso Me.Height > 0 Then
' Clear the background image graphics
If Me.m_backImage Is Nothing Then
' Cached Background Image
Me.m_backImage = New Bitmap(Me.Width, Me.Height)
Dim backGraphics As Graphics = Graphics.FromImage(Me.m_backImage)
backGraphics.Clear(Color.Transparent)
Me.PaintTransparentBackground(backGraphics, Me.ClientRectangle)
End If
m_BackGraphics.Clear(Color.Transparent)
m_BackGraphics.DrawImageUnscaled(Me.m_backImage, 0, 0)
m_ControlGraphics.Clear(Color.Transparent)
m_ControlGraphics.SmoothingMode = SmoothingMode.HighQuality
' Begin drawing
Dim path As GraphicsPath = GetBoxBorder()
m_ControlGraphics.FillPath(BackgroundBrush, path)
PaintArrowAndLine(m_ControlGraphics)
' Draw text
DrawText(m_ControlGraphics)
m_ControlGraphics.Flush()
m_BackGraphics.DrawImage(m_ControlBuffer,
New Rectangle(0, 0,
m_ControlBuffer.Width,
m_ControlBuffer.Height),
0, 0,
m_ControlBuffer.Width,
m_ControlBuffer.Height,
GraphicsUnit.Pixel)
m_BackGraphics.Flush()
' Now paint this to the screen
screenGraphics.DrawImageUnscaled(m_BackBuffer, 0, 0)
End If
End Sub
Thanks in advance
Last edited by Wardo; Jun 3rd, 2020 at 02:05 PM.
Reason: Grammar
-
Jun 3rd, 2020, 09:12 PM
#2
Re: Custom ComboBox with editable text possible?
When the DropDowenStyle is set to DropDown, there is actually a Win32 edit control embedded in the .NET control. You'd have to access that to be able to custom draw on that part of the control.
-
Jun 4th, 2020, 08:09 AM
#3
Thread Starter
New Member
Re: Custom ComboBox with editable text possible?
Can you guide me on how to do that? Is it through the DRAWITEMSTRUCT? https://docs.microsoft.com/en-us/win...drawitemstruct
-
Jun 4th, 2020, 08:14 AM
#4
Re: Custom ComboBox with editable text possible?
I have no idea how it would be done.
-
Jun 5th, 2020, 04:21 AM
#5
Thread Starter
New Member
Re: Custom ComboBox with editable text possible?
I found that WM_CTLCOLOREDIT could help me, from the docs:
An edit control that is not read-only or disabled sends the WM_CTLCOLOREDIT message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control.
How can i accomplish this? I'm searching to do it from the WndProc of my ComboBox, but don't know how to:
If an application processes this message, it must return the handle of a brush. The system uses the brush to paint the background of the edit control.
Just for the sake of of showing code, this is what i've tried in the last couple of minutes since i asked.
Code:
<DllImport("gdi32.dll")>
Public Shared Function CreateSolidBrush(ByVal color As Integer) As IntPtr
End Function
Protected Overrides Sub WndProc(ByRef m As Message)
If (m.Msg = &H133) Then
Dim brush As IntPtr = CreateSolidBrush(RGB(255, 0, 0))
m.Result = brush
End If
MyBase.WndProc(m)
End Sub
Any advice?
Last edited by Wardo; Jun 5th, 2020 at 05:51 AM.
Reason: Added my attempt as code
-
Jun 5th, 2020, 07:26 PM
#6
Re: Custom ComboBox with editable text possible?
 Originally Posted by Wardo
I found that WM_CTLCOLOREDIT could help me, from the docs:
How can i accomplish this? I'm searching to do it from the WndProc of my ComboBox, but don't know how to:
Just for the sake of of showing code, this is what i've tried in the last couple of minutes since i asked.
Code:
<DllImport("gdi32.dll")>
Public Shared Function CreateSolidBrush(ByVal color As Integer) As IntPtr
End Function
Protected Overrides Sub WndProc(ByRef m As Message)
If (m.Msg = &H133) Then
Dim brush As IntPtr = CreateSolidBrush(RGB(255, 0, 0))
m.Result = brush
End If
MyBase.WndProc(m)
End Sub
Any advice?
Looking at what you've posted, you're calling CreateSolidBrush and returning a pointer to a brush. The docs text you quoted says it can be used to change the edit control (part of the Combo) colors and text. I think it wouldn't be possible to achieve what you're hoping for in that way. You're looking for a usable edit control, and what you've posted isn't that.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|