473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

ComboBox lock/suppress DropDown


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;

Jul 12 '06 #1
6 6222
ia**********@hotmail.com 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.con trols ?

Jul 12 '06 #2
Have you tried asking this question in
microsoft.public.dotnet.framework.windowsforms or
microsoft.public.dotnet.framework.windowsforms.con trols ?
Yes, I also posted this in
microsoft.public.dotnet.framework.windowsforms.con trols

Jul 12 '06 #3
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
Jul 13 '06 #4
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;

Jul 13 '06 #5
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;

Jul 14 '06 #6
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;

Jul 19 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jean | last post by:
hi: i am developing a custom combobox for my company's needs that is made up of a textbox, listbox, button. i am using c#. everything is fine except for one issue. in a normal combobox,...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
0
by: Mike | last post by:
Hi all! I have an OwnerDrawVariable ComboBox in .net. In the ComboBox DropDown event I display another control - works well. In the control's Leave event I remove the control - works well. So...
4
by: Kalvin | last post by:
I have seen this question raised, but I cannot find an answer. I have an MDI app, when I load an child form with a combobox being bound in the load event, it won't allow me to set selectedindex =...
3
by: **Developer** | last post by:
I want to have a ComboBox that is loaded programmically not except keyboard inputs. I tried in KeyDown not calling MyBase.OnKeyDown(e) and also tried setting e.Handled = True but neither appear...
5
by: Gil | last post by:
Is there a way to tell if a combbox is in dropdown mode. I tried and if statement combobox.dropdown = true but i get an error. dropwndown function doesnt store if its true or false what i am...
1
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on...
6
by: OldBirdman | last post by:
Is there a good way, in Access 2002, to only allow a user to pick from the dropdown list for a combobox? Logically, this would 'Lock' the textbox portion and have the dropdown list unlocked. Many...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.