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);
}
}
}
展开
 我来答
csd314
2011-12-13 · TA获得超过493个赞
知道小有建树答主
回答量:730
采纳率:50%
帮助的人:569万
展开全部
放到Form的Paint事件中
MSDN上有写:Control.CreateGraphics 方法生成的“Graphics 只在当前窗口消息期间有效”

参考资料: http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.creategraphics(v=VS.80).aspx

kangduty
2011-12-13
知道答主
回答量:35
采纳率:0%
帮助的人:33.3万
展开全部
在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);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
钛元素的IT服务站
2011-12-13 · TA获得超过1217个赞
知道小有建树答主
回答量:1517
采纳率:61%
帮助的人:419万
展开全部
this.Refresh()试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2011-12-13
展开全部
你的代码已经画了 至于不显示 你并没有要求他画在什么位置 可能在某角落里 全屏看一下
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式