如何使用RaiseEvent?可以举例说明吗?谢谢!

解决方案 »

  1.   

    RaiseEvent 是VB的keyword,在C#中用什么?
      

  2.   

    http://microrest.home.chinaren.com/class/event.htm看一下这篇文章不知道对你有没有帮助
      

  3.   

    谢谢你。
    对于那个Graphics的问题,不知道你还记得吗?我怎么给不了你分数?昨天还看见了编辑框的,今天就没有了。
    :)
      

  4.   

    你的这篇文章我在.net document上看过。例子是一样的。我想知道的是在C#中,有没有类似RaiseEvent的东东,
    可以方便的触发一个事件。
      

  5.   

    我也不知道怎样才能给你分,呵呵C#面向高端市场,应该没有象RaiseEvent这种简单的东西
      

  6.   

    //昨天告诉你的方法,你不信?!
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication1
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.panel1 = new System.Windows.Forms.Panel();
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // panel1
    // 
    this.panel1.Name = "panel1";
    this.panel1.Size = new System.Drawing.Size(288, 176);
    this.panel1.TabIndex = 0;
    this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(24, 208);
    this.button1.Name = "button1";
    this.button1.TabIndex = 1;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.Location = new System.Drawing.Point(152, 208);
    this.button2.Name = "button2";
    this.button2.TabIndex = 2;
    this.button2.Text = "button2";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 270);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.button2,
      this.panel1,
      this.button1});
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
    Random r=new Random();

    e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(r.Next(255),r.Next(255),r.Next(255))) ,50,50,100,100);
    } private void button1_Click(object sender, System.EventArgs e)
    {
    PaintEventArgs g=new PaintEventArgs(Graphics.FromHwnd(this.panel1.Handle),new Rectangle(0,0,this.panel1.Width,this.panel1.Height));
    panel1_Paint(this.panel1 ,g);
    this.Refresh();
    } private void button2_Click(object sender, System.EventArgs e)
    {
    Random r=new Random();
    Graphics g=Graphics.FromHwnd(this.panel1.Handle);
    g.FillRectangle(new SolidBrush(Color.FromArgb(r.Next(255),r.Next(255),r.Next(255))),50,50,100,100);
    }
    }
    }
      

  7.   

    谢谢CForce,
    我知道怎么回事了。使用 如下的程序:
    Graphics g = Graphics.FromHwnd(this.panel1.Handle);
    g.DrawLine(...);panel1.Show();这样才可以 把图像显示出来。
      

  8.   

    我还想知道如何触发一个 事件,比如,
    我在程序中要触发一个鼠标的 点击事件,鼠标的位置是给定的。
    how to?
      

  9.   

    你要触发一个事件还是使用一个事件的方法?C#里触发事件我没怎么研究,可能要用Api:SendMessage,使用事件的方法,我上面例子已经有了。
      

  10.   

    好了,给分了。
    触发事件,我的意思是指直接调用一个不用参数的public方法吧。如果自己写,我可以写一个。但是,是否每一个事件处理程序都会对应一个简单的不带参数的public method呢。
    我想知道就是这个。
      

  11.   

    我还有一个关于mdi的问题。看可不可以解决。
    (请看别的问题,谢谢)