How do you prevent a windows from being moved?

前端 未结 15 2000
刺人心
刺人心 2020-11-27 15:30

How would i go about stopping a form from being moved. I have the form border style set as FixedSingle and would like to keep it this way because it looks good in vista :)

15条回答
  •  Happy的楠姐
    2020-11-27 16:29

    It's not all pretty (there is some flashing going on when you try to move the form), but you can use the LocationChanged property to keep the form where you want it:

    private Point _desiredLocation;
    // assign the _desiredLocation variable with the form location at some
    // point in the code where you know that the form is in the "correct" position
    
    
    private void Form_LocationChanged(object sender, EventArgs e)
    {
        if (this.Location != _desiredLocation)
        {
            this.Location = _desiredLocation;
        }
    }
    

    Out of curiousity; why would you want to do this?

提交回复
热议问题