Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Transparent control in translucent window overlaying a webbrowser control

Posted on 2009-05-01
11
Medium Priority
?
1,203 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:MarkBottomley
  • 6
  • 5
11 Comments
 

Author Comment

by:MarkBottomley
ID: 24287638
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24292195
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
 

Author Comment

by:MarkBottomley
ID: 24292388
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 24297316
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
 

Author Comment

by:MarkBottomley
ID: 24297474
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 24297544
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
 

Author Comment

by:MarkBottomley
ID: 24298247
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24299783
Can you show me your current experimentation (if possible), so that I can test?
0
 

Accepted Solution

by:
MarkBottomley earned 0 total points
ID: 24300884
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24301245
If it works, go with it...
0
 

Author Comment

by:MarkBottomley
ID: 24301438
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

581 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