如何防止用户更改窗口的位置

时间:2011-08-13 15:51:20

标签: c# winforms

  

可能重复:
  Fixing the position of a form

在我的应用程序中,某些表单必须不被用户移动。 如何禁用移动表单的另一个位置。

我将该代码放在form_load

this.ControlBox = false; this.Text = string.Empty;

当表单的标题为空时,表示无法移动其他位置。 但我想保留表格标题。

有办法吗?

1 个答案:

答案 0 :(得分:2)

我不确定这是最好的方法,但您可以执行类似以下代码的操作,以避免更改表单当前位置:

    public Form1()
    {
        InitializeComponent();
        pt = this.Location;
    }

    private Point pt;
    private void Form1_Move(object sender, EventArgs e)
    {
        this.Location = pt;
    }
希望这有帮助。