调整没有边框的表单的大小 [英] Resizing a form with no border

查看:113
本文介绍了调整没有边框的表单的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我设置FormBorderStyle = None,我怎么能允许它调整大小?



[修改:学习如何写一个正确的问题。主题应该是一般的,详细说明应该包含问题的更详细描述]

If I set FormBorderStyle = None, how can I allow it to be resized?

[Modified: Learn how to write a proper question. The subject should be general and the "Detailed Description" should contain the more detailed description of the question]

推荐答案

你要做的是使用表格自己实现它MouseMove和MouseDown事件。如果您有菜单,这会有点复杂,因为您还必须处理菜单的MouseMove和MouseDown,因为它将覆盖Form的事件。基础是:



What you have to do is implement it yourself using the Form's MouseMove and MouseDown events. This is a little more complicated if you have menus because then you also have to handle the menu's MouseMove and MouseDown as well because it will override the Form's events. The basics are:

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
    if ((e.X <= 2 && e.Y <= 2) || (e.X + 2 >= this.Width && e.Y + 2 >= this.Height))
    {
        this.Cursor = Cursors.SizeNWSE;
    }
    else if ((e.X + 2 >= this.Width && e.Y <= 2) || (e.X <= 2 && e.Y + 2 >= this.Height))
    {
        this.Cursor = Cursors.SizeNESW;
    }
    else if (e.X <= 2 || e.X + 2 >= this.Width)
    {
        this.Cursor = Cursors.SizeWE;
    }
    else if (e.Y <= 2 || e.Y + 2 >= this.Height)
    {
        this.Cursor = Cursors.SizeNS;
    }
    else
    {
        this.Cursor = Cursors.Default;
    }
}





当然,要完全实现它,你必须检查鼠标是否是down(你可以使用bool并在MouseDown和MouseUp事件中设置它),然后检查它被拖动的方式。如果它被向上或向左拖动,您必须首先移动表单,然后根据其移动量调整大小。如果它在右侧或底部,您可以将高度和宽度设置为鼠标位置(当然,首先检查,因为看起来鼠标没有注册为在窗体中,直到它比高度小两个和宽度)。



您可以通过仅允许它们使用右下角调整大小来简化它,您可以在该角落添加一张图片,表示您可以调整它的大小。



[更新]

实际上,它不会那么简单。您首先必须对鼠标进行全局挂钩。原因是当您移出窗体时,MouseMove将无法工作,您必须执行此操作才能调整窗体大小。所以,它可以完成,但同样,你必须使用全局钩子。有关如何执行此操作的文章如下:使用C#处理全局鼠标和键盘挂钩 [ ^ ]


In C#(和VB,就此而言)你需要为一个表格设置一个大小的边框:它是用户拉出的边框,当没有边框时,没有什么可以抓住的。



假设您真正想要的是没有标题栏的大小形式,您可以通过设置 ControlBox MaximizeBox 来实现和 MinimizeBox 全部到 False 文本到一个空字符串。如果没有任何内容显示在标题栏中,框架将不会绘制一个。只需记住给用户一些关闭表单的方法; P
In C# (and VB, for that matter) you need to have a border for a form to be sizeable: it is the border that the user pulls, and when there is no border, there is nothing to grab on to.

Assuming that what you really want is a sizable form without a title bar, you can get this by setting ControlBox, MaximizeBox and MinimizeBox all to False and Text to an empty string. With nothing to display in the title bar, the Framework won't draw one. Just remember to give your users some way to close the form ;P


没有边框,只有AFAIK方式,将处理MouseDown,MouseMove,MouseUp和Paint事件。你必须得到移动的坐标并改变表格的大小。



如果你真的需要调整大小,你应该有一个边框。 />


BTW为什么你有无边框形式?如果您的动机可以通过边框实现,则不需要所有这些事件。
Without a border, only way AFAIK, will be to handle the MouseDown, MouseMove,MouseUp and Paint events. You will have to get the co-ordinates of the move and change the size of the form.

If you really need resizing, you should have a border.

BTW why are you having a borderless form? If your motive can be achieved with a border, you do not need all those events.


这篇关于调整没有边框的表单的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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