I am trying to learn how to draw over a form's border. As an interim I did the following:

  • Added Panel to form and made to size

  • Set the formboder=none and the backcolor = the transparency color on the form so that it is transparent and only the panel is visible

  • Set the Panels background image

  • Used Code to draw the border I want around the panel (basic as it is)


Now, I want to place an image in the center of the border around the panel, and have it half drawn on the form (which is in effect transparent) and half on the panel. It is just not working. I tried to use GDI to draw the image but it would not work right either. Here is what I have so far:
Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = e.Graphics
        Dim img As Image = Nothing
        Try
            img = Image.FromFile("C:\New Folder\GDITest\GDITest\912.gif")
        Catch ex As Exception
        End Try

        If IsNothing(img) Then Exit Sub

        Dim centerX As Integer = CInt((Me.Width / 2) - (img.Width / 2)) 'x coordinate
        Dim centerY As Integer = Panel1.Top - (img.Height / 2) 'y coordinate

        With PictureBox1
            .Parent = Me
            .BackgroundImage = img
            .BackgroundImageLayout = ImageLayout.Stretch
            .BorderStyle = BorderStyle.None
            .Width = img.Width / 2
            .Height = img.Height / 2
            .Left = centerX
            .Top = centerY
        End With

        'This is the GDI stuff that is not working, 
        'it places the image halfway on the panel only
        'so that only half the image is visible.
        'Dim cPoint As New Point(centerX, centerY)
        'g.DrawImage(img, cPoint)
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim g As Graphics = e.Graphics
        Dim w As Integer = Panel1.Width
        Dim h As Integer = Panel1.Height
        'Pen Setup
        Dim OuterBorderPen As New Pen(Color.Black, 2)
        Dim InnerBorderPen As New Pen(Color.Gold, 1)

        'Setup my rectangles
        Dim outerRect As Rectangle = Me.ClientRectangle
        Dim innerRect As New Rectangle(2, 2, w - 5, h - 5)
        Dim innerRect2 As New Rectangle(4, 4, w - 8, h - 8)

        g.DrawRectangle(OuterBorderPen, outerRect)
        g.DrawRectangle(InnerBorderPen, innerRect)
        g.DrawRectangle(OuterBorderPen, innerRect2)
        'Tried to use this to make the image come to the forefront.
        Panel1.SendToBack()
    End Sub