
C#画一个矩形,为什么不显示?
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black, 10);
g.DrawRectangle(p, 50, 50, 50, 50);
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black, 10);
g.DrawRectangle(p, 50, 50, 50, 50);
}
}
} 展开
4个回答
展开全部
放到Form的Paint事件中
MSDN上有写:Control.CreateGraphics 方法生成的“Graphics 只在当前窗口消息期间有效”
MSDN上有写:Control.CreateGraphics 方法生成的“Graphics 只在当前窗口消息期间有效”
参考资料: http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.creategraphics(v=VS.80).aspx
展开全部
在Form1的pain事件里添加:
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black, 10);
g.DrawRectangle(p, 50, 50, 50, 50);
e.Graphics.DrawRectangle(p, 50, 50, 50, 50);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black, 10);
g.DrawRectangle(p, 50, 50, 50, 50);
e.Graphics.DrawRectangle(p, 50, 50, 50, 50);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.Refresh()试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-12-13
展开全部
你的代码已经画了 至于不显示 你并没有要求他画在什么位置 可能在某角落里 全屏看一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询