绘图方法(把你们能想出的绘图方法都交出来吧)

newtee 2012-08-10 10:15:13
抛砖引玉:

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
private bool ismousedown = false;//开始画图
private PointF startposition;
private PointF nowposition;
private Image img;
private Image image;
private Pen pen;
private Graphics g;

public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
this.UpdateStyles();
img = new Bitmap(this.Width, this.Height);
image = new Bitmap(this.Width,this.Height);
pen = new Pen(Color.Red, 2);
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ismousedown = true;
startposition.X = e.X;
startposition.Y = e.Y;
}
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{

if (ismousedown)
{
nowposition.X = e.X;
nowposition.Y = e.Y;
g = Graphics.FromImage(img);
g.Clear(Color.WhiteSmoke);
g.DrawImage(image, 0, 0);
g.DrawRectangle(pen,Math.Min(nowposition.X,startposition.X),Math.Min(nowposition.Y,startposition.Y),Math.Abs(nowposition.X -startposition.X ),Math.Abs(nowposition.Y-startposition.Y));
g.Dispose();
Graphics graphcis = this.CreateGraphics();
graphcis.DrawImage(img, 0, 0);
graphcis.Dispose();
}
}
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
ismousedown = false;
g = Graphics.FromImage(image);
g.DrawImage(img, 0, 0);
g.Dispose();
}
}
}
类似此方法你可以画出你想要的图片(直线,椭圆等等),潜水去了。大家玩吧!祝上班的同志工作顺利,上学的孩子学习进步。
...全文
193 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
newtee 2012-08-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

准备写个绘制引擎?
[/Quote]还没到那个境界
dylike 2012-08-11
  • 打赏
  • 举报
回复
准备写个绘制引擎?
newtee 2012-08-10
  • 打赏
  • 举报
回复
1楼自己占了。楼下请用代码说话。let's talk about it!
newtee 2012-08-10
  • 打赏
  • 举报
回复
1楼自己占了。楼下请用代码说话。let's talk about it!
newtee 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

大爷的,还删除
[/Quote]删就删吧 随它去了 现在去博客园和coderproject发展去
bookc-man 2012-08-10
  • 打赏
  • 举报
回复
靠,学习的评论也删除,有木有啊,也太霸道了吧

110,539

社区成员

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

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

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