展开全部
不就是拖拽图形节点么,对于经常做图像开发的程序员应该很简单,需要的是MouseDown、MouseMove、MouseUp事件,以及HitTest函数,在MouseMove事件里改变节点的坐标就可以了,上伪代码:
private bool dragging;
private int dragInex = -1;
MouseDown += new MouseEventHandler(frmArrowRender_MouseDown);
MouseMove += new MouseEventHandler(frmArrowRender_MouseMove);
MouseUp += new MouseEventHandler(frmArrowRender_MouseUp);
void frmArrowRender_MouseDown(object sender, MouseEventArgs e)
{
dragInex = HitTestPoint(e.Location);
if (dragInex >= 0)
{
dragging = true;
Cursor = Cursors.Hand;
}
}
void frmArrowRender_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
switch (dragInex)
{
case 0:
arrow.Head = e.Location;
break;
case 1:
arrow.TailMiddle = e.Location;
break;
case 2:
arrow.TopMiddle = e.Location;
break;
case 3:
arrow.Middle = e.Location;
break;
case 4:
arrow.TailLeft = e.Location;
break;
case 5:
arrow.TailRight = e.Location;
break;
default:
break;
}
Invalidate();
}
if (HitTestPoint(e.Location) >= 0)
Cursor = Cursors.Hand;
else
Cursor = Cursors.Default;
}
void frmArrowRender_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
Cursor = Cursors.Default;
}
private int HitTestPoint(Point location)
{
int index = -1;
if (Hit(arrow.Head, location))
index = 0;
else if (Hit(arrow.TailMiddle, location))
index = 1;
else if (Hit(arrow.TopMiddle, location))
index = 2;
else if (Hit(arrow.Middle, location))
index = 3;
else if (Hit(arrow.TailLeft, location))
index = 4;
else if (Hit(arrow.TailRight, location))
index = 5;
return index;
}
private bool dragging;
private int dragInex = -1;
MouseDown += new MouseEventHandler(frmArrowRender_MouseDown);
MouseMove += new MouseEventHandler(frmArrowRender_MouseMove);
MouseUp += new MouseEventHandler(frmArrowRender_MouseUp);
void frmArrowRender_MouseDown(object sender, MouseEventArgs e)
{
dragInex = HitTestPoint(e.Location);
if (dragInex >= 0)
{
dragging = true;
Cursor = Cursors.Hand;
}
}
void frmArrowRender_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
switch (dragInex)
{
case 0:
arrow.Head = e.Location;
break;
case 1:
arrow.TailMiddle = e.Location;
break;
case 2:
arrow.TopMiddle = e.Location;
break;
case 3:
arrow.Middle = e.Location;
break;
case 4:
arrow.TailLeft = e.Location;
break;
case 5:
arrow.TailRight = e.Location;
break;
default:
break;
}
Invalidate();
}
if (HitTestPoint(e.Location) >= 0)
Cursor = Cursors.Hand;
else
Cursor = Cursors.Default;
}
void frmArrowRender_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
Cursor = Cursors.Default;
}
private int HitTestPoint(Point location)
{
int index = -1;
if (Hit(arrow.Head, location))
index = 0;
else if (Hit(arrow.TailMiddle, location))
index = 1;
else if (Hit(arrow.TopMiddle, location))
index = 2;
else if (Hit(arrow.Middle, location))
index = 3;
else if (Hit(arrow.TailLeft, location))
index = 4;
else if (Hit(arrow.TailRight, location))
index = 5;
return index;
}
展开全部
不知道自定义控件怎么做的。
基本原理:
自定义控件添加ifSelected属性。属性的Set方法中,根据数据点位置显示或隐藏小的十字控件(也是自定义的)。
十字控件的移动之后,修改数据点的值,拖拽操作就简单了,标准代码很多。
你可以在自定义控件中保留十字控件列表,也可以每次进入编辑模式是,按数据点来New控件,还可以直接把数据点和十字控件封装为一个类,自定义控件中保留类实例的列表。
基本原理:
自定义控件添加ifSelected属性。属性的Set方法中,根据数据点位置显示或隐藏小的十字控件(也是自定义的)。
十字控件的移动之后,修改数据点的值,拖拽操作就简单了,标准代码很多。
你可以在自定义控件中保留十字控件列表,也可以每次进入编辑模式是,按数据点来New控件,还可以直接把数据点和十字控件封装为一个类,自定义控件中保留类实例的列表。
追问
HIT函数,和arrow都没有定义,有没有哪位大神能再帮小弟一把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询