本文介绍了没有从代码中画出任何线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

为什么没有在屏幕上用以下代码绘制一条线??

Hi there,

Why doesn''t a Line get drawn on the screen with below code???

//Declaration
public Graphics obj_Graphics;
private Bitmap obj_Bitmap;

//Coding
        obj_Bitmap = new Bitmap(1000, 1000);
        obj_Graphics = Graphics.FromImage(obj_Bitmap);
        obj_Graphics.DrawLine(new Pen(new SolidBrush(Color.Black), 5), 100, 500, 400, 500);



在此先感谢...



Thanks in advance...

推荐答案


obj_Graphics = Graphics.FromImage(obj_Bitmap);

如果要在屏幕上绘制它,请处理窗体或窗体上的面板的Paint事件,并使用在EventArgs参数中处理的Graphics对象:

If you want to draw it i=on teh screen, then handle the Paint event for your form, or a panel on your form and use the Graphics object you are handled in the EventArgs parameter:

e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Black), 5), 100, 500, 400, 500);


这篇关于没有从代码中画出任何线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:49