How to: Change the input status of ComboBox to readonly mode; the read-only mode of textbox;

Source: Internet
Author: User

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 );


}
}


}

Okay. Combine my previous blog
Http://blog.csdn.net/FlashElf/archive/2004/10/31/161024.aspx

Not only can readonly be used, but can also restrict input;
Close the work;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.