111,131
社区成员
发帖
与我相关
我的任务
分享
public class Test{//你的自定义类
public delegate void XXXEventHandler(object obj,XXXEventArgs e);
public event XXXEventHandler XXX;//XXX是事件名字
protected virtual void OnXXX(XXXEventArgs e){
if (this.XXX != null) this.XXX(e);
}
//在你需要输出日志的地方
this.OnXXX(new XXXEventArgs("your log"));
public class XXXEventArgs : EventArgs{
private string _Text;
public string Text{
get{ return _Text; }
}
public XXXEventArgs(string strText){
this._Text = strText;
}
}
}
//====调用
Test t = new Test();
t.XXX += new XXXEventHandler(test_XXX);
private void test_XXX(object obj,XXXEventArgs e){
//这里事件会被触发自己YY吧
}
不是让你的类去调用窗体 而是应该在你类里面提供一个事件 让别的东西来绑定
[DllImport("kernel32.dll")]
public static extern IntPtr AllocConsole();
然后调用 AllocConsole() 就可以弹出控制台窗口了
然后程序里面 直接用
Console.Wr....就可以了
