日期:2014-05-17  浏览次数:21173 次

怎样让c#中的程序在设计模式下进行调试执行

怎样让c#中的程序在设计模式下进行调试执行

在设计系统时,一般需要运行中进行调试执行,我记得过去看过一个在设计模式下就可以执行Button_Click事件下的例子。
请大虾能能否指点下,或给个例子

Tks!

------解决方案--------------------
You need to override the designer's GetHitTest() method, so the designer can route the click event to your control:

C# code

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;                             //<---

namespace WindowsFormsApplication1
{
    [Designer(typeof(MyDesigner))]                             //<---
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if( this.DesignMode )
            {
                MessageBox.Show("Click in design mode");
            }
        }
    }

    class MyDesigner : ControlDesigner
    {
        protected override bool GetHitTest(Point point)         //<---
        {
            point = this.Control.PointToClient(point);
            foreach (Control c in this.Control.Controls)
            {
                if (c.Bounds.Contains(point))
                {
                    return true;
                }
            }
            return base.GetHitTest(point);
        }
    }
}

------解决方案--------------------
探讨
You need to override the designer's GetHitTest() method, so the designer can route the click event to your control:


C# code
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design; //<---

namespace WindowsFormsApplication1
{
[Designer(typeof(MyDesigner))] …

------解决方案--------------------
探讨
You need to override the designer's GetHitTest() method, so the designer can route the click event to your control:


C# code
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design; //<---

namespace WindowsFormsApplication1
{
[Designer(typeof(MyDesigner))] …

------解决方案--------------------
探讨
在需要调试的代码部分插入断点,然后再按F5键就进入的调试模式!

------解决方案--------------------
探讨
You need to override the designer's GetHitTest() method, so the designer can route the click event to your control:


C# code
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design; //<---

namespace WindowsFormsApplication1
{
[Designer(typeof(MyDesigner))] …

------解决方案--------------------
实际上可以不用F5就可以调试滴

可以直接在即时窗口里,动态new一个对象,然后就可以直接调用这个对象的方法

不过这种东西对无界面的纯逻辑代码比较好,而带事件的UI,这种方式就有问题了,因为少了鼠标交互,所以一些与客户交互性的代码比较难验证
------解决方案--------------------
仔细看了下,代码目的不一样,再试了下,你的代码是对的。。。。