摘要: 以前从来没有遇到过这个问题,跨线程访问控件,一般只有赋值的时候单独写委托什么的,但是这次却突然发现居然获取控件的值时,不写委托也会报错。为了防止以后忘掉,咱把方法记下来。/// /// 控件委托帮助类/// public class ControlHelper{ /// /// 跨线程设置控件属性值委托类型定义 /// delegate void SetControlPropertyCallBack(Control control, string name, object value); /// /// 跨线程设置控件属性值 /// pu... 阅读全文
posted @ 2013-03-26 14:53 古兰色回忆 阅读(479) 评论(0) 推荐(0) 编辑
摘要: private void Button_Paint(object sender, PaintEventArgs e){ Button btn = sender as Button; System.Drawing.Drawing2D.GraphicsPath btnPath = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.Rectangle newRectangle = btn.ClientRectangle; newRectangle.Inflate(-1, -1); e.Graphics... 阅读全文
posted @ 2012-11-29 17:53 古兰色回忆 阅读(702) 评论(0) 推荐(0) 编辑
摘要: protected override void OnPaint(System.Windows.Forms.PaintEventArgs e){ GraphicsPath oPath = new GraphicsPath(); int x = 0; int y = 0; int w = Width; int h = Height; int a = 14; Graphics g = CreateGraphics(); oPa... 阅读全文
posted @ 2012-11-29 17:33 古兰色回忆 阅读(810) 评论(0) 推荐(0) 编辑
摘要: int[] array = new int[2000];int fill = 9;ArrayList.Repeat(fill, 2000).CopyTo(array); 阅读全文
posted @ 2012-11-28 10:54 古兰色回忆 阅读(623) 评论(0) 推荐(0) 编辑
摘要: 首先定义一个枚举 /// <summary> /// 枚举注释的自定义属性类 /// </summary> public class EnumDescriptionAttribute : Attribute { private string m_strDescription; public EnumDescriptionAttribute(string strPrinterName) { m_strDescription = strPrinterName; } public... 阅读全文
posted @ 2012-11-23 11:39 古兰色回忆 阅读(5877) 评论(0) 推荐(0) 编辑
摘要: public class 类{ private string _属性; public string 属性 { set { this._属性 = value; } get { return this._属性; } }}public class 执行{ public 执行() { } public void 方法() { 类 实例 = new 类(); object val = 实例.GetType().GetProperty("属性").GetValue(实例, null); }} 阅读全文
posted @ 2012-11-21 17:26 古兰色回忆 阅读(248) 评论(0) 推荐(0) 编辑
摘要: object obj = this.GetType().GetField("控件名称", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); Label lbl = (Label)obj; 阅读全文
posted @ 2012-11-21 17:22 古兰色回忆 阅读(4002) 评论(1) 推荐(2) 编辑
摘要: 使用方法名的字符串,调用该类中的方法。 /// <summary>/// 绘制线性波形/// </summary>public void DrawLinear(){ //实现方法}private void button_click(object sender,EventArgs e){ this.GetType().GetMethod("DrawLinear").Invoke(this, null);}请注意被调用的方法一定要是公用的。 阅读全文
posted @ 2012-11-05 17:01 古兰色回忆 阅读(273) 评论(0) 推荐(0) 编辑
摘要: 刚刚开始做CS项目,对于项目中的应用各种不熟悉。在MDI容器窗体上设置了一个菜单,菜单上每一个按钮可以打开一个子窗体。最初使用的方法是/// <summary>/// 选择面板/// </summary>private static OpenSelect os;private void OpenSelectForm(){ if (os == null || os.IsDisposed) { os = new OpenSelect(); os.MdiParent = this; os.Show(); }}基本上打开每一个窗体都是这个做的... 阅读全文
posted @ 2012-10-18 15:13 古兰色回忆 阅读(510) 评论(0) 推荐(0) 编辑
摘要: 设置窗体出现的具体位置:窗体 form = new 窗体(); form.StartPosition = FormStartPosition.Manual;form.Location = new Point(300, 0);form.Show(); 禁止窗体自由移动:public const int WM_SYSCOMMAND = 0x112;public const int SC_MOVE = 0xF012;protected override void WndProc(ref Message m){ if (m.Msg == WM_SYSCOMMAND) { ... 阅读全文
posted @ 2012-10-16 17:32 古兰色回忆 阅读(3310) 评论(0) 推荐(0) 编辑