求关于自绘的思路或是代码!!

shanying_0 2008-10-26 11:21:04
就是类似与vs设计器。就是一点直线这个button。我可以在窗口上画一个直线,
一点矩形,我可以在窗口上画一个矩形!还有其他的。就是类似这样的功能的东西。
求一个思路做法,最好详细点,
有代码参考就更好了!!!大家积极发言呀。

!!!!!顶着有分!!!
...全文
110 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hake303 2008-10-28
  • 打赏
  • 举报
回复
5楼写得比较详细了
shanying_0 2008-10-28
  • 打赏
  • 举报
回复
不要沉了。顶呀
palmax 2008-10-27
  • 打赏
  • 举报
回复
ding
abcyzq 2008-10-27
  • 打赏
  • 举报
回复
顶!我使劲帮楼主顶!
shanying_0 2008-10-27
  • 打赏
  • 举报
回复
大家顶呀,顶也有分的
cja03 2008-10-26
  • 打赏
  • 举报
回复
正式的做法是封装自己的图形对象。
如果要求不高,可以这样做:



//这里只有线,其它的自己添加
enum Action
{
None,
Line
}

Action currentAction = Action.None;//当前命令

GraphicsPath gp = new GraphicsPath();//存诸图形,可以一并显示(红色)
GraphicsPath tempGP = new GraphicsPath();//临时,在画时的显示(蓝色)

private void buttonLine_Click(object sender, EventArgs e)//点击了画线按钮
{
this.currentAction = Action.Line;
}

private void buttonClear_Click(object sender, EventArgs e)//点击了清除按钮
{
gp.Reset();
tempGP.Reset();
this.Invalidate();
}

Point mouseDownPoint = new Point();//鼠标按下时的点
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left || this.currentAction == Action.None)
return;

switch (this.currentAction)
{
case Action.None:
break;
case Action.Line:
mouseDownPoint.X = e.X;
mouseDownPoint.Y = e.Y;
break;
default:
break;
}
}

//随着鼠标的位置改变,正在画的图形也会跟着改,把它写到tempGP
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left || this.currentAction == Action.None)
return;

tempGP.Reset();
switch (this.currentAction)
{
case Action.None:
break;
case Action.Line:
tempGP.AddLine(mouseDownPoint.X, mouseDownPoint.Y, e.X, e.Y);
this.Invalidate();
break;
default:
break;
}
}

//图形确定,加入gp
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left || this.currentAction == Action.None)
return;

switch (this.currentAction)
{
case Action.None:
break;
case Action.Line:
gp.AddLine(mouseDownPoint.X, mouseDownPoint.Y, e.X, e.Y);
gp.CloseFigure();
tempGP.Reset();
this.Invalidate();
break;
default:
break;
}
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

e.Graphics.DrawPath(Pens.Red, gp);

e.Graphics.DrawPath(Pens.Blue, tempGP);
}
yilunduyue 2008-10-26
  • 打赏
  • 举报
回复
重载窗体的paint事件,至于绘图直线,椭圆等基本的图形gdi+都有实现!!!
simonezhlx 2008-10-26
  • 打赏
  • 举报
回复
GDI+就可以满足你的要求,自己去封装对应的图形类。代码自己搞定吧
周公 2008-10-26
  • 打赏
  • 举报
回复
在Paint事件里写绘制代码,以下是绘制圆形按钮的代码。

private void roundButton_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{

System.Drawing.Drawing2D.GraphicsPath buttonPath =
new System.Drawing.Drawing2D.GraphicsPath();

// Set a new rectangle to the same size as the button's
// ClientRectangle property.
System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;

// Decrease the size of the rectangle.
newRectangle.Inflate(-10, -10);

// Draw the button's border.
e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

// Increase the size of the rectangle to include the border.
newRectangle.Inflate( 1, 1);

// Create a circle within the new rectangle.
buttonPath.AddEllipse(newRectangle);

// Set the button's Region property to the newly created
// circle region.
roundButton.Region = new System.Drawing.Region(buttonPath);

}
CraxyMouse 2008-10-26
  • 打赏
  • 举报
回复
http://blog.csdn.net/dunao/archive/2008/10/22/3124257.aspx
看看我写的这个吧!
可以满足你的要求!

110,536

社区成员

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

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

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