0

My situation is something like this.

I have a form as frmPopup which has a panel as pnlCtrlHolder. I'll using this form a popup and display a third form as control in this panel.

on form X.

dim frm as frmPopup
''Set the properties for this frmPopup
frm.Opacity=60

Dim frmContent as frmContent
''Set the properties for this frmPopup
frm.Opacity=100

frm.SetForm(frmContent)
frm.ShowDialog(me.toplevelControl)

In frmPopup:

Public Sub SetForm(frm as Windows.Forms.Form)
pnlCtrlHolder.Controls.Clear()
pnlCtrlHolder.Controls.add(frm)
End Sub

Now my problem, This makes entire form with frmContent with opacity =60, but I need this only on frmPopup but not on frmContent.

I am working on vb.net Winforms application. I understand that I am adding a form as control on a form with opacity as 60. But is there any way to achieve the desired result. . Am i missing something?

Raj Jayaswal
  • 468
  • 1
  • 9
  • 22
  • This code cannot work as posted, a form's TopLevel property must be set to false before you can treat it like a child window. At which point it also stops being possible to tinker with Opacity, that only works for top level windows. – Hans Passant Aug 16 '11 at 12:35
  • This is not the final code but just a concept to get into. This might have several syntax error in it. – Raj Jayaswal Aug 16 '11 at 13:43
  • Why are you using 'a form as control' you should probably just create a usercontrol – Matt Wilko Aug 16 '11 at 13:55
  • I want to create something like "Lightbox". I have to use this becuase this is an actual form containing a different set of logics depending on user's response. Please suggest me if you have a better idea. – Raj Jayaswal Aug 16 '11 at 14:09

3 Answers3

0

How about:

dim frm as New frmPopup   
frm.Opacity=60
Dim frmContent as New frmContent
frmContent.Opacity=100
Kev
  • 118,037
  • 53
  • 300
  • 385
  • Hi John, I meant the same what you have written. Thanks for replying but this is not working. – Raj Jayaswal Aug 16 '11 at 11:56
  • Sorry I meant to write:>> dim frm as New frmPopup frm.Opacity = 0.6 Dim frmContent as New frmContent frmContent.Opacity = 1 – John Anthony Oliver Aug 16 '11 at 12:13
  • DIM frm as frmPopup is a declaration. The next statement cannot work as frm is NOTHING. Post more code, as this piece does not compile. error: frm is used before it has been assigned a value. A Null reference exception could result at runtime. – Martin Aug 16 '11 at 12:23
0

Sorry I meant OPACITY is a value between zero and one.

I know this works as I've just tried it. :-)

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.Opacity = 1
        Dim newForm As New Form
        newForm.Text = "NewForm"
        newForm.Opacity = 0.6
        newForm.Show()

    End Sub

End Class

Try something like this:>>

dim frm as New frmPopup   
frm.Opacity=0.6
Dim frmContent as New frmContent
frmContent.Opacity=1
  • add a panel on frm and set the frmContent in that panel. Result will be a form as popup with frmContent added to its panel and frm will have opacity as 0.6. Try this and then get to me please. – Raj Jayaswal Aug 16 '11 at 13:46
  • How are your setting frmContent in a Panel? Are you using the SetParent API call? – John Anthony Oliver Aug 16 '11 at 15:13
0

If you are trying to set the opacity of a Form that you put in a Panel then it doesn't look like it will show, sorry.

Add 2 Forms and one Panel to a new PROJECT and try this please:>>

Option Strict On
Option Explicit On
Option Infer Off

Public Class Form1

    Public Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    Friend WithEvents someForm As New Form2

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

        someForm.Show()
        someForm.BackColor = Color.White
        someForm.Opacity = 1
        'System.Threading.Thread.Sleep(2000)
        SetParent(someForm.Handle, Panel1.Handle)

    End Sub

End Class

I am working on vb.net Winforms application. I understand that I am adding a form as control on a form with opacity as 60. But is there any way to achieve the desired result. . Am i missing something?

I even tried that myself like this without the effect you are after.

Option Strict On
Option Explicit On
Option Infer Off

Public Class Form1

    Friend WithEvents frmPopUp As New Form

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

        frmPopUp.Opacity = 0.6
        frmPopUp.TopLevel = False
        frmPopUp.Text = "frmPopUp"
        Me.Controls.Add(frmPopUp)
        frmPopUp.Show()

    End Sub

End Class