"类在winform中的应用的例子"?太抽象,具体我也好给啊

解决方案 »

  1.   

    定义一个类:
    class myclass
    {
    public string addString(string i,string j)
    {
    return i+j;
    }
    }
    在窗体里应用:
    private void button1_Click(object sender, System.EventArgs e)
    {
    myclass my = new myclass();

    MessageBox.Show(my.addString("ok","除了ok不知道还有什么"));
    }
      

  2.   

    public class Father
    {
    public void show(string str)
    {
    MessageBox.Show(str);
    }
    }
    public class Child
    {
     public void show(string str)
    {
    MessageBox.Show("重载后的show方法",str);
    }
    }在窗体load事件里写
    Child c=new Child();
    c.show("楼主看对不对哦,呵呵");
      

  3.   

    我可以在MSN上给你一个。完全的开发事例,不过比较简单。
      

  4.   

    public class MyClass
    {
        private int no;  // 成员
        public int No    // 属性
        {
    get { return no;}
    set { no = value;}
        }
        private string name; // 成员
        public string Name   // 属性
        {
    get { return name;}
    set { name = value;}
        }
        public static string Space(int i) // 静态方法,功能类似VB的Sapce函数
        {
    string str = "";
    if (i > 1) 
        for (int j = 0; j < i; j ++)
    str += ' ';
    return str;
        }
    }// 调用// 调用类的静态方法时,不需要声明类的实例
    MessageBox.Show("我爱" + MyClass.Space(20) + "你"); 
    // 声明类MyClass的实例(对象)mc
    MyClass mc = new MyClass();
    mc.No = 12345;  // 给对象的属性赋值
    mc.Name = "楼主,你好"; // 同上
    MessageBox.Show(mc.No.ToString() + mc.Name);
      

  5.   

    多线程更新RichTextBox
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Threading;namespace FormTest
    {
    //定义代理
    public delegate void RichtextboxAppendtextHandler(string Input); public class MainForm : System.Windows.Forms.Form
    {
    public System.Windows.Forms.RichTextBox richTextBox1;
    private System.Windows.Forms.Button button1;
    private System.ComponentModel.Container components = null; public MainForm()
    {
    InitializeComponent();
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.richTextBox1 = new System.Windows.Forms.RichTextBox();
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // richTextBox1
    // 
    this.richTextBox1.Location = new System.Drawing.Point(24, 44);
    this.richTextBox1.Name = "richTextBox1";
    this.richTextBox1.Size = new System.Drawing.Size(408, 244);
    this.richTextBox1.TabIndex = 0;
    this.richTextBox1.Text = "richTextBox1";
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(324, 12);
    this.button1.Name = "button1";
    this.button1.TabIndex = 1;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // MainForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(496, 325);
    this.Controls.Add(this.button1);
    this.Controls.Add(this.richTextBox1);
    this.Name = "MainForm";
    this.Text = "MainForm";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new MainForm());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.richTextBox1.Clear();
    for (int i=1;i<255;i++)
    {
    ThreadMethod method = new ThreadMethod(i.ToString(),this);
    Thread thScan = new Thread(new ThreadStart(method.ThreadRun)); 
    thScan.Start();  
    }
    }
    public void UpdateRichTextBox(string appendValue)
    {
    this.richTextBox1.AppendText(appendValue);
    }
    }
    public class ThreadMethod
    {
    private string a = string.Empty ;
    private MainForm fm;
    public ThreadMethod(string APart,MainForm myfm)
    {
    this.a = APart;
    this.fm = myfm;
    }
    public void ThreadRun()

    RichtextboxAppendtextHandler myHandler = new RichtextboxAppendtextHandler(this.fm.UpdateRichTextBox);
    for(int i=0;i<10000;i++)
    {
    int vv = i;
    }
    try
    {

    this.fm.richTextBox1.Invoke(myHandler,new object[]{a+"\r"});
    }
    catch(Exception error)
    {
    this.fm.richTextBox1.Invoke(myHandler,new object[]{a+":"+error.Message+"\r"});
    }
    }
    }
    }