PC Review


Reply
Thread Tools Rate Thread

ComboBox lock/suppress DropDown

 
 
ian_jacobsen@hotmail.com
Guest
Posts: n/a
 
      12th Jul 2006

I have a control that is derived from the standard ComboBox. I want to
lock or suppress the DropDown when the arrow button is clicked without
disabling the control.

This is related to another post that I have out there for a custom
OnPaint event. I want to provide custom colors for ComboBox that work
even when the Enabled is set to false (by default it is set to Gray).
I have provided a new implementation for the Enabled property to handle
it myself. When the control is in my disabled state I am supressing
KeyDowns so that it appears as if it is disabled. The only problem is
that you can still drop down the list, and choose an item. If I can
lock this, I'm good to go.

Oh, and I'd rather not have to use SendMessage in WndProc to accomplish
this. I don't want to have a dependency on user32.dll.

--Ian;

 
Reply With Quote
 
 
 
 
Bruce Wood
Guest
Posts: n/a
 
      12th Jul 2006
(E-Mail Removed) wrote:
> I have a control that is derived from the standard ComboBox. I want to
> lock or suppress the DropDown when the arrow button is clicked without
> disabling the control.
>
> This is related to another post that I have out there for a custom
> OnPaint event. I want to provide custom colors for ComboBox that work
> even when the Enabled is set to false (by default it is set to Gray).
> I have provided a new implementation for the Enabled property to handle
> it myself. When the control is in my disabled state I am supressing
> KeyDowns so that it appears as if it is disabled. The only problem is
> that you can still drop down the list, and choose an item. If I can
> lock this, I'm good to go.
>
> Oh, and I'd rather not have to use SendMessage in WndProc to accomplish
> this. I don't want to have a dependency on user32.dll.


Have you tried asking this question in
microsoft.public.dotnet.framework.windowsforms or
microsoft.public.dotnet.framework.windowsforms.controls ?

 
Reply With Quote
 
ian_jacobsen@hotmail.com
Guest
Posts: n/a
 
      12th Jul 2006
> Have you tried asking this question in
> microsoft.public.dotnet.framework.windowsforms or
> microsoft.public.dotnet.framework.windowsforms.controls ?


Yes, I also posted this in
microsoft.public.dotnet.framework.windowsforms.controls

 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      13th Jul 2006

> I have a control that is derived from the standard ComboBox. I want to
> lock or suppress the DropDown when the arrow button is clicked without
> disabling the control.
>
> This is related to another post that I have out there for a custom
> OnPaint event. I want to provide custom colors for ComboBox that work
> even when the Enabled is set to false (by default it is set to Gray).
> I have provided a new implementation for the Enabled property to handle
> it myself. When the control is in my disabled state I am supressing
> KeyDowns so that it appears as if it is disabled. The only problem is
> that you can still drop down the list, and choose an item. If I can
> lock this, I'm good to go.


Put another control (override OnPaint and call ControlPaint.DrawComboButton)
ontop of it. You can get the size and position of the combo button by
P/Invoking GetComboBoxInfo (or you can calculate it with a little use of
SystemInformation.CaptionButtonSize)


> Oh, and I'd rather not have to use SendMessage in WndProc to accomplish
> this. I don't want to have a dependency on user32.dll.


Why not? It's not like user32.dll won't be there.


/claes


 
Reply With Quote
 
ian_jacobsen@hotmail.com
Guest
Posts: n/a
 
      13th Jul 2006
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;

 
Reply With Quote
 
Claes Bergefall
Guest
Posts: n/a
 
      14th Jul 2006
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

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
>



 
Reply With Quote
 
ian_jacobsen@hotmail.com
Guest
Posts: n/a
 
      19th Jul 2006
Awesome, thanks Claes.

I ended up using an override of WndProc and providing my own custom
draw method on the WM_PAINT message in the derived ComboBox class. The
ComboBox has a really messed up OnPaint event, that doesn't allow for
painting your own custom text box area.

--Ian;

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Suppress Dropdown Menu Manuelauch Microsoft Access Forms 3 29th May 2009 12:55 AM
How to Suppress combobox dropdown? =?Utf-8?B?QnJhZG1hbg==?= Microsoft Dot NET Framework Forms 1 20th Feb 2007 04:00 PM
Re: Bug: Combobox.dropdown = True during Form.Load event handler causes listbox to be disabled, even though combobox is Enabled. Herfried K. Wagner [MVP] Microsoft Dot NET Framework Forms 0 12th Feb 2004 10:00 PM
Bug: Combobox.dropdown = True during Form.New() causes listbox to be disabled, even though combobox is Enabled. =?Utf-8?B?UmF0a2lsZXk=?= Microsoft Dot NET Framework Forms 1 12th Feb 2004 09:58 PM
Bug: Combobox.dropdown = True during Form.Load event handler causes listbox to be disabled, even though combobox is Enabled. =?Utf-8?B?UmF0a2lsZXk=?= Microsoft Dot NET Framework 0 12th Feb 2004 07:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.