3

私はWindowsアプリケーションが初めてです。C# と .NET で。添付した画像のようなものが欲しいです。ポップアップが開いたら、mdi の親ページをシャドウまたは無効にします。(Web アプリケーションや Jquery ポップアップで行うように)

ここに画像の説明を入力

することは可能ですか?はいの場合、どうすればそれができますか。

助けてください。

4

4 に答える 4

1

これを実現するには、の不透明度プロパティを使用します。これによりWindows.Form 、新しいフォームを作成し、その不透明度を設定して(たとえば、.75)、子ウィンドウを表示しているときはいつでもこれを親の上に表示します。例を以下に示します

There are three windows used here
1. ParentForm
2. OverlayForm
3. ChildForm

1.親フォーム

1. Create an instance of the Child form 
2. Create an Instance of the Overlayform, Pass the objects Instances of Child and Parent(current form) as a parameter to the Constructor
3. Then Show the OverLay Form by using  ShowDialog Method.

Code:

public partial class ParentForm : Form
{
    public ParentForm()
    {

        InitializeComponent();
    }

    private void ParentForm_Load(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        ChildForm child1 = new ChildForm();
        // Create a new form.
        OverlayForm form2 = new OverlayForm(this, child1);
        child1.OverLay = form2;
        // Display the form as a modal dialog box.
        form2.ShowDialog(this);
    }
}

2.オーバーレイフォーム

1. In the constructor store the childForm and ParentForm object in a local variables. 
       And Set the The properties (like width,height) to the Overlay Window
    2. In the OverlayForm_Load show the ChildForm window.

public partial class OverlayForm : Form
{
    public Form ParentForm { get; set; }
    public Form child { get; set; }
    public OverlayForm(Form parent, Form child)
    {
        InitializeComponent();
        this.child = child;
        this.ParentForm = parent;

        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.ShowInTaskbar = false;
        this.Width = ParentForm.Width;
        this.Height = ParentForm.Height;
        this.Top = ParentForm.Top;
        this.Left = ParentForm.Left;
        this.StartPosition = ParentForm.StartPosition;
        // Set the opacity to 75%.
        this.Opacity = .75;
    }

    private void OverlayForm_Load(object sender, EventArgs e)
    {
        child.Show();
        child.TopMost = true;
        child.Focus();
        child.BringToFront();
    }
}

これにより、親フォームがぼやけて見えます。また、子フォームのオーバーレイを閉じるためのコードを作成する必要があります

3.チャイルドフォーム

1. Set the object of the Overlay  to a property in Child Window
2. And in the Form_Closing event of the child window, close the Overlay window.

public partial class ChildForm : Form
{
    //This is set in the Parent form where the child form instatce is created
    public Form OverLay { get; set; }
    public ChildForm()
    {
        InitializeComponent();
    }

    private void ChildForm_Load(object sender, EventArgs e)
    {
    }

    private void ChildForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        this.OverLay.Close();
    }
}
于 2012-07-30T11:10:37.007 に答える
0

Microsoft Windows では、実際には子ウィンドウの概念はありません。ポップアップ、またはモーダル/モードレス ダイアログは、画面上の任意の場所に配置できるという点で他のウィンドウと同じであるため、親ウィンドウとして考えているものの境界の外にある可能性があります。

デスクトップではうまく機能しない Web の概念がいくつかあります。

于 2012-07-30T08:19:56.627 に答える