Hack Forums
[C#] Anyone know how to make a borderless form draggable in c#? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Anyone know how to make a borderless form draggable in c#? (/showthread.php?tid=5910088)



Anyone know how to make a borderless form draggable in c#? - KingSea - Nov 20, 2018

I've looked all over the internet for solutions, but didn't find any because they are in visual basic not c#.

if you have a solution please reply below.


RE: Anyone know how to make a borderless form draggable in c#? - gigajew - Nov 20, 2018

It's fairly straightforward. In your regular windows form, just override WndProc() and put your drag-drop logic there. In the following example I created my own property called TitleBarHeight, which defines how high on the form the cursor has to be to allow movement. Note that I also initialize this property in the Form's constructor.




RE: Anyone know how to make a borderless form draggable in c#? - 0xBB - Nov 20, 2018

Use wpf:

Code
<Window x:Class="GayNamespace.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:local="clr-namespace:GayNamespace"
       mc:Ignorable="d"
       ResizeMode="NoResize"
       MouseDown="Window_MouseDown"
       Title="Gay App" Height="450" Width="697" WindowStyle="None">
   [...]
</Window>

and the Window_MouseDown in your viewmodel event is:

Code
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
   if (e.LeftButton == MouseButtonState.Pressed)
   {
        DragMove();
   }
}



RE: Anyone know how to make a borderless form draggable in c#? - HFDone - Nov 21, 2018

https://hackforums.net/showthread.php?tid=4558018


RE: Anyone know how to make a borderless form draggable in c#? - Nick (Name) - Nov 21, 2018

Your question is answered on the first link when google searching:
http://lmgtfy.com/?q=drag+borderless+form+c%23


RE: Anyone know how to make a borderless form draggable in c#? - passwords - Nov 22, 2018

@ibennz beat me to it.
Use WPF, no one uses Winforms anymore and if you do you're either a skid or a retard
where as one compliments the other pretty nice.

EDIT
Or if you work with legacy stuff at work.
may god bless their souls.

Create a WPF project, set the Windows WindowStyle property to None and add a event for MouseDown and then add a some logic to see wether the LeftMouse button is pressed and if it is just call the DragMove(); function.


RE: Anyone know how to make a borderless form draggable in c#? - Nick (Name) - Nov 22, 2018

(Nov 22, 2018 11:41 AM)NETGuard Wrote:  @ibennz beat me to it.
Use WPF, no one uses Winforms anymore and if you do you're either a skid or a retard
where as one compliments the other pretty nice.

EDIT
Or if you work with legacy stuff at work.
may god bless their souls.

Create a WPF project, set the Windows WindowStyle property to None and add a event for MouseDown and then add a some logic to see wether the LeftMouse button is pressed and if it is just call the DragMove(); function.

I still use WinForms for some, big emphasis on some, projects. Usually only ever use WinForms for simple UI applications. I do enjoy WPF a lot more than WinForms for theming.


RE: Anyone know how to make a borderless form draggable in c#? - passwords - Nov 22, 2018

(Nov 22, 2018 11:52 AM)Nick (Name) Wrote:  I still use WinForms for some, big emphasis on some, projects. Usually only ever use WinForms for simple UI applications. I do enjoy WPF a lot more than WinForms for theming.

Not only for theming but think about MVVM, databinging etc.
Just makes it so much easier to maintain, I do get that some people still use Winforms though, I personally think they should scrap it, they obviously can't due to the massive amount of companies running on legacy.