惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky
MyScale Blog
MyScale Blog
Jina AI
Jina AI
B
Blog
Microsoft Security Blog
Microsoft Security Blog
T
Troy Hunt's Blog
博客园_首页
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
GbyAI
GbyAI
T
Tenable Blog
B
Blog RSS Feed
S
Securelist
T
Threat Research - Cisco Blogs
P
Privacy International News Feed
P
Proofpoint News Feed
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
罗磊的独立博客
AWS News Blog
AWS News Blog
V
V2EX
宝玉的分享
宝玉的分享
J
Java Code Geeks
小众软件
小众软件
Spread Privacy
Spread Privacy
腾讯CDC
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
V
Visual Studio Blog
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
C
Check Point Blog
Webroot Blog
Webroot Blog
D
DataBreaches.Net
Cloudbric
Cloudbric
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家

博客园 - 曲滨*銘龘鶽

IE8 隐藏命令行参数 学习 ASP.NET mvc 第一天、也可能是最后一天 Visual Studio 2008 开启被遗忘的 “同步类视图”功能、附带一个MSDN 的 bug 实战 IE8 开发人员工具 windows 桌面开发 - 子类化控件(不用任何WinAPI),演示拦截Button的WM_LBUTTONDBLCLK 在真实项目中使用第三方或开源代的代码,组件,中间件,框架的基本规则 你有?项目设计开发阶段,甲方经常的要求看程序,而经常在做【假界面】【假程序】的情况吗? Windows Live Writer 测试 文档共享:罗斯文2007 (Northwind 2007),数据库文件,中文版本、英文版、英文表结构中文数据版 本机 MSDN Sorry, no topics were found for the selected link 问题,及临时解决方案 2008-9-6 文档共享:罗斯文2007 (Northwind 2007),数据库,微软最新的 Access 2007 样列数据库分析(中文/英文) C# 操作 XML 数据库类型、Oracle XMLType IE7,ie8说爱你不容易,企业应用困局 如何:在 Winform 动态启动、控制台命令行? 设计模式学习:Model View Presenter (MVP) C# 直接执行、调用本机代码、汇编代码 shell Native Code OneDay “屏幕任务”小软件 TaskScreen_080408 Oracle 使用数据泵 expdp impdp 导入导出数据库“表空间”文件 适合编程开发用的"宋体"和"新宋体"
如何:使 comboBox 输入状态变成 readonly 方式;TextBox 只读时的效果;
曲滨*銘龘鶽 · 2008-07-10 · via 博客园 - 曲滨*銘龘鶽

桌面应用程序中的
comboBox 下拉框,输入方式;
分为3种状态
 Simple 文本部分可编辑。列表部分总可见。
 DropDown 文本部分可编辑。用户必须单击箭头按钮来显示列表部分。这是默认样式。
 DropDownList 用户不能直接编辑文本部分。用户必须单击箭头按钮来显示列表部分。

却没有 readonly 状态;有些时候客户要copy 下拉框里的数据确实挺郁闷的,为啥没有?这个得问ms 了呵呵
不过 comboBox 其实是一个嵌套控件(复合控件)在 DropDownList  状态时;他由 下拉列表,和 comboBox  本身组成
DropDown 状态时 comboBox  中多了一个 edit 就是 .net 下的 TextBox 那个输入状态是由 edit 控制的;
不过这个 edit 是无法在 .net 下取得的

this.comboBox1.Controls.Count 返回 0;

既然知道原理了解决问题也就相对简单的(不用 Win API 看来是不行了)
现在我们需要知识
1) 如果取得子控件;这个有多种方法可以实现我们选择

GetWindow 这个 API 取xx窗口或控件下的第一个子控件比较方便也不用回调什么的;
    比 EnumWindows API 容易用多了
2) 如何给 edit (TextBox) 设置只读状态;
   这个就是发个消息基本可以搞定(不过忘记是那个消息了),看看 msdn 找 em_ 开头的消息,找到 EM_SETREADONLY 看名字就是他了;
  根据 SDK 规则,em_ 开头的消息都是对应 edit 的;

打开代码编辑器,几行搞定;

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

    
}

好了结合我以前的一个blog

http://blog.csdn.net/FlashElf/archive/2004/10/31/161024.aspx

不但可以readonly 还可以限制输入;
打完收工;