在Winform中禁用移动形式 [英] Disable move form in winform

查看:77
本文介绍了在Winform中禁用移动形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用应用程序,我想禁用移动表单.但是我不知道怎么办?

I''m working with a application, I want disable move form. but I don''t know how do it?

推荐答案

很奇怪,这很容易实现:

Weird enough, this is ridiculously simple to achieve:

  1. 将以下代码添加到表单构造函数中:
  1. Add the following code to the the form constructor:
public NonMovableForm() {
   InitializeComponent();
   //add this:
   this.ShowInTaskbar = false;
   this.ControlBox = false;
   this.Text = null;
} //NonMovableForm

  • 如果确实需要,请创建一个伪造的控件,它模仿(或不带有)关闭按钮的标题栏,并将其停靠在表单顶部.
  • 不要实现表单拖动. :-)
  • 准备好接受用户的多次投诉.
  • 盈利?我不确定-请参阅上面的项目.


  • 这个想法是排除所有默认的拖动窗体的方法:标题栏和包含移动命令的非客户端图标菜单.

    无论如何,问题就解决了.自己决定是否真正想要.

    —SA



    The idea is to exclude all default means of dragging a form: the title bar and the non-client icon menu which contains move command.

    Anyway, the problem is solved. Decide for yourself if you really want it.

    —SA


    以下是解决此设计问题的几种方法:

    1.意识到您正在以非标准的方式使用WinForm,并考虑使用另一种类型的容器:

    一个.即使您在WinForm中实现了LocationChanged事件,以自动将Form的位置重置回某个固定的位置:当您尝试移动Form时,您仍然会得到视觉瑕疵……这取决于操作系统的视觉设置……例如如:窗体边界矩形的移动轮廓.

    2.如果确实确实需要使表格在某些时候可移动并在其他时候固定,并且您愿意忍受该表格标题栏的出现和消失,则您要做的就是完全隐藏标题栏和边框将ControlBox设置为``false.

    3.如果您必须拥有一个始终保持相同外观的表格...(即始终有一个标题栏...)并且您可以在没有视觉伪像的情况下控制其可移动性,那么您将可以使用Win用于创建WndProc并处理SC_Move消息的API.

    4.最后,您可以使用不带文本标题的Form,将FormBorderStyle设置为"FixedToolWindow,将ControlBox设置为" false,然后将自己的用户界面等效于标题栏放置在Form上,然后实现自己的单击拖动功能,可以在需要时关闭或打开它.
    Here are a few ways you can approach this design issue:

    1. realize that you are using a WinForm in ways that are not-standard, and consider using another type of container:

    a. even if you implement the LocationChanged event in the WinForm to automatically reset the Location of the Form back to some fixed place: you will still get a visual artifact as you attempt to move the Form ... depending on OS visual settings ... such as: a moving outline of the Form''s bounding rectangle.

    2. if you really have to make a Form movable at some times, and fixed at other times, and you are willing to put up with the appearance and disappearance of the Form''s title bar, all you have to do to completely hide the title bar and border is set ControlBox to ''false.

    3. if you must have a Form that retains the same appearance at all times ... i.e., always has a title bar ... and which you can control the movability of with no visual artifacts, you are going to have use the Win API to create a WndProc, and handle the SC_Move message.

    4. finally, you can use a Form with no Text caption, and FormBorderStyle set to ''FixedToolWindow, and ControlBox set to ''false, and put your own ui-equivalent to the Title Bar on the Form, and then implement your own click-drag-move functionality, which you can turn off or on when you wish.


    这篇关于在Winform中禁用移动形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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