Vb.net 以两种不同的不透明度显示窗体

Vb.net 以两种不同的不透明度显示窗体,vb.net,winforms,opacity,Vb.net,Winforms,Opacity,我的情况是这样的 我有一个表格frmPopup,它有一个面板pnlCtrlHolder。我将使用此窗体作为弹出窗口,并在此面板中显示第三个窗体作为控件 在表格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.SetF

我的情况是这样的

我有一个表格frmPopup,它有一个面板pnlCtrlHolder。我将使用此窗体作为弹出窗口,并在此面板中显示第三个窗体作为控件

在表格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)
在frmPopup中:

Public Sub SetForm(frm as Windows.Forms.Form)
pnlCtrlHolder.Controls.Clear()
pnlCtrlHolder.Controls.add(frm)
End Sub
现在我的问题是, 这使得整个表单的frmContent的不透明度为60,但我只需要在frmPopup上使用它,而不需要在frmContent上使用它

我正在开发vb.net Winforms应用程序。我知道我正在一个不透明为60的窗体上添加一个窗体作为控件。但是有没有办法达到预期的效果。我错过什么了吗

那么:

dim frm as New frmPopup   
frm.Opacity=60
Dim frmContent as New frmContent
frmContent.Opacity=100

对不起,我的意思是不透明度是介于0和1之间的值

我知道这很有效,因为我刚刚试过。:-)

试试这样的方法:>>

dim frm as New frmPopup   
frm.Opacity=0.6
Dim frmContent as New frmContent
frmContent.Opacity=1

如果您试图设置放置在面板中的窗体的不透明度,那么它看起来不会显示,抱歉

向新项目添加2个表单和一个面板,然后尝试此操作:>>

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
我正在开发vb.net Winforms应用程序。我知道我是 在不透明度为60的窗体上添加窗体作为控件。但是有吗 任何达到预期结果的方法。我错过什么了吗

我自己也试过了,没有你想要的效果

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

嗨,约翰,我的意思和你写的一样。感谢您的回复,但这不起作用。很抱歉,我想写:>>将frm作为新frmPopup frm进行调整。不透明度=0.6将frm内容调整为新frmContent frmContent。不透明度=1DIM frm作为frmPopup是一个声明。下一条语句无法工作,因为frm为NOTHING。发布更多代码,因为这段代码无法编译。错误:frm在分配值之前使用。运行时可能会导致空引用异常。此代码无法按发布方式工作,必须将窗体的TopLevel属性设置为false,然后才能将其视为子窗口。在这一点上,它也不再可能修补不透明性,这只适用于顶级窗口。这不是最终的代码,但只是一个概念进入。这可能有几个语法错误。为什么要使用“窗体作为控件”您可能只需要创建一个usercontrol我想创建类似“Lightbox”的东西。我必须使用它,因为这是一个实际的表单,包含一组不同的逻辑,这取决于用户的响应。如果您有更好的想法,请建议我。在frm上添加一个面板,并在该面板中设置frm内容。结果将是一个窗体作为弹出窗口,面板中添加frm内容,frm的不透明度为0.6。请试试这个,然后联系我。你如何设置面板中的FRM内容?您正在使用SetParent API调用吗?三种不同的答案?你应该用最新的信息编辑你的原始答案。对于LarsTech,请原谅,我还不太习惯这些论坛。
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