0

根据msdn here上写的内容,如果要插入的字符数超过richTextBox的宽度,我应该收到EN_MAXTEXT消息,如果它没有ES_AUTOHSCROLL样式。
但这对我不起作用。

我写了这段代码:

    public class myRTB : RichTextBox
        {

            protected override void WndProc(ref Message m)
            {
                if (m.Msg == (WM_REFLECT | WM_COMMAND))
                {
                    int code = (int)m.WParam;
                    code = (code >> 16) & 0xffff;  // convert to hiword   
                    if (code == EN_MAXTEXT)
                    {
                        MessageBox.Show("max text");
                    }
                }

                base.WndProc(ref m);
            }

            public const int WM_USER = 0x400;
            public const int WM_REFLECT = WM_USER + 0x1C00;
            public const int WM_COMMAND = 0x111;
            public const int EN_MAXTEXT = 0x0501;

        }

我使用这段代码删除了 ES_AUTOHSCROLL 样式:

            private void button1_Click(object sender, EventArgs e)
            {
                // get the style
                IntPtr style = GetWindowLongPtr32(myRTB1.Handle, GWL_STYLE);
                // remove the ES_AUTOHSCROLL style
                SetWindowLong32(myRTB1.Handle, GWL_STYLE, (int)style - ES_AUTOHSCROLL);
            }

            public const int GWL_STYLE = -16;
            public const int ES_AUTOHSCROLL = 0x0080;

            [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
            private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);

            [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
            private static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex);
4

1 回答 1

-1

删除 WM_REFLECT,它与 C# 无关。

于 2012-08-18T21:07:52.613 回答