在pictureBox中画线,怎么什么也看不到呢?

hhd2009555 2010-01-16 08:04:31
在一个form上,建了pictureBox,然后在pictureBox的Paint事件中写如下代码,

System.Drawing.Graphics ht;
ht = this.pictureBox1.CreateGraphics();
Pen ok = new Pen(System.Drawing.Color.DarkBlue, 3);
Rectangle jx = new Rectangle();
jx.X = 0;
jx.Y = 0;
jx.Width = 100;
jx.Height = 200;
ht.DrawLine(ok, 0, 10, 100, 90);
奇怪的是,图片框中什么也没有,但把form在屏幕上拖动,使其部分超出屏幕,线条就出现了,很奇怪。
...全文
227 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhd2009555 2010-01-17
  • 打赏
  • 举报
回复
不好意思,行了,谢谢hhc123,你是个高手吧,太厉害了!
hhd2009555 2010-01-17
  • 打赏
  • 举报
回复
老大,怎么弄也不行呀!
Pro_ah 2010-01-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hhc123 的回复:]
C# codeprivatevoid pictureBox1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics ht;
ht= e.Graphics;
Pen ok=new Pen(System.Drawing.Color.Dark?-
[/Quote]

Up
hhc123 2010-01-16
  • 打赏
  • 举报
回复

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics ht;
ht = e.Graphics;
Pen ok = new Pen(System.Drawing.Color.DarkBlue, 3);
Rectangle jx = new Rectangle();
jx.X = 0;
jx.Y = 0;
jx.Width = 100;
jx.Height = 200;
ht.DrawLine(ok, 0, 10, 100, 90);

}
ysz89757 2010-01-16
  • 打赏
  • 举报
回复
在最后加一句:invalidate();

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧