In a desktop application
ComboBox drop-down box, input method;
Divided into three States
The simple text section can be edited. The list is visible.
The dropdown text part can be edited. You must click the arrow to display the list. This is the default style.
The dropdownlist user cannot directly edit the text section. You must click the arrow to display the list.
But there is no readonly status. Sometimes the data in the copy drop-down box is really depressing. Why not? This is Ms.
However, ComboBox is actually a nested control (Composite Control) in the dropdownlist state. It consists of a drop-down list and ComboBox itself.
In the dropdown state, one more edit in the ComboBox is the input state of the textbox in. net, which is controlled by Edit;
However, this edit cannot be obtained in. net. This. combobox1.controls. Count returns 0;
Since we know the principle, solving the problem is relatively simple (we don't need to win the API)
Now we need knowledge
1) if the subcontrol is obtained, there are multiple methods to achieve this. We can use the getwindow API to retrieve the first subcontrol under the XX window or control, which is convenient and does not require callback;
It is easier to use than enumwindows APIs.
2) how to set the read-only status for Edit (textbox;
This is basically enough to send a message (but I forgot the message). Let's look at the message starting with EM _ in msdn. Find em_setreadonly and check that it is his name;
According to SDK rules, all messages starting with EM _ correspond to edit;
Open the code editor and check several lines;
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;
Namespace windowsformsapplication1
{
Public partial class form1: Form
{
// Using system. runtime. interopservices;
[Dllimport ("user32.dll", charset = charset. Auto, exactspelling = true)]
Public static extern intptr getwindow (intptr hwnd, int ucmd );
Int gw_child = 5;
[Dllimport ("user32.dll", charset = charset. Auto)]
Public static extern intptr sendmessage (intptr hwnd, int MSG, int wparam, int lparam );
Public const int em_setreadonly = 0xcf;
Public form1 ()
{
Initializecomponent ();
Intptr edithandle = getwindow (combobox1.handle, gw_child );
Sendmessage (edithandle, em_setreadonly, 1, 0 );
}
}
}