Thanks to @Maciej Los , I found the problem and the solution, bypassing the message processed for Mouse Left Click (0x201) and only selecting the Combobox:
protected override void WndProc(ref Message m)
{
if (ReadOnly)
{
switch (m.Msg)
{
case 0x201:
case 0x203:
break;
default:
base.WndProc(ref m);
break;
}
}
else
{
if (m.Msg == 0x201)
{
Select();
}
else
base.WndProc(ref m);
}
if (m.Msg == WM_PAINT)
{
using (var g = Graphics.FromHwnd(Handle))
{
using (var p = new Pen(this.BorderColor, 1))
{
g.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
}
}
}
}
Edited:
This is ok, but missing one thing. On first click it is Ok, DropDownList will show only one time, but on second click it will not dropping anymore. So, the solution is to change
if (m.Msg == 0x201)
{
Select();
}
to this
if (m.Msg == 0x201)
{
Select();
DroppedDown = true;
}
Edit 2:
I found that above solution is good, but something missing.
If I move the mouse over the control some flickering effect appears, but only if control does not have focus, so I have improved the code with this one:
else
{
if (m.Msg == 0x201)
{
Select();
DroppedDown = true;
}
else
if (!Focused || m.Msg != 0x0200)
{
base.WndProc(ref m);
}
}
So, let's see the entire code, to be easy for copy paste:
protected override void WndProc(ref Message m)
{
if (ReadOnly)
{
switch (m.Msg)
{
case 0x201:
case 0x203:
break;
default:
base.WndProc(ref m);
break;
}
return;
}
else
{
if (m.Msg == 0x201)
{
Select();
DroppedDown = true;
}
else
if (!Focused || m.Msg != 0x0200)
{
base.WndProc(ref m);
}
}
if (m.Msg == WM_PAINT)
{
using (var g = Graphics.FromHwnd(Handle))
{
using (var p = new Pen(this.BorderColor, 1))
{
g.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
}
}
}
}