为何图像绘制不出来
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace texun
{
public partial class Form1 : Form
{
private bool isStart = false;
Thread pt = null;
public int i = 0;
private Graphics newDM = null;
private Bitmap bufferimg = null;
public Form1()
{
InitializeComponent();
LaunchForm();
}
private void LaunchForm()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
isStart = true;
newDM = Graphics.FromImage(bufferimg);
}
private void PaintThread()
{
while (isStart)
{
DMMove(newDM);
this.Invalidate();
Thread.Sleep(100);
}
}
private void Form1_Load(object sender, EventArgs e)
{
pt = new Thread(new ThreadStart(PaintThread));
pt.Start();
}
private void DMMove(Graphics g)
{
int i = 0;
SolidBrush sb = new SolidBrush(Color.Red);
g.FillEllipse(sb, i += 3, i += 3, 10, 10);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
}
}
}
本来想画一个移动的点的,但是DMMove()方法貌似出了问题。我是新手……麻烦浅显点…… GDI+ Bitmap Graphics
[解决办法]
CreateGraphics 是属于Control类的,那么只要继承Control的都可以,
首先,你要看到图片,那么展示图片的控件可以是picturebox,picturebox需存在于窗体上,然后调用picturebox的CreateGraphics 创建画板
[解决办法]