zoukankan      html  css  js  c++  java
  • 如何:使 comboBox 输入状态变成 readonly 方式;TextBox 只读时的效果

    桌面应用程序中的
    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);
                
                
            }        
        }

        
    }
  • 相关阅读:
    Redis哨兵(Sentinel)模式
    一个http请求就是一个线程吗,java的服务是每收到一个请求就新开一个线程来处理吗
    Redis 快速入门
    Redis 持久化之RDB和AOF
    Junit 入门使用教程 转自:http://www.cnblogs.com/ysocean/p/6889906.html
    Spring里PropertyPlaceholderConfigurer类的使用 转自:https://www.cnblogs.com/huqianliang/p/5673701.html
    Apache Commons Codec 编码/解码 (Base64/MD5/SHA1/SHA256等算法) 转自https://blog.csdn.net/hbtj_1216/article/details/52813741
    hive中时间日期函数的使用
    关于mat函数
    strip 和split
  • 原文地址:https://www.cnblogs.com/Kingly/p/1424989.html
Copyright © 2011-2022 走看看