How to use WM_NCHITTEST and WS_EX_LAYOUTRTL together?

218 Views Asked by At

I have SizableUserControl Class using WM_NCHITTEST message and CustomUserControl Class that use WS_EX_LAYOUTRTL and WS_EX_NOINHERITLAYOUT for mirror on RightToLeft. When I'm using both the resize on runtime is reversed. How can I fix it?

Thanks for any help.

1

There are 1 best solutions below

0
On

I fixed it by adding this code to the CustomUserControl Class.

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    if (m.Msg == 0x84) // WM_NCHITTEST
        if (this.RightToLeft == RightToLeft.Yes && this.RightToLeftLayout)
            switch ((int)m.Result)
            {
                case 10: // HTLEFT
                    m.Result = (IntPtr)11; // HTRIGHT
                    break;
                case 11: // HTRIGHT
                    m.Result = (IntPtr)10; // HTLEFT
                    break;
                case 13: // HTTOPLEFT
                    m.Result = (IntPtr)14; // HTTOPRIGHT
                    break;
                case 14: // HTTOPRIGHT
                    m.Result = (IntPtr)13; // HTTOPLEFT
                    break;
                case 16: // HTBOTTOMLEFT
                    m.Result = (IntPtr)17; // HTBOTTOMRIGHT
                    break;
                case 17: // HTBOTTOMRIGHT
                    m.Result = (IntPtr)16; // HTBOTTOMLEFT
                    break;
                default:
                    break;
            }
}