I meant that you should create a new control and override its OnPaint. It
needs to be in order to trap the mouse clicks.
Inherit Control like this (make it an internal class in your ComboBox
class):
internal class ReadOnlyButton : Control
{
public ReadOnlyButton()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.Selectable, false);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
ControlPaint.DrawScrollButton(e.Graphics, this.ClientRectangle,
ScrollButton.Down, ButtonState.Inactive);
}
}
In the constructor of your ComboBox class:
....
m_readOnlyButton = new ReadOnlyButton();
m_readOnlyButton.Visible = false;
this.Controls.Add(m_readOnlyButton);
....
When you want your combo to be read only:
....
m_readOnlyButton.Visible = true;
m_readOnlyButton.BringToFront();
....
To position it (you might need to experiment a bit here, or use
GetComboBoxInfo):
....
Size size;
size.Height = this.Height - 4
size.Width = SystemInformation.CaptionButtonSize.Width - 2
m_readOnlyButton.Size = size
m_readOnlyButton.Location = new Point(this.Width -
SystemInformation.CaptionButtonSize.Width - 2, 0);
....
/claes
<ia**********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Claes Bergefall wrote:
>Put another control (override OnPaint and call
ControlPaint.DrawComboButton)
ontop of it.
This is simply a paint routine, not an new control (I didn't know about
ControlPaint, so that's a cool find, thanks). However I did try adding
a real button control (new Button()) and tried to place it on top of
the combobox button. I can't get it to show up, and all the clicks end
up going to the combo box so the list is still dropped down.
-- Ian;