如何调试Winforms Designer [英] How to debug winforms designer

查看:99
本文介绍了如何调试Winforms Designer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题不是在设计期间如何调试。我实际上想调试设计器中可用的事件。我知道表单有负载和其他类型的事件。 Windows窗体设计器中是否有任何事件,例如init,load等?

My question is not how to debug during design time. I actually want to debug through the events available in designer. I know that the form has load and other type of events. Is there any events in windows forms designer like init, load, etc ?

我已经通过用户控件在ASP中进行了类似的调试。它允许我们在将用户控件的输出HTML添加到设计器之前对其进行查看。

I have done a similar debugging in ASP through user controls. It allows us to view the output HTML of a user control before adding it to the designer.

我知道Windows窗体和ASP有所不同,但应该检查一些事件

I know windows forms and ASP are different but there should be some event to check values of Controls before actually rendering it.


我的表单需要很长时间才能在VS设计器中打开。因此,我在Visual Studio(devenv.exe)上附加了
调试器,在窗体的
InitializeComponent中设置一个断点以逐步解决问题,以了解问题所在。
但是,断点没有被击中。

My Form takes a long time to open in the VS designer. So I attached a debugger to VisualStudio (devenv.exe), set a breakpoint in my Form’s InitializeComponent to step through it to see what the problem is. However, the breakpoint is not getting hit.


推荐答案

发现了一个很老的(将近12年)通过以下堆栈溢出问题 Winforms Designer如何实例化我的表单?

Found a really old(almost 12 years) blog post through the following stack overflow question How does the Winforms Designer instantiate my form?

博客: https://blogs.msdn.microsoft.com/ rprabhu / 2004/12/12 / how-does-the-windows-forms-designer-in-visual-studio-load-a-form /

上面的博客中的一句话引出了我正确的方向

A quote from above blog that points me in the right direction


设计人员实际上并没有实例化Form1。是
创建Form1基类的实例

Well, the designer is not really instantiating Form1 at all. It is creating an instance of the base class of Form1

按照上面的引用,按照以下步骤操作并找到使设计师变慢的代码

As per the above quote, follow the below steps and find the code that makes the designer slow

1)创建一个扩展Form的类并将其添加到您的winforms项目中

1) Create a class that extends Form and add it to your winforms project

public class DebuggableForm : Form
{
    public DebuggableForm()
    {
        //Put your code in InitializeComponent method here.
        //Through line-by-line debugging you can find 
        //which line is making the designer slow
    }
}

2)扩展上述类,而不是直接扩展Form1.cs中的Form。 Form1是表单的名称,请在您的项目中检查相应的表单名称

2) Extend the above class instead of directly extending Form in Form1.cs. Here Form1 is the name of a form, check the appropriate form name in your project

public class Form1: DebuggableForm
{
//Your actual form code
}

3)放置一个断点在步骤1( DebuggableForm

3) Place a breakpoint in the constructor of class created in step-1 (DebuggableForm)

4)中创建的类的构造函数中,将项目附加到VS并在新的VS中打开一个项目

4) Attach your project to another instance of VS and open a project in new VS

5)在新打开的项目中打开form1.cs并再次执行步骤2。

5) Open form1.cs in newly opened project and perform step-2 again.

6)打开设计器或在解决方案资源管理器中双击Form1。在DebuggableForm中的调试器将被击中。

6) Open the designer or double click on Form1 in solution explorer. Your debugger in DebuggableForm will be hit

注意:上述步骤中的Form1.cs是指Windows窗体项目中的窗体。名称可能因您的项目而异

Note: Form1.cs in above steps refer to a form in windows forms project. The name may vary in your project

这篇关于如何调试Winforms Designer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆