开发者

Show a form in two different opacity

开发者 https://www.devze.com 2023-03-28 22:33 出处:网络
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.

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 n开发者_JAVA技巧ot 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?


How about:

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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消