.填充矩形不绘制任何内容

本文关键字:任何内 绘制 填充矩形 | 更新日期: 2023-09-27 18:36:03

我很难弄清楚为什么.填充矩形对我不起作用。

此外,由于它没有任何例外,我用尽了为什么会这样的想法,所以我在这里需要一些帮助:/

受影响的代码部分是这个

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的了解非常有限

提前感谢,

鲁本·:)

.填充矩形不绘制任何内容

好的,这对:D有很大帮助。谢谢!

然后发布评论作为答案:

this.CreateGraphics可能是罪魁祸首。这将绘制到在表单刷新时擦除的临时图面。在 Paint() 事件中使用e.Graphics,或者绘制到带有Graphics.FromImage()的位图并显示该位图。