说明:form1移动鼠标,在form2显示鼠标在form1范围内移动的坐标
委托类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public delegate void reveciveDelegate(int i, bool f, MouseEventArgs e);
public class DelClass
{
public static void grawAction(reveciveDelegate re)
{
Form1.reevent += delegate (int i, bool f, MouseEventArgs e)
{
re(i, f, e);
};
}
}
}
Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public static event reveciveDelegate reevent;
public Form1()
{
InitializeComponent();
Form2 f = new Form2();
f.Show();
}
public void Form1_MouseMove(object sender, MouseEventArgs e)
{
reevent(10,false, e);
}
}
}
Form2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
draw();
}
private void draw()
{
DelClass.grawAction((i,f,e)=> {
this.label1.Text = e.X + "," + e.Y + " ";
});
}
}
}
c#委托参考示例
最新推荐文章于 2024-04-17 08:59:55 发布