设置ClientRectangle在C#中的自定义窗体 [英] Set ClientRectangle in custom form in C#

查看:1230
本文介绍了设置ClientRectangle在C#中的自定义窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#我有没有边框风格,覆盖OnPaint事件自定义表单,并绘制透明按键自定义背景。我希望把我自己的客户端矩形值(这样的内容将放在我的自定义边框内),但unfortunally窗体的ClientRectangle属性是只读的。我发现了咨询网覆盖WndProc方法(它设置客户端大小),但saddly,我发现关于很少的信息。尤其是它需要填补这是由wParam和lParam,我所指的数据真的不知道如何在C#中做到这一点。

In C# I have custom form of None border style which override onPaint event and draw custom background with transparency key. I want to set my own client rectangle value (so content would be placed inside my custom border), but unfortunally Form's ClientRectangle property is read-only. I found advice over net to override WndProc method (where it sets client size) but saddly, I found very little info about that. Especially it requires to fill data which are pointed by lParam and wParam and I really don't know how to do this in C#.

任何帮助吗?

推荐答案

您的问题有几个事情,与我无关......首先你要绘制自己的边框上,然后调整客户端矩形。作为客户端的矩形被确定在移动窗口时,这确实是不可能的。一旦确定了完全不同的绘制消息是负责起草的所有非客户端的内容。因此,你可以做你的建议是什么;然而,这将打破当前的边界画。

Your question has a couple of things that concern me... first you want draw your own border and then adjust the client rectangle. This really isn't possible as the client rectangle is determined when the window moves. Once determined a completely different paint message is responsible for drawing all non-client content. Thus you can do what you suggest; however, it will break your current border painting.

这将远远eaiser所有的控件从表单移动到一个新的面板控制,并将其放置在窗体上。现在你可以,如果你在那里调整客户区位置时,该面板

It would be FAR eaiser to move all your controls from your form into a new Panel control and place it on the form. Now you can position this panel as if you where adjusting the client area.

如果你必须使用你原来的想法修改,你会做以下窗口客户区着手:

If you must proceed with your original thought to modify the window client area you would do the following:

    private void AdjustClientRect(ref RECT rcClient)
    {
        rcClient.Left += 10;
        rcClient.Top += 10;
        rcClient.Right -= 10;
        rcClient.Bottom -= 10;
    }

    struct RECT { public int Left, Top, Right, Bottom; }
    struct NCCALCSIZE_PARAMS
    {
        public RECT rcNewWindow;
        public RECT rcOldWindow;
        public RECT rcClient;
        IntPtr lppos;
    }

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        const int WM_NCCALCSIZE = 0x0083;
        if (m.Msg == WM_NCCALCSIZE)
        {
            if (m.WParam != IntPtr.Zero)
            {
                NCCALCSIZE_PARAMS rcsize = (NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NCCALCSIZE_PARAMS));
                AdjustClientRect(ref rcsize.rcNewWindow);
                Marshal.StructureToPtr(rcsize, m.LParam, false);
            }
            else
            {
                RECT rcsize = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
                AdjustClientRect(ref rcsize);
                Marshal.StructureToPtr(rcsize, m.LParam, false);
            }
            m.Result = new IntPtr(1);
            return;
        }
    }

这篇关于设置ClientRectangle在C#中的自定义窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆