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

推荐订阅源

T
Tailwind CSS Blog
博客园 - Franky
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 叶小钗
罗磊的独立博客
The GitHub Blog
The GitHub Blog
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
N
Netflix TechBlog - Medium
T
The Exploit Database - CXSecurity.com
云风的 BLOG
云风的 BLOG
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
Cyberwarzone
Cyberwarzone
T
Threatpost
T
Threat Research - Cisco Blogs
Recent Announcements
Recent Announcements
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
量子位
V
V2EX
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed
I
Intezer
Schneier on Security
Schneier on Security
雷峰网
雷峰网
B
Blog RSS Feed
Jina AI
Jina AI
爱范儿
爱范儿
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
美团技术团队
博客园 - 【当耐特】

博客园 - 曲滨*銘龘鶽

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 还可以限制输入;
打完收工;