my code override WndProc and paint the control all by myself:
<br />
using System;<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
using System.Drawing.Drawing2D;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace CustomControls<br />
{<br />
[ToolboxBitmap(typeof(System.Windows.Forms.ComboBox))]<br />
public class CustomComboBox: ComboBox<br />
{ <br />
#region ComboInfoHelper<br />
internal class ComboInfoHelper<br />
{<br />
[DllImport("user32")] <br />
private static extern bool GetComboBoxInfo(IntPtr hwndCombo, ref ComboBoxInfo info);<br />
<br />
#region RECT struct<br />
[StructLayout(LayoutKind.Sequential)]<br />
private struct RECT <br />
{<br />
public int Left;<br />
public int Top;<br />
public int Right;<br />
public int Bottom;<br />
}<br />
#endregion<br />
<br />
#region ComboBoxInfo Struct<br />
[StructLayout(LayoutKind.Sequential)]<br />
private struct ComboBoxInfo <br />
{<br />
public int cbSize;<br />
public RECT rcItem;<br />
public RECT rcButton;<br />
public IntPtr stateButton;<br />
public IntPtr hwndCombo;<br />
public IntPtr hwndEdit;<br />
public IntPtr hwndList;<br />
}<br />
#endregion<br />
<br />
public static int GetComboDropDownWidth()<br />
{<br />
ComboBox cb = new ComboBox();<br />
int width = GetComboDropDownWidth(cb.Handle);<br />
cb.Dispose();<br />
return width;<br />
}<br />
public static int GetComboDropDownWidth(IntPtr handle)<br />
{<br />
ComboBoxInfo cbi = new ComboBoxInfo();<br />
cbi.cbSize = Marshal.SizeOf(cbi);<br />
GetComboBoxInfo(handle, ref cbi);<br />
int width = cbi.rcButton.Right - cbi.rcButton.Left;<br />
return width;<br />
}<br />
}<br />
#endregion<br />
<br />
public const int WM_ERASEBKGND = 0x14;<br />
public const int WM_PAINT = 0xF;<br />
public const int WM_NC_PAINT = 0x85;<br />
public const int WM_PRINTCLIENT = 0x318;<br />
private static int DropDownButtonWidth = 17;<br />
<br />
[DllImport("user32.dll", EntryPoint="SendMessageA")]<br />
public static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, object lParam);<br />
<br />
[DllImport("user32")]<br />
public static extern IntPtr GetWindowDC (IntPtr hWnd );<br />
<br />
[DllImport("user32")]<br />
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC );<br />
<br />
static CustomComboBox()<br />
{<br />
DropDownButtonWidth = ComboInfoHelper.GetComboDropDownWidth() + 2;<br />
}<br />
<br />
public CustomComboBox()<br />
: base()<br />
{<br />
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
}<br />
<br />
protected override void OnSelectedValueChanged(EventArgs e)<br />
{<br />
base.OnSelectedValueChanged (e);<br />
this.Invalidate();<br />
}<br />
<br />
protected override void WndProc(ref Message m)<br />
{<br />
if (this.DropDownStyle == ComboBoxStyle.Simple)<br />
{<br />
base.WndProc(ref m);<br />
return;<br />
}<br />
<br />
IntPtr hDC = IntPtr.Zero;<br />
Graphics gdc = null;<br />
switch (m.Msg)<br />
{<br />
case WM_NC_PAINT: <br />
hDC = GetWindowDC(this.Handle);<br />
gdc = Graphics.FromHdc(hDC);<br />
SendMessage(this.Handle, WM_ERASEBKGND, hDC, 0);<br />
SendPrintClientMsg();
PaintFlatControlBorder(this, gdc);<br />
m.Result = (IntPtr) 1;
ReleaseDC(m.HWnd, hDC);<br />
gdc.Dispose(); <br />
<br />
break;<br />
case WM_PAINT: <br />
base.WndProc(ref m);<br />
hDC = GetWindowDC(this.Handle);<br />
gdc = Graphics.FromHdc(hDC);<br />
Pen p = new Pen((this.Enabled? BackColor:SystemColors.Control), 2); <br />
gdc.DrawRectangle(p, new Rectangle(2, 2, this.Width-3, this.Height-3));<br />
PaintFlatDropDown(this, gdc);<br />
PaintFlatControlBorder(this, gdc);<br />
ReleaseDC(m.HWnd, hDC);<br />
gdc.Dispose(); <br />
<br />
break;<br />
default:<br />
base.WndProc(ref m);<br />
break;<br />
}<br />
}<br />
private void SendPrintClientMsg()<br />
{<br />
Graphics gClient = this.CreateGraphics();<br />
IntPtr ptrClientDC = gClient.GetHdc();<br />
SendMessage(this.Handle, WM_PRINTCLIENT, ptrClientDC, 0);<br />
gClient.ReleaseHdc(ptrClientDC);<br />
gClient.Dispose();<br />
}<br />
<br />
private void PaintFlatControlBorder(Control ctrl, Graphics g)<br />
{<br />
Rectangle rect = new Rectangle(0, 0, ctrl.Width, ctrl.Height);<br />
if (ctrl.Focused == false || ctrl.Enabled == false )<br />
ControlPaint.DrawBorder(g, rect, SystemColors.ControlDark, ButtonBorderStyle.Solid);<br />
else<br />
ControlPaint.DrawBorder(g, rect, Color.Black, ButtonBorderStyle.Solid);<br />
Color borderColor = Color.LightBlue;<br />
ControlPaint.DrawBorder(g, rect, borderColor, ButtonBorderStyle.Solid);<br />
}<br />
public static void PaintFlatDropDown(Control ctrl, Graphics g)<br />
{<br />
Rectangle rect = new Rectangle(ctrl.Width-DropDownButtonWidth, 0, DropDownButtonWidth, ctrl.Height);<br />
ControlPaint.DrawComboButton(g, rect, ButtonState.Flat);<br />
}<br />
<br />
protected override void OnLostFocus(System.EventArgs e)<br />
{<br />
base.OnLostFocus(e);<br />
this.Invalidate();<br />
}<br />
<br />
protected override void OnGotFocus(System.EventArgs e)<br />
{<br />
base.OnGotFocus(e);<br />
this.Invalidate();<br />
} <br />
protected override void OnResize(EventArgs e)<br />
{<br />
base.OnResize (e);<br />
this.Invalidate();<br />
}<br />
<br />
}<br />
}<br />
<br />