.FillRectangle 不绘制任何东西 [英] .FillRectangle not drawing anything
问题描述
我无法弄清楚为什么 .FillRectangle 对我不起作用.
I'm having trouble figuring out why .FillRectangle is not working for me.
此外,由于它没有抛出任何异常,我想不出为什么会这样,所以我需要一些帮助:/
Furthermore, as it's not thorwing any exception, I ran out of ideas why it could be, so I need some help here:/
受影响的部分代码是这样的
The part of the code affected is this
try
{
using (FileStream fileStream = File.OpenRead(filePath))
{
using (StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8, true, 1024))
{
String line;
int mW = Convert.ToInt32(Math.Round(this.Size.Width / 2d));
int mH = Convert.ToInt32(Math.Round(this.Size.Height / 2d));
SolidBrush myBrush;
myBrush = new SolidBrush(Color.Black);
PointF A = new PointF(0f, 0f);
Graphics g = this.CreateGraphics();
g.TranslateTransform(mW, mH);
while ((line = streamReader.ReadLine()) != null)
{
string[] points = line.Split(',');
A = new PointF((float)(Convert.ToDecimal(points[0])), ((float)(Convert.ToDecimal(points[1]))));
//A is defined correctly, as A.X and A.Y both have values
g.FillRectangle(myBrush, A.X, A.Y, 1f, 1f);
}
}
}
}
catch (Exception p)
{
MessageBox.Show(p.Message);
}
任何帮助将不胜感激,因为我对 Grpahics 的了解非常有限
Any help would be supper appreciated, as my knowledge about Grpahics is very limited
提前致谢,
鲁本 :)
推荐答案
好的,这很有帮助:D.谢谢!
Ok, that helped a lot :D. Thanks!
发表评论作为答案然后:
Posting comment as an Answer then:
this.CreateGraphics
可能是罪魁祸首.这将绘制到一个临时表面,当表单刷新时该表面会被擦除.在 Paint() 事件中使用 e.Graphics
,或者使用 Graphics.FromImage()
绘制位图并显示它.
this.CreateGraphics
is the likely culprit. This draws to a temp surface that gets erased when the Form refreshes. Either use e.Graphics
in the Paint() Event, or draw to a Bitmap with Graphics.FromImage()
and display that.
这篇关于.FillRectangle 不绘制任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!