Extend System.Windows.Forms.ComboBox

I would like to extend the System.Windows.Forms.ComboBox control with the ReadOnly property, which displays the text of the selected items (similar to a label) when ReadOnly = true. (I don't like that the disabled view is achieved by setting Enabled = false)

How do I do this in winforms? This was very easy in ASP.NET where all I had to do was override the Render method. However, this is not so easy with winforms.

From what I'm about, I need

a) Override OnPaint method

b) Call this.SetStyle (ControlStyles.UserPaint, true) to call OnPaint.

But now it seems to me that I have to do the whole picture myself. It's true? Couldn't the underlying ComboBox be allowed to handle coloring the control when ReadOnly = false? Also, what ControlStyles should I be using?

+1


source to share


2 answers


Do what windows do.
You only have 1 item in the combo box and let it be selected and included.



+1


source


Place a ComboBox control in a UserControl. The UserControl will go through most of the properties and events, but in response to the .ReadOnly property, it will hide the ComboBox control and show the ReadOnly edit box.



0


source







All Articles