none
When moving borderless window, lines appear on form - VB.NET RRS feed

  • Question

  • Hi everyone!

    I'm trying to create a custom form (borderless). Unfortunately I have 2 chunks of code interfering with one another:

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
            ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.FromArgb(64, 64, 64), ButtonBorderStyle.Solid)
        End Sub

    and...

        Private Sub Panel2_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel2.MouseDown
            drag = True
            mousex = Windows.Forms.Cursor.Position.X - Me.Left
            mousey = Windows.Forms.Cursor.Position.Y - Me.Top
        End Sub
    
        Private Sub Panel2_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel2.MouseMove
            If drag Then
                Me.Top = Windows.Forms.Cursor.Position.Y - mousey
                Me.Left = Windows.Forms.Cursor.Position.X - mousex
            End If
        End Sub
    
        Private Sub Panel2_MouseUp(sender As Object, e As MouseEventArgs) Handles Panel2.MouseUp
            drag = False
        End Sub

    As you can see, the first code block is intended to draw a darker border around panel1 (which is the main window). The second block of code is intended to, when holding the mouse down on the titlebar (panel2), move the window about. However, when I move the window outside of the screen, the drawn borders from the first block are then painted onto the main panel.

    Here's a picture: http://tinypic[DOT]com/r/10z5nio/9

    This was from moving the window diagonally to the bottom right of the screen outside of the screen.

    I hope I make sense and thanks so much for any help! :)

    Thanks,

    Arrd

    Friday, October 20, 2017 11:49 PM

Answers

  •  Don`t use the ClipedRectangle of the panel's PaintEventArgs,  instead use a rectangle that is the size of the Panel like this...

        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
            ControlPaint.DrawBorder(e.Graphics, New Rectangle(0, 0, Panel1.Width, Panel1.Height), Color.FromArgb(64, 64, 64), ButtonBorderStyle.Solid)
        End Sub
    


    If you say it can`t be done then i`ll try it

    Saturday, October 21, 2017 12:28 AM

All replies

  • Hi

    Would this help

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim drag As Boolean = False
        Dim mousex As Integer = 0
        Dim mousey As Integer = 0
        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
            '    ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.FromArgb(64, 64, 64), ButtonBorderStyle.Solid)
            Dim p As New Pen(Brushes.Black, 2)
            e.Graphics.DrawRectangle(p, Panel1.ClientRectangle)
        End Sub
        Private Sub Panel2_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel2.MouseDown
            drag = True
            mousex = Cursor.Position.X - Left
            mousey = Cursor.Position.Y - Top
        End Sub
        Private Sub Panel2_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel2.MouseMove
            If drag Then
                Top = Cursor.Position.Y - mousey
                Left = Cursor.Position.X - mousex
            End If
        End Sub
        Private Sub Panel2_MouseUp(sender As Object, e As MouseEventArgs) Handles Panel2.MouseUp
            drag = False
        End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    Saturday, October 21, 2017 12:14 AM
  •  Don`t use the ClipedRectangle of the panel's PaintEventArgs,  instead use a rectangle that is the size of the Panel like this...

        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
            ControlPaint.DrawBorder(e.Graphics, New Rectangle(0, 0, Panel1.Width, Panel1.Height), Color.FromArgb(64, 64, 64), ButtonBorderStyle.Solid)
        End Sub
    


    If you say it can`t be done then i`ll try it

    Saturday, October 21, 2017 12:28 AM
  • It worked thank you!!
    Saturday, October 21, 2017 12:30 AM
  • It worked thank you!!

     You're Welcome.  8)

    If you say it can`t be done then i`ll try it

    Saturday, October 21, 2017 12:38 AM