我想让dateTimePicker、comboBox、textBox这三个控件,看上去是可以修改、编辑的,实际是不可修改、编辑的。如何实现呀。

解决方案 »

  1.   

    这些控件都有一个Enabled属性,设置为False不就可以了吗?
    只能看不能用
      

  2.   

    combobox.Enable=false;
    dateTimePicker.Enable=false;
    textBox.Enable=false;textBox.ReadOnly=true;
      

  3.   

    需要看的視圖效果,
    覺得使用控件的ReadOnly=true比較符合,
    而Enable=false是使控件失效,
    且顯示的顏色明顯不讓修改..
      

  4.   

     [System.Runtime.InteropServices.DllImport("coredll.dll")]
            public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc);
            [System.Runtime.InteropServices.DllImport("coredll.dll")]
            public static extern int GetWindowLong(IntPtr hWnd, int nIndex);        public const int GWL_STYLE = -16;
            public const int WS_DISABLED = 0x8000000;
            public static void SetControlEnabled(Control c, bool enabled)
            {
                if (enabled)
                { SetWindowLong(c.Handle, GWL_STYLE, (~WS_DISABLED) & GetWindowLong(c.Handle, GWL_STYLE)); }
                else
                { SetWindowLong(c.Handle, GWL_STYLE, WS_DISABLED | GetWindowLong(c.Handle, GWL_STYLE)); }
            }
    不太理解,看这有用没?
      

  5.   

    我说的是看上去像是增加时的样子,实际不可以修改Enabled属性是可以实现这个功能,但是Enabled同时把控件颜色给修改了
      

  6.   

    看上去是可以修改、可编辑?将 textBox 的 ReadOnly 设置成 true 就行了.另外两个有点难度, 可以将其 Enable 设置成 false, 然后设置其 BackColor , 不过这样也不能完全达到楼主的要求.
      

  7.   


    comboBox 没有ReadOnly属性呀
      

  8.   

    dateTimePicker. 截获鼠标点击消息
    comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    textBox.ReadOnly = false;