How do you prevent a windows from being moved?

前端 未结 15 1976
刺人心
刺人心 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条回答
  • 2020-11-27 16:14

    Private Sub MyFormLock() Me.Location = New Point(0, 0) End Sub

    Private Sub SearchSDR_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
        Call MyFormLock()
    End Sub
    
    0 讨论(0)
  • 2020-11-27 16:15

    Try to override WndProc:

    protected override void WndProc(ref Message m)
    {
       const int WM_NCLBUTTONDOWN = 161;
       const int WM_SYSCOMMAND = 274;
       const int HTCAPTION = 2;
       const int SC_MOVE = 61456;
    
       if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))
       {
           return;
       }
    
       if ((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))
       {
           return;
       }
    
       base.WndProc(ref m);
    }
    
    0 讨论(0)
  • 2020-11-27 16:17

    I found this to stop the form from moving (its in c#)

    protected override void WndProc(ref Message m)
            {
                const int WM_SYSCOMMAND = 0x0112;
                const int SC_MOVE = 0xF010;
    
                switch (m.Msg)
                {
                    case WM_SYSCOMMAND:
                        int command = m.WParam.ToInt32() & 0xfff0;
                        if (command == SC_MOVE)
                            return;
                        break;
                }
                base.WndProc(ref m);
            }
    

    Found here

    0 讨论(0)
  • 2020-11-27 16:19

    change the Form property StartPostion to Manual. Then, handle the LocationChanged event:

    private void frmMain_LocationChanged(object sender, EventArgs e)
    {
    Location = new Point(0, 0);
    }
    
    0 讨论(0)
  • 2020-11-27 16:24

    You can try:

    this.Locked = true;
    
    0 讨论(0)
  • 2020-11-27 16:27

    In Windows, the WS_CAPTION style is the non-client area that allows your window to be moved with a mouse. So the easiest way to do what you want is to remove this style from your window.

    However, if you need to have a caption and still achieve what you want, then the next style would be to capture the WM_NCHITTEST message and check for HTCAPTION. If the code is HTCAPTION, return NTNOWHERE instead. This will prevent the default window procedure from executing the default move window thing.

    0 讨论(0)
提交回复
热议问题