如何使用RaiseEvent?可以举例说明吗?谢谢!
解决方案 »
- 新手请教!关于示波器程序的编写思路!
- 用try -catch来把访问dll的代码包含起来,而dll的内容有所改变之后,为什么该try-catch块捕捉不到异常?
- 讨论:关于鼠标拖动对象的问题.怎样才能让对象的半透明的"影子"跟着鼠标一起移动?
- 如何实现像rar的拖放功能,要拖放后解压数据的
- 请教高手关于window.location问题
- IT农庄8号群7542065,UP有分
- emf(metafile)输出的矢量图形怎么按比例打印
- ---如何能在C#中一次性关闭所有的MDI子窗体---
- 哪位大神对Chrome_RenderWidgetHostHWND 有所了解吗? 我想获取它的内容 帮帮忙
- 谁知道那里有详细介绍关于c#的数据库方面的书?告诉我几本,谢谢!
- 要用双缓冲做动画,如何在内存里建立Graphics对象?
- 我可以学C#吗?
对于那个Graphics的问题,不知道你还记得吗?我怎么给不了你分数?昨天还看见了编辑框的,今天就没有了。
:)
可以方便的触发一个事件。
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);
}
}
}
我知道怎么回事了。使用 如下的程序:
Graphics g = Graphics.FromHwnd(this.panel1.Handle);
g.DrawLine(...);panel1.Show();这样才可以 把图像显示出来。
我在程序中要触发一个鼠标的 点击事件,鼠标的位置是给定的。
how to?
触发事件,我的意思是指直接调用一个不用参数的public方法吧。如果自己写,我可以写一个。但是,是否每一个事件处理程序都会对应一个简单的不带参数的public method呢。
我想知道就是这个。
(请看别的问题,谢谢)