Search code examples
c#draggableborderless

how to make borderless to normalize on drag only in the top of the border


how do i make my borderless form normalize when you are dragging it on the top like you do on browser i had tryed with this

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

         //   if (WindowState == System.Windows.WindowState.Maximized)

           //     WindowState = System.Windows.WindowState.Normal;

        }
    }

but that normalized it all the time no matter where you clicked on the form


Solution

  • you can achieve that by making example a transparent label in the top of the form and then use this

    private void label_MouseDown(object sender, MouseButtonEventArgs e)
    {
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        DragMove();
    
        if (WindowState == System.Windows.WindowState.Maximized)
    
            WindowState = System.Windows.WindowState.Normal;
    
    }
    }