拖拽矩形的问题

mazhengning188 2012-02-05 10:39:02
我从菜单里拖出两个相同的矩形 我一拖拽第二个就会把第一个消掉了 似乎成同一个矩形了 怎么解决啊
...全文
82 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
MJ_dangerous 2012-02-06
  • 打赏
  • 举报
回复
不介意的话把你代码发我瞧瞧。lw@szcyt.cn
MJ_dangerous 2012-02-06
  • 打赏
  • 举报
回复
绝对是代码有问题嘛!
mazhengning188 2012-02-06
  • 打赏
  • 举报
回复
这是网上找的 你们看看问什么会那样
mazhengning188 2012-02-06
  • 打赏
  • 举报
回复
private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Link ;
}
public DrawRectangle rectangle;
private void panel1_DragDrop(object sender, DragEventArgs e)
{
string itemtype = e.Data.GetData(typeof(string)).ToString();
if (itemtype == "A")
{


Point lefttoppoint = this.PointToScreen(this.panel1.Location);
DrawRectangle objrect = new DrawRectangle(e.X - lefttoppoint.X, e.Y - lefttoppoint.Y, 100, 50);
//objrect.intStatusTypeId = 0;
//objrect.dblStatusId = 1;
objrect.strStatusName = "状态1 ";
rectangle = objrect;

repaint();


}

}

private void toolStripButton1_MouseDown_1(object sender, MouseEventArgs e)
{
toolStrip1.DoDragDrop("A", DragDropEffects.Link );
}




public void drawMouseObjs(MouseEventArgs e, int intEvent)
{


DrawRectangle objrect = rectangle;
switch (intEvent)
{
case 1://mouseDown()
if ( objrect.contains(e.X, e.Y))//按下的鼠标坐标在节点的范围内。
{
Graphics g =panel1 . CreateGraphics();
objrect.last_x = objrect._x - e.X;
objrect.last_y = objrect._y - e.Y;
objrect.isMove = 1;
int x1 = objrect._x;
int y1 = objrect._y;
int w1 = objrect._w;
int h1 = objrect._h;
//Pen penWhite = new Pen(Color.White, 2);
// g.DrawRectangle(penWhite, x1, y1, w1, h1);
//g.FillRectangle(new SolidBrush(Color.White), x1, y1, w1, h1);
// g.FillRectangle(new SolidBrush(Color.White), x1 + 6, y1 + 6, w1, h1); //用白色擦掉画好的节点
//g.DrawRectangle(new Pen(Color.Black), x1, y1, w1, h1);//给节点加个黑边框。代表选中了该节点,可以拖动了。
g.Dispose();
return;
}
break;

case 2://mouseMove()
if ( objrect.isMove == 1)
{
Graphics g = panel1.CreateGraphics();
int x1 = objrect._x;
int y1 = objrect._y;
int w1 = objrect._w;
int h1 = objrect._h;
//g.DrawRectangle(new Pen(Color.White), x1, y1, w1, h1);
//用白色擦掉拖动时上一位置的节点
g.FillRectangle(new SolidBrush(Color.White), 0, 0, this.Width, this.Height);
//g.Clear(panel1.BackColor);
objrect.setLocation(e.X, e.Y);
//int x2 = objrect._x;
//int y2 = objrect._y;
//Pen penBlack = new Pen(Color.Black);
//g.DrawRectangle(penBlack, x2, y2, w1, h1); //在新位置画新的带黑边框的节点
repaint();
g.Dispose();
return;

}
break;
case 3://mouseUp()
if ( objrect.isMove == 1)
{
updateLocation(e, objrect);//更新节点位置
objrect.isMove = 0;
//repaint();//在新位置处,重新画一个带颜色和阴影及节点说明的矩形框。
return;
}
break;
}

}

public void updateLocation(MouseEventArgs e,DrawRectangle objrect)
{

objrect.setLocation(e.X, e.Y);
//this.checkStatus( objrect);//节点是否在画板内,省略
int PosX = objrect._x + Convert.ToInt32( objrect._w / 2);
int PosY = objrect._y + Convert.ToInt32( objrect._h / 2);
double dblStatusId = objrect.dblStatusId;

}

public void repaint()//画图
{

Graphics g = panel1.CreateGraphics();
//先将图形所有区域用白色填充

Pen WhitePen = new Pen(Color.White);
//g.DrawRectangle(WhitePen, 0, 0, this.Width, this.Height);
//g.FillRectangle(new SolidBrush(Color.White), 0, 0, this.Width, this.Height);
//填充完毕
DrawRectangle rect = rectangle;

int intType = rect.intStatusTypeId;
string strType = " ";
switch (intType)
{
case 0:
strType = "开始 ";
break;
case 1:
strType = "结束 ";
break;
case 2:
strType = "普通 ";
break;
case 3:
strType = "子流 ";
break;
case 4:
strType = "自动 ";
break;
case 5:
strType = "分流 ";
break;
case 6:
strType = "合流 ";
break;
case 7:
strType = "转流程 ";
break;
}

int x1 = rect._x;
int y1 = rect._y;
int w1 = rect._w;
int h1 = rect._h;
string strName = rect.strStatusName;//节点名称

g.FillRectangle(new SolidBrush(Color.Orange), x1, y1, w1, Convert.ToInt32(h1 * 0.6));//用颜色填充上半部分,用来说明节点的类型
g.FillRectangle(new SolidBrush(Color.Blue), x1, y1 + Convert.ToInt32((h1 * 0.6)), w1, Convert.ToInt32(h1 * 0.4));//用颜色画下半部分,用来说明是第几个节点。
Font drawFont = new Font("宋体 ", 9);
StringFormat drawFormat = new StringFormat();

drawFormat.Alignment = StringAlignment.Center;
SolidBrush drawBrush = new SolidBrush(Color.Black);

RectangleF drawRect = new RectangleF(x1, y1, w1, Convert.ToInt32(h1 * 0.6));
RectangleF drawRect2 = new RectangleF(x1, y1 + Convert.ToInt32(h1 * 0.6), w1, Convert.ToInt32(h1 * 0.4));
g.DrawString(strType, drawFont, drawBrush, drawRect, drawFormat);//在上半部分添加节点类型说明文字
g.DrawString(strName, drawFont, new SolidBrush(Color.White), drawRect2, drawFormat);//在下半部分添加节点编号。

g.Dispose();//释放graphics对象。

}

private void panel1_MouseDown(object sender, MouseEventArgs e)
{

int intClickCount = e.Clicks;//鼠标的点击次数
if (e.Button == MouseButtons.Left)//左键,有对右键和双击的处理,此处省略
{
if (intClickCount == 1)
{
this.drawMouseObjs(e, 1);
}
}
}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Left)
{
this.drawMouseObjs(e, 2);

}
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.drawMouseObjs(e, 3);
}
}


}

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧