English 中文(简体)
C#:如何采取可消除的形式迁移?
原标题:C#: how to disable form move?

The MSV-Studio description for Locked is "The Locked property determines if we can move or resize the control" so I set the winforms Locked property to true but the form is still movable. What is the correct way to prevent the form from moving?

最佳回答

最大化。 感谢 JackN. ;-

问题回答

我使用以下代码显示内部书面公司安全申请的形式方言窗口,其中一项要求是,不能将形式转移、重新布局或以任何其他形式生活。 任何方面,见下面的开端......

/// <seealso href="http://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx"/>
    /// <seealso href="http://msdn.microsoft.com/en-us/library/ms633545(v=vs.85).aspx"/>
    public class ShowMessage
    {
        const int SW_SHOWMAXIMIZED = 3; //for maximising (if desired)
        const int SW_SHOW = 5; //for simply activating the form (not needed)
        const int SW_SHOWNORMAL = 1; //displays form at original size and position (what we use here)

        const UInt32 SWP_NOSIZE = 0x0001; //cannot be resized
        const UInt32 SWP_NOMOVE = 0x0002; //cannot be moved

        static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); //always lives at the top
        const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; //sets the flags for no resize / no move

        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        /// <summary>
        /// Displays the passed form using the parameters set in the base ShowMessage class
        /// </summary>
        /// <param name="frm">A Windows Form object</param>
        /// <example><code>ShowMessage.ShowTopmost(new myForm());</code></example>
        public static void ShowTopmost(Form frm)
        {
            ShowWindow(frm.Handle, SW_SHOWNORMAL); //shows the form
            SetWindowPos(frm.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); //sets the form position as topmost, centered

        }
    }

Then I simply call

ShowMessage.ShowTopmost(new frmMessage());

我不说这是唯一的方式,也不是正确的方式,而是说是:

这种做法通常不好,无法防止用户转移窗口。 用户应当能够在他想要的地方有窗户。 防止重新武装是一回事,防止迁移是另一回事。 我不了解任何C#本土这样做的方法,但你可能 h到温32,以防止窗户流动。

你也许能够利用形式上的实时活动,把形式重新定位到起点。 你们必须抓住和储存(记忆)起点。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签