C#用picturebox画坐标轴 10
privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=Graphics.FromHwnd(this...
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = Graphics.FromHwnd(this.pictureBox2.Handle);
Pen pen2 = new Pen(Color.Black,2);
g.DrawLine(pen2, 120, 100, 120, 350);
g.DrawLine(pen2, 120, 350, 370, 350);
Pen p = new Pen(Color.Blue,2);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLine(p, 370, 100, 370, 350);
Pen pen3 = new Pen(Color.Black, 5);
g.DrawEllipse(pen3, 150, 368, 2, 2);
Pen pen4 = new Pen(Color.Red, 5);
g.DrawEllipse(pen4, 250, 368, 2, 2);
}
这样写可以吗?可是运行时为什么不能显示? 展开
{
Graphics g = Graphics.FromHwnd(this.pictureBox2.Handle);
Pen pen2 = new Pen(Color.Black,2);
g.DrawLine(pen2, 120, 100, 120, 350);
g.DrawLine(pen2, 120, 350, 370, 350);
Pen p = new Pen(Color.Blue,2);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLine(p, 370, 100, 370, 350);
Pen pen3 = new Pen(Color.Black, 5);
g.DrawEllipse(pen3, 150, 368, 2, 2);
Pen pen4 = new Pen(Color.Red, 5);
g.DrawEllipse(pen4, 250, 368, 2, 2);
}
这样写可以吗?可是运行时为什么不能显示? 展开
2个回答
展开全部
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen2 = new Pen(Color.Black, 2);
g.DrawLine(pen2, 120, 100, 120, 350);
g.DrawLine(pen2, 120, 350, 370, 350);
Pen p = new Pen(Color.Blue, 2);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLine(p, 370, 100, 370, 350);
Pen pen3 = new Pen(Color.Black, 5);
g.DrawEllipse(pen3, 150, 368, 2, 2);
Pen pen4 = new Pen(Color.Red, 5);
g.DrawEllipse(pen4, 250, 368, 2, 2);
}
这样就可以啦。
{
Graphics g = e.Graphics;
Pen pen2 = new Pen(Color.Black, 2);
g.DrawLine(pen2, 120, 100, 120, 350);
g.DrawLine(pen2, 120, 350, 370, 350);
Pen p = new Pen(Color.Blue, 2);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLine(p, 370, 100, 370, 350);
Pen pen3 = new Pen(Color.Black, 5);
g.DrawEllipse(pen3, 150, 368, 2, 2);
Pen pen4 = new Pen(Color.Red, 5);
g.DrawEllipse(pen4, 250, 368, 2, 2);
}
这样就可以啦。
追问
只有黑色和蓝色两条纵坐标轴其它的不见了
追答
你的PictureBox的大小要足够大赛,小了,你肯定看不到。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码没问题,问题出在Paint事件上,你可以仔细查下paint事件的发生时机
可以把这些代码放在click事件下,然后点击进行测试:
private void pictureBox2_Click(object sender, EventArgs e)
{
………………
}
可以把这些代码放在click事件下,然后点击进行测试:
private void pictureBox2_Click(object sender, EventArgs e)
{
………………
}
追问
这样的话就一定要单击才能显示咯?
追答
是的,要想一直显示,好像不能直接添加,试试等窗体加载完毕后再把paint事件添加给form
不改变的话拖动改变窗体大小(触发了paint事件)能看到你的绘图效果
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询