星期一, 十月 06, 2008

ReadOnlyRichTextBox - Roland Weigelt
This is a lot better than the previous solution, I think I found this before... what ever, set style then you dont need to set Enabled = false. Then you can set backcolor etc to make it look what ever you want. :)
        public ReadOnlyRichTextBox()
{
base.ReadOnly=true;
base.TabStop=false;
this.SetStyle(ControlStyles.Selectable, false);
}

I knew that I had the perfect solution before.

const int WM_SETFOCUS = 0x0007;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_SETFOCUS:
// We don't want the RichTextBox to be able to receive focus, so just
// pass the focus back to the control it came from.
IntPtr prevCtl = m.WParam;
Control c = Control.FromHandle(prevCtl);
c.Select();
return;
}
base.WndProc (ref m);
}

没有评论:

发表评论