C# 中 在窗体上用gdi+画个圆点,我想利用timer实现圆点的移动,结果出现的是一条粗线,不知道该怎么做

如题所述

第1个回答  2010-06-05
每移动一次刷新(Refresh)就可以了,
第2个回答  2010-06-05
移动的时候要擦掉之前的圆!
第3个回答  2010-06-05
给你一个我编的例子吧,不过是按按钮移动的
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;
using System.Drawing.Drawing2D;

namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Graphics g;
GraphicsPath gp, gpOld;
Matrix RotationTransform, TranslationTransform;
PointF TheRotationPoint;
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
gp = new GraphicsPath();
gp.AddBezier(110, 110, 110, 115, 120, 115, 125, 130);
gp.AddEllipse(125, 130, 8, 8);
gpOld = gp.Clone() as GraphicsPath;
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
TranslationTransform = new Matrix(1, 0, 0, 1, 0, 0);
TheRotationPoint = new PointF(110.0f, 110.0f);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{

gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}

}

private void button1_Click(object sender, EventArgs e)
{

}
//int iCount = 1;
private void button2_Click(object sender, EventArgs e)
{
//iCount++;

//pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
//g = Graphics.FromImage(this.pictureBox1.Image);
//RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
//TranslationTransform = new Matrix(1, 0, 0, 1, 0, 0);
//TheRotationPoint = new PointF(110.0f, 110.0f);
//for (int i = 0; i < iCount; i++)
//{
// for (float f = 0.0f; f < 359.0f; f += 45.0f)
// {
// gp.Transform(TranslationTransform);
// RotationTransform.RotateAt(f, TheRotationPoint);
// gp.Transform(RotationTransform);
// g.FillPath(Brushes.Orange, gp);
// g.DrawPath(Pens.Green, gp);
// RotationTransform.Dispose();
// RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
// gp = gpOld.Clone() as GraphicsPath;
// }
// TheRotationPoint.X = TheRotationPoint.X + 100;
// TranslationTransform.Translate(100, 0);
//}
}
bool leftDown = false;
bool rightDown = false;
bool upDown = false;
bool downDown = false;
private void button2_MouseDown(object sender, MouseEventArgs e)
{
rightDown = true;
while (rightDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.X += 2;
TranslationTransform.Translate(2, 0);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}

private void button2_MouseUp(object sender, MouseEventArgs e)
{
rightDown = false;
}

private void button1_MouseDown(object sender, MouseEventArgs e)
{
leftDown = true;
while (leftDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.X -= 2;
TranslationTransform.Translate(-2, 0);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}

private void button1_MouseUp(object sender, MouseEventArgs e)
{
leftDown = false;
}

private void button3_MouseDown(object sender, MouseEventArgs e)
{
upDown = true;
while (upDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.Y -= 1;
TranslationTransform.Translate(0, -1);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}

private void button3_MouseUp(object sender, MouseEventArgs e)
{
upDown = false;
}

private void button4_MouseDown(object sender, MouseEventArgs e)
{
downDown = true;
while (downDown)
{
Application.DoEvents();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
g = Graphics.FromImage(this.pictureBox1.Image);
TheRotationPoint.Y += 1;
TranslationTransform.Translate(0, 1);
for (float f = 0.0f; f < 359.0f; f += 45.0f)
{
//Application.DoEvents();
gp.Transform(TranslationTransform);
RotationTransform.RotateAt(f, TheRotationPoint);
gp.Transform(RotationTransform);
g.FillPath(Brushes.Orange, gp);
g.DrawPath(Pens.Green, gp);
RotationTransform.Dispose();
RotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
gp = gpOld.Clone() as GraphicsPath;
}
}
}

private void button4_MouseUp(object sender, MouseEventArgs e)
{
downDown = false;
}

}
}本回答被提问者采纳
第4个回答  2010-06-05
invalidate()

C# 图形图像编程,我想用GDI画一圈的圆,如下图。请高手指点怎么实现?
t属于(0,360)此时可画出一个完整的圆,当然由于小圆还有半径,所以取点时t要隔一定角度进行取值,这要根据你的小圆半径为定

在C#窗体中,画一个圆时,周围总是有矩齿,怎么消除这些?
为了消除绘制的图形的锯齿现象,可以修改Graphics 对象的SmoothingMode 为HighQuality在调用绘图的方法前加入这一句话就可以了: g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 消除锯齿前的代码: using System;using System.Collections.Generic;using System.ComponentModel;using Syste...

在C#中,用GDI+绘在窗体上的图,然后把窗体最小化,再展开所画的图就没...
窗体有个事件是专门控制这个的。选择这个事件"Paint" 进入它,在里面填写相应的你刚才绘制的图像代码就可以了。最好将绘制的图像放到缓存里面,Paint 事件里面直接调缓存就可以了。

用C# GDI+画一条折线,怎么让这条折线随时间向下移动,并且上一时刻的线...
你可以在窗体上添加一个picturebox和一个timer,设置timer的时间间隔。画折线是需要有几个点的,你可以设这几个点的Y坐标值为变量,然后隔一段时间将这几个Y值加一个值,然后重新画出来就行了,用picturebox的refresh方法可以擦除掉上一次画的折线。

用C#.net的GDI+画图,如何实现图像的旋转,比如直线,矩形,椭圆等等,用R...
画“直线,矩形,椭圆”这个是怎么画的???c#.net GDI+里面有相应的函数,那旋转是一样的,你画直线时,需要提供参数,画矩形时也需要提供参数,旋转只不过是参数变量变了而已。求出变量就可以了!

在C#,GDI+中,怎样把画出来的矩形(Rectangle)的四个角变成圆形,使其变成...
using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius)){ g.FillPath(brush, path);} } internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius){ GraphicsPath roundedRect = new GraphicsPath();roundedRect.AddArc(rect.X, rect.Y, cornerRadius *...

C# winform 窗体里 用GDI+画一条直线 怎么用鼠标点击这条直线,触发事件...
首先你需要先将这个直线的坐标记录下来,记录起点终点即可。在窗体或者是你画线的控件中捕获click事件,在click事件里面获取当前鼠标的坐标位置,根据此坐标计算此点到记录的直线之间的距离,如果小于一定值,比如小于2个像素就认为点中了此直线,就可一触发其他事件执行操作了。关键是如何判断鼠标点中的点在...

用GDI+(C#语言)画出的图形如何保存
楼上正解,一般都是在窗体的Form_Load事件中new 一个bitmap,然后设置本窗体的BackImage为那个BitMap,然后Graphics.FromImage() ,你就可一保存那个图片了 ,

我想用C#做一个系统,能够实时显示小车(agv)的位置,并画出运动轨迹,涉及...
每次agv小车移动的时候你记录个坐标(x,y),然后用GDI+绘制折线图的方式把你刚才记的坐标(x,y)连接起来,就是agv小车的路径了;

C# GDI+绘图,我用mm作为单位,但是在屏幕上画出来的线条长度,和实际不...
mm是不能直接转换为像素的,网上的的一些方法也都是有问题的,比如http:\/\/www.cnblogs.com\/oY-CCTR\/archive\/2012\/11\/15\/2772193.html 如果你一定要在屏幕上画出与实际的mm相等的长度,就必须知道显示器本身的宽度(比如19英寸还是21英寸),以及分辨率才行,然后根据这个来计算出dpi是多少,具体过程...

相似回答
大家正在搜