Can you make Powershell GUI form draggable without title bar? RRS feed

  • Question

  • Hi,

    I would like to know If you can make a Powershell GUI form draggable/movable without a title bar? I have searched online but all I find is how to do it in C#. So is there some way to add a C# event handler to a Powershell GUI form control event for MouseDown? or is there a powershell way of doing this that i'm not aware of? I'd rather this be in Powershell as I don't know much C#. Below is what I found for C#. Any help would be much appreciated!

    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
                if (e.ChangedButton == MouseButton.Left)

    • Moved by Bill_Stewart Friday, July 27, 2018 6:25 PM Abandoned
    Saturday, April 28, 2018 6:24 PM

All replies

  • All depends on what kind of form you are using.  "Windows Forms Form" or WPF form?


    Saturday, April 28, 2018 7:24 PM
  • I should note that the code posted is only for WPF forms.

    The PowerShell version for WPF should be:

                if ($_.ChangedButton -eq 'Left')


    Saturday, April 28, 2018 8:14 PM
  • Here is a simple form, I tried your code but it did not work. Did I do this right?

    Add-Type -AssemblyName System.Windows.Forms
    $Mainform        = New-Object System.Windows.Forms.Form
    $Mainform.Height = 500
    $Mainform.Width  = 336
    $Mainform.StartPosition = 'CenterScreen'
         if ($_.ChangedButton -eq 'Left'){

    Saturday, April 28, 2018 8:57 PM
  • The WPF code cannot work with a Windows Form.  It is only valid for WPF forms.


    Saturday, April 28, 2018 9:14 PM
  • The following is a well guarded secret method.  You must have correct clearance to use it.

    Be careful ...

    $code = @'
    using System;
    using System.Runtime.InteropServices;
    public static class Win32API{
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        public static extern bool ReleaseCapture();
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type $code
    #Event Argument: $_ = [System.Windows.Forms.MouseEventArgs
        if ($_.Button -eq 'Left'){
            [Win32API]::SendMessage($form1.Handle, 0xA1, 0x2, 0)
    $form1 = New-Object System.Windows.Forms.Form
    $form1.Size = '500,336'
    $form1.StartPosition = 'CenterScreen'
    $form1.FormBorderStyle = 'None'


    Saturday, April 28, 2018 9:25 PM