Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net Form BackGroundImage not showing in borderless customized form

Posted on 2012-04-06
2
Medium Priority
?
479 Views
Last Modified: 2012-04-06
Hi

In this code, which resides in the much larger piece of code shown below it I am building a bordeless moveable custom form but the background image does not show. Not sure how to remedy this.

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        FormBorderStyle = FormBorderStyle.None

        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        BackColor = Color.Transparent

        BackgroundImage = My.Resources.BackBlue

        DoubleBuffered = True
        ' Opacity = 0.9
    End Sub




Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Public Class Form1
    ' Set the thickness of the virtual form border that should catch the resizing
    ' If below 1, the resize function does not work!
    Private VIRTUALBORDER As Integer = 4
    Private SHOWVIRTUALBORDERS As Boolean = True

    ' Declare the limits for the form size
    Private MINHEIGHT As Integer = 10
    Private MAXHEIGHT As Integer = 300
    Private MINWIDTH As Integer = 20
    Private MAXWIDTH As Integer = 600


    Private RESIZESTART As Point
    Private RESIZEDESTINATION As Point
    Private MOUSEPOS As Point

    ' Define Rectangles & Booleans for all 9 + 1 areas of the Form.
    Private R0 As Rectangle
    Private R1 As Rectangle
    Private R2 As Rectangle
    Private R3 As Rectangle
    Private R4 As Rectangle
    Private R5 As Rectangle
    Private R6 As Rectangle
    Private R7 As Rectangle
    Private R8 As Rectangle
    Private R9 As Rectangle


    ' Bool to determine if the form is being moved (True when the form is clicked in the center area (R5))
    Private ISMOVING As Boolean

    ' Bool to determine if the form is being rezised (True when the form is clicked in all areas except the center (R5))
    Private ISREZISING As Boolean

    ' Bool's to determine in which direction the form is moving
    Private ISRESIZINGLEFT As Boolean
    Private ISRESIZINGRIGHT As Boolean

    Private ISRESIZINGTOP As Boolean
    Private ISRESIZINGBOTTOM As Boolean

    Private ISRESIZINGTOPRIGHT As Boolean
    Private ISRESIZINGTOPLEFT As Boolean

    Private ISRESIZINGBOTTOMRIGHT As Boolean
    Private ISRESIZINGBOTTOMLEFT As Boolean


    '
    '        
    '          
    '          
    '                Y
    '          
    '                |
    '                |
    '                |
    '                |    
    '                |                                                                          
    '   X   ---------|------------------------------------------------------------------------   X
    '                |                                                                          
    '                |    <-------------------------- R0 ----------------------------->
    '                |
    '                |
    '                |    |-----------------------------------------------------------|  
    '                |    | R1 |                      R2                         | R3 |
    '                |    |-----------------------------------------------------------|
    '                |    |    |                                                 |    |
    '                |    |    |                                                 |    |
    '                |    | R4 |                      R5                         | R6 |
    '                |    |    |                                                 |    |
    '                |    |    |                                                 |    |
    '                |    |-----------------------------------------------------------|  
    '                |    | R7 |                      R8                         | R9 |
    '                |    |-----------------------------------------------------------|
    '                |
    '                |
    '                |
    '                |
    '          
    '                Y                                                                                                                          

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        FormBorderStyle = FormBorderStyle.None

        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        BackColor = Color.Transparent

        BackgroundImage = My.Resources.BackBlue

        DoubleBuffered = True
        ' Opacity = 0.9
    End Sub


    Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Select Case e.Button
            Case MouseButtons.Left

                If R1.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGTOPLEFT = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R2.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGTOP = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R3.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGTOPRIGHT = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R4.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGLEFT = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R5.Contains(MOUSEPOS) Then
                    ' If the center area of the form is pressed (R5), then we should be able to move the form.
                    ISMOVING = True
                    ISREZISING = False
                    MOUSEPOS = New Point(e.X, e.Y)
                    Cursor = Cursors.SizeAll
                End If
                If R6.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGRIGHT = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R7.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGBOTTOMLEFT = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R8.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGBOTTOM = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                If R9.Contains(MOUSEPOS) Then
                    ISREZISING = True
                    ISRESIZINGBOTTOMRIGHT = True
                    RESIZESTART = PointToScreen(New Point(e.X, e.Y))
                End If
                Exit Select
        End Select
    End Sub

    Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        RESIZEDESTINATION = PointToScreen(New Point(e.X, e.Y))
        R0 = Bounds

        ' If the form has captured the mouse...
        If Capture Then
            If ISMOVING = True Then
                ISREZISING = False
                ' ISMOVING is true if the R5 rectangle is pressed. Allow the form to be moved around the screen.
                Location = New Point(MousePosition.X - MOUSEPOS.X, MousePosition.Y - MOUSEPOS.Y)
            End If
            If ISREZISING = True Then
                ISMOVING = False

                If ISRESIZINGTOPLEFT Then
                    Bounds = New Rectangle(R0.X + RESIZEDESTINATION.X - RESIZESTART.X, R0.Y + RESIZEDESTINATION.Y - RESIZESTART.Y, R0.Width - RESIZEDESTINATION.X + RESIZESTART.X, R0.Height - RESIZEDESTINATION.Y + RESIZESTART.Y)
                End If
                If ISRESIZINGTOP Then
                    Bounds = New Rectangle(R0.X, R0.Y + RESIZEDESTINATION.Y - RESIZESTART.Y, R0.Width, R0.Height - RESIZEDESTINATION.Y + RESIZESTART.Y)
                End If
                If ISRESIZINGTOPRIGHT Then
                    Bounds = New Rectangle(R0.X, R0.Y + RESIZEDESTINATION.Y - RESIZESTART.Y, R0.Width + RESIZEDESTINATION.X - RESIZESTART.X, R0.Height - RESIZEDESTINATION.Y + RESIZESTART.Y)
                End If
                If ISRESIZINGLEFT Then
                    Bounds = New Rectangle(R0.X + RESIZEDESTINATION.X - RESIZESTART.X, R0.Y, R0.Width - RESIZEDESTINATION.X + RESIZESTART.X, R0.Height)
                End If
                If ISRESIZINGRIGHT Then
                    Bounds = New Rectangle(R0.X, R0.Y, R0.Width + RESIZEDESTINATION.X - RESIZESTART.X, R0.Height)
                End If
                If ISRESIZINGBOTTOMLEFT Then
                    Bounds = New Rectangle(R0.X + RESIZEDESTINATION.X - RESIZESTART.X, R0.Y, R0.Width - RESIZEDESTINATION.X + RESIZESTART.X, R0.Height + RESIZEDESTINATION.Y - RESIZESTART.Y)
                End If
                If ISRESIZINGBOTTOM Then
                    Bounds = New Rectangle(R0.X, R0.Y, R0.Width, R0.Height + RESIZEDESTINATION.Y - RESIZESTART.Y)
                End If
                If ISRESIZINGBOTTOMRIGHT Then
                    Bounds = New Rectangle(R0.X, R0.Y, R0.Width + RESIZEDESTINATION.X - RESIZESTART.X, R0.Height + RESIZEDESTINATION.Y - RESIZESTART.Y)
                End If

                RESIZESTART = RESIZEDESTINATION
                Invalidate()
            End If
        Else

            ' If the form has not captured the mouse; the mouse is just hovering the form...
            MOUSEPOS = New Point(e.X, e.Y)

            ' Changes Cursor depending where the mousepointer is at the form...
            If R1.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeNWSE
            End If
            If R2.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeNS
            End If
            If R3.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeNESW
            End If
            If R4.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeWE
            End If
            If R5.Contains(MOUSEPOS) Then
                Cursor = Cursors.[Default]
            End If
            If R6.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeWE
            End If
            If R7.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeNESW
            End If
            If R8.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeNS
            End If
            If R9.Contains(MOUSEPOS) Then
                Cursor = Cursors.SizeNWSE
            End If
        End If
    End Sub

    Private Sub Form1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        ISMOVING = False
        ISREZISING = False

        ISRESIZINGLEFT = False
        ISRESIZINGRIGHT = False

        ISRESIZINGTOP = False
        ISRESIZINGBOTTOM = False

        ISRESIZINGTOPRIGHT = False
        ISRESIZINGTOPLEFT = False

        ISRESIZINGBOTTOMRIGHT = False
        ISRESIZINGBOTTOMLEFT = False

        Invalidate()
    End Sub


    Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        ' Every time the form paints, set the location and size of the form areas...
        '#Region "DIVIDE THE FORM INTO 9 SUB AREAS"
        R1 = New Rectangle(New Point(ClientRectangle.X, ClientRectangle.Y), New Size(VIRTUALBORDER, VIRTUALBORDER))
        R2 = New Rectangle(New Point(ClientRectangle.X + R1.Width, ClientRectangle.Y), New Size(ClientRectangle.Width - (R1.Width * 2), R1.Height))
        R3 = New Rectangle(New Point(ClientRectangle.X + R1.Width + R2.Width, ClientRectangle.Y), New Size(VIRTUALBORDER, VIRTUALBORDER))

        R4 = New Rectangle(New Point(ClientRectangle.X, ClientRectangle.Y + R1.Height), New Size(R1.Width, ClientRectangle.Height - (R1.Width * 2)))
        R5 = New Rectangle(New Point(ClientRectangle.X + R4.Width, ClientRectangle.Y + R1.Height), New Size(R2.Width, R4.Height))
        R6 = New Rectangle(New Point(ClientRectangle.X + R4.Width + R5.Width, ClientRectangle.Y + R1.Height), New Size(R3.Width, R4.Height))

        R7 = New Rectangle(New Point(ClientRectangle.X, ClientRectangle.Y + R1.Height + R4.Height), New Size(VIRTUALBORDER, VIRTUALBORDER))
        R8 = New Rectangle(New Point(ClientRectangle.X + R7.Width, ClientRectangle.Y + R1.Height + R4.Height), New Size(ClientRectangle.Width - (R7.Width * 2), R7.Height))
        R9 = New Rectangle(New Point(ClientRectangle.X + R7.Width + R8.Width, ClientRectangle.Y + R1.Height + R4.Height), New Size(VIRTUALBORDER, VIRTUALBORDER))
        '#End Region


        '#Region "SET FILL COLORS FOR THE VIRTUAL BORDER"
        If SHOWVIRTUALBORDERS Then
            Dim GFX As Graphics = e.Graphics
            GFX.FillRectangle(Brushes.White, R5)

            GFX.FillRectangle(Brushes.Gold, R1)
            GFX.FillRectangle(Brushes.Gold, R3)
            GFX.FillRectangle(Brushes.Gold, R7)
            GFX.FillRectangle(Brushes.Gold, R9)

            GFX.FillRectangle(Brushes.Blue, R2)
            GFX.FillRectangle(Brushes.Blue, R8)
            GFX.FillRectangle(Brushes.Blue, R4)
            GFX.FillRectangle(Brushes.Blue, R6)
        End If
        '#End Region
    End Sub

    Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
        'CODE TO LIMIT THE SIZE OF THE FORM
        If Height > MAXHEIGHT Then
            Capture = False
            Height = MAXHEIGHT
        End If
        If Height < MINHEIGHT Then
            Capture = False
            Height = MINHEIGHT
        End If
        If Width > MAXWIDTH Then
            Capture = False
            Width = MAXWIDTH
        End If
        If Width < MINWIDTH Then
            Capture = False
            Width = MINWIDTH
        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 37816260
In the Paint() event, it fills the main portion of the form in White!

Comment out this line:

            GFX.FillRectangle(Brushes.White, R5)
0
 

Author Closing Comment

by:Murray Brown
ID: 37816428
Thanks very much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question