Transparent control in translucent window overlaying a webbrowser control

I have implemented a layered form setup similar to the solution from Idle_Mind linked  below:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23980050.html?sfQueryTermInfo=1+10+overlai+window#notices

I have set a panel in the form Glass, using the transparent color from Glass to "cut a hole" in the Glass so I can click into the Webbrowser in the underlying Exhibit form, but the click does not pass through to the browser control, it is intercepted by the Exhibit form holding the browser control as I see Exhibit_Click being activated, but no action from the browser.  I have tried many variations, but need to keep the ordering of the Glass and the Exhibit forms fixed.  The solution so far provides me with move/resize/minimize/restore and maintains the order, but has something funny with the transparency operation.  I have done separate forms with the same functionality, but I suspect it may be related to focus fiddling.
Public Class Exhibit
 
    Private Glaze As Glass
    Public Sub New()
        InitializeComponent()
        Glaze = New Glass(Me)
        Me.Show()
        Glaze.Show()
 
    End Sub
 
    Private Sub Exhibit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        Debug.Print("Exhibit_Click")
    End Sub
 
    Private Sub Exhibit_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Glaze.Close()
    End Sub
 
 
    Private Sub Exhibit_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
        If Not IsNothing(Glaze) Then
            Glaze.FocusGrab()
        End If
    End Sub
 
    Private Sub Exhibit_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
        If Not IsNothing(Glaze) Then
            Glaze.FocusGrab()
        End If
    End Sub
 
    Private Sub Exhibit_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Glaze.Hide()
        Else
            If Not IsNothing(Glaze) Then
                Glaze.Show()
                Glaze.FocusGrab()
            End If
        End If
    End Sub
 
    Private Sub Exhibit_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Glaze.FocusGrab()
    End Sub
End Class
 
Public Class Glass
 
    Inherits System.Windows.Forms.Form
 
    Private WithEvents frm As Exhibit
    Private Glazed As Exhibit
 
    Public Sub New(ByVal FormToGlaze As Exhibit)
        InitializeComponent()
        'Me.StartPosition = FormStartPosition.Manual
        Me.frm = FormToGlaze
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.ShowInTaskbar = False
        Glazed = FormToGlaze
        Me.TopMost = True
    End Sub
 
    Public Sub FocusGrab()
        If Not IsNothing(frm) Then
            Me.Size = frm.ClientRectangle.Size
            Me.Location = frm.PointToScreen(New Point(0, 0))
            Me.BringToFront()
        End If
    End Sub
 
    Private Sub Glass_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        Me.TopMost = False
    End Sub
 
    Public Sub Glass_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
        FocusGrab()
    End Sub
 
    Private Sub Glass_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Not IsNothing(frm) Then
            If Me.WindowState = FormWindowState.Minimized Then
                frm.Hide()
            Else
                frm.Show()
                FocusGrab()
            End If
        End If
    End Sub
 
End Class

Open in new window

MarkBottomleyAsked:
Who is Participating?
 
MarkBottomleyAuthor Commented:
The following appears to be doing what I want so it may be considered a solution?!  Exhibit contains a Browser Control. I can draw a panel in the TransparencyKey colour and it provides an active hole to the Exhibit. I can also set the Glass transparency value and observe the Browser Control underneath. The Glass form stays on top and moves/resizes/hides with the Exhibit.  I have stripped the code down to it's basics to cover the specific problem. It could benefit from Object Orientation with instances instead of specific classes, but this is all I need for now.  The InitializeExhibit is currecnly called from a button click, but could just as easily be in the Form Load function.


Public Class Exhibit
 
    Private Function InitializeExhibit() As Boolean
        Me.Cursor = Cursors.WaitCursor
        Browser.navigate("http://www.google.com")
        Glass.Glaze()
        Me.Cursor = Cursors.Default
        Return True
    End Function
 
    Private Sub Exhibit_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
        If Not IsNothing(Glass) Then
            Glass.Location = Me.PointToScreen(New Point(0, 0))
        End If
    End Sub
 
    Private Sub Exhibit_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Glass.Hide()
        Else
            Glass.Show()
            Glass.Location = Me.PointToScreen(New Point(0, 0))
            Glass.Size = Browser.Size
        End If
    End Sub
 
End Class
 
 
Public Class Glass
 
    Public Sub Glaze()
        Me.Show()
        Me.Location = Exhibit.PointToScreen(New Point(0, 0))
        Me.Size = Exhibit.Browser.Size
        Me.Owner = Exhibit
    End Sub
 
End Class

Open in new window

0
 
MarkBottomleyAuthor Commented:
I tried a different trick to get 2 forms overlayed by placing them inside an MDIParent, but once they become MDIChild forms they do not appear to support any Opacity or Transparency Key values.  Please confirm? (It is annoying...)
0
 
Bob LearnedCommented:
I can't confirm 100%, but MDI forms act very differently from the same non-MDI forms.  There are ways around using MDI forms.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
MarkBottomleyAuthor Commented:
It appears that the main problem in the first part of the question is the assigning of focus to the Glass form causes the Exhibit form to act funny in the click through mode.  Without focus on Exhibit, it won't propagate to the WebBrowser control.

I also agree that the MDI forms are useless for this purpose.
0
 
Bob LearnedCommented:
Can you describe how you are using MDI forms?  I can think of another possibility, but I need to make sure how the forms interact.
0
 
MarkBottomleyAuthor Commented:
My goal is to have 2 forms overlapped and locked together.  This means they resize/move/hide/show together.  The other requirements are that the 2 forms are locked together in z-order - i.e. another window cannot appear between the 2 forms and the translucent for is always on top.  I am using the top form to intercept input to the lower form for verification and control so it is translucent to allow the lower form to be viewed.  I will also occasionally create a transparent "hole" in the upper form to allow access to some specific portion of the lower form while maintaining the z-order.  Hopefully that explains my goals.  I was trying to use the MDI configuration to have the parent form be the back form and the MDI Child be the translucent form covering a portion of the MDI Parent Client area (containing a WebBrowser control in particular)  However MDI is not a requires part of the solution, just another attempt to layer forms and access both Transparent and Translucent features.
0
 
Bob LearnedCommented:
You can always add a Form to another Form, but you need to do a little work, without using an MDI parent.

Example:


Public Class ParentForm
    Inherits Form
 
    Private m_child As ChildForm = Nothing
 
    Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
 
        m_child = New ChildForm()
        m_child.TopLevel = False
 
        m_child.TransparencyKey = Color.Magenta
        m_child.Location = New Point(50, 50)
        m_child.Size = New Size(Me.ClientSize.Width \ 2, Me.ClientSize.Height \ 2)
 
        Me.Controls.Add(m_child)
    End Sub
 
End Class
 
Public Class ChildForm
    Inherits Form
 
End Class

Open in new window

0
 
MarkBottomleyAuthor Commented:
I played with your solution, but as soon as you place a form in a form as a control, TransparencyKey and Opacity cease to work although it does achieve the repositioning and z-order features.  I turned m_child.BackColor = Color.Magenta and it failed to show anything underneath including a button I place on the parent form.  I don't know whether this has an easy solution.  I have tried many variations of form stacking and mixing of BringToFront/SendToBack/TopMost to no full solution yet.  The cross calling of focus related actions between the forms can also cause flickering and occasional infinite looping.  I'm still trying things at my end.
0
 
Bob LearnedCommented:
Can you show me your current experimentation (if possible), so that I can test?
0
 
Bob LearnedCommented:
If it works, go with it...
0
 
MarkBottomleyAuthor Commented:
TheLearnedOne's guidance was helpful in setting the direction for finding a successful solution - previously referenced Idle_Mind's implementation was also useful - would give points there if I knew how.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.