Hi Vipkid,
You can use an ordinary form to show a partly transparent rectangle in front of the web browser. You need to set various properties of the form to make it work well. If the user can move/resize the form, code the forms Move and Resize events to keep them aligned; otherwise set the bounds in a similar way in the Load event. The following code goes on the form (Form1) which hosts the web browser (WebBrowser1):
You only need the WithEvents keyword if you want to do something with frm's events, for example the Click event.vb.net Code:
Private WithEvents frm As New Form With _ {.FormBorderStyle = Windows.Forms.FormBorderStyle.None, .Owner = Me, _ .StartPosition = FormStartPosition.Manual, .Visible = False, _ .ShowInTaskbar = False, .BackColor = Color.Gray, .Opacity = 0.6} Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If frm.Visible Then frm.Hide() Else frm.Show(Me) End If End Sub Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move, Me.Resize frm.Bounds = RectangleToScreen(WebBrowser1.Bounds) End Sub
@jmcilhinney. John, I never see anyone else recommending forms for solving this kind of transparency problem. Is there some good reason for not doing so?
BB




Reply With Quote