[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)); } } 不太理解,看这有用没?
只能看不能用
dateTimePicker.Enable=false;
textBox.Enable=false;textBox.ReadOnly=true;
覺得使用控件的ReadOnly=true比較符合,
而Enable=false是使控件失效,
且顯示的顏色明顯不讓修改..
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)); }
}
不太理解,看这有用没?
comboBox 没有ReadOnly属性呀
comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
textBox.ReadOnly = false;