How do you display a custom UserControl as a dialog?

后端 未结 7 1521
孤街浪徒
孤街浪徒 2020-12-07 15:45

How do you display a custom UserControl as a dialog in C#/WPF (.NET 3.5)?

7条回答
  •  星月不相逢
    2020-12-07 15:59

    I know this is for .net 3.5, but here is a workable solution for .net 2.0

      MyUserControl myUserControl= new MyUserControl();
    
      Form window = new Form
      {
        Text = "My User Control",
        TopLevel = true,
        FormBorderStyle = FormBorderStyle.Fixed3D, //Disables user resizing
        MaximizeBox = false,
        MinimizeBox = false,
        ClientSize = myUserControl.Size //size the form to fit the content
      };
    
      window.Controls.Add(myUserControl);
      myUserControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
      window.ShowDialog();
    

提交回复
热议问题