MouseMove에서 사용자 지정 이벤트를 발생시키는 사용자 지정 컨트롤 인스턴스가 몇 개 있습니다. 여기에 코드입니다 : 있는 EventArgs 클래스 :"전역"WinForms 이벤트
public class GroupMoveEventArgs
{
public enum Action { CalcOffset, Move };
Action action;
int mouse_x;
int mouse_y;
// setters missed here
public GroupMoveEventArgs(GroupMoveEventArgs.Action action,
int mouse_x, int mouse_y)
{
this.action = action;
this.mouse_x = mouse_x;
this.mouse_y = mouse_y;
}
}
제어 클래스 :
public delegate void GroupMoveEventHandler(object sender, GroupMoveEventArgs e);
public event GroupMoveEventHandler GroupMoveEvent;
protected virtual void figureMouseMove(object sender, MouseEventArgs e)
{
if (mouseDown)
{
if (inGroup)
{ // raising the event
if (this.GroupMoveEvent != null)
GroupMoveEvent(this, new GroupMoveEventArgs(
GroupMoveEventArgs.Action.Move,
Parent.PointToClient(Control.MousePosition).X,
Parent.PointToClient(Control.MousePosition).Y));
}
}
}
protected virtual void OnGroupMoveEvent(object sender, GroupMoveEventArgs e)
{
Console.WriteLine("Got mouse move event " + this.num_of_points);
if (inGroup)
{
if (e.EventAction == GroupMoveEventArgs.Action.Move)
{
Location = new Point(e.MouseX - offset.X, e.MouseY - offset.Y);
}
else
if (e.EventAction == GroupMoveEventArgs.Action.CalcOffset)
{
Control c = sender as Control;
Point pnt = Parent.PointToClient(Control.MousePosition);
Point tmp = c.Location;
offset.X = pnt.X - tmp.X;
offset.Y = pnt.Y - tmp.Y;
}
}
}
문제는 내가 이벤트를 발생시킬 때, 내가 모든 컨트롤을 필요로 할 때, 오직 송신자에 의해 처리되고 있다는 것입니다 그것을 처리합니다. 어떻게해야합니까?
미리 감사드립니다. Ivan.
은 모두 같은 양식의 이러한 컨트롤입니까? –
예, 같은 양식에 있습니다. –
텍스트 상자 컨트롤이이 이벤트에 관심을 가질 수있는 방법을보기가 어렵습니다. 일반적으로 폼에는 이벤트 핸들러가 있어야하며 컨트롤에 관심이있는 모든 메서드를 호출해야합니다. –