How to debug winform userControl in designer with dotnet 6?

昌杰 王 21 Reputation points
2022-11-11T06:38:36.097+00:00

I want to know how to debug winform userControl in design time?

  1. dotnet sdk version:6.0.403;
  2. IDE:Visual Studio 2022 community 17.3.0;
  3. as the document say,as fallow:
    259376-image.png
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,825 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 31,196 Reputation points Microsoft Vendor
    2022-11-24T07:05:53.017+00:00

    Hi @昌杰 王 , Welcome to Q&A.

    From my testing, this document works fine for .Net 6.

    Both my library files and project are .Net 6

    My steps:

    • Create a .Net 6 usercontrol library file and modify the design of UserControl1.
    • Add the following code to the class: private string demoStringValue = null;
      [Browsable(true)]
      public string DemoString
      {
      get
      {
      return this.demoStringValue;
      }
      set
      {
      demoStringValue = value;
      }
      }
    • Build library files.
    • Add a breakpoint to the property.
    • Modify the startup item of the project to the current project.

    263708-image.png

    • Create a new .Net 6 winform project, add the library file to reference.
    • Drag usercontrol1 into design and add a button.
    • Add the following code to the button: private void button1_Click(object sender, EventArgs e)
      {
      userControl12.DemoString = (string)button1.Text;
      MessageBox.Show(userControl12.DemoString);
      }
    • You can see it hit the breakpoint.

    demo2

    Best Regards,
    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. 昌杰 王 21 Reputation points
    2022-11-11T06:43:00.747+00:00