Graphcis 类与UI控件 PictureBox的配合问题

weixin_38055275 2018-08-05 10:23:27
本人新手,想问一下 Graphcis 类如果要在 PictureBox 控件上画图,怎么使 Graphcis 类的绘图范围与 PictureBox 控件的范围一致?
...全文
18 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38070435 2018-08-09
  • 打赏
  • 举报
回复
直接从picturebox中取graphics
Graphics g=picturebox.CreateGraphics();
专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms
weixin_38068996 2018-08-08
  • 打赏
  • 举报
回复
那么,我想问,如果要限定 Graphcis 的绘图范围,是不是只需要将它的绘图范围设置成 pictureBox 控件的窗口大小就可以了?
weixin_38065708 2018-08-08
  • 打赏
  • 举报
回复
你好,
我不太清楚你指的范围一致是什么意思, Graphcis 类如果要在 PictureBox 控件上画图, 可以使用PictureBox 的Paint 事件,如果Graphcis 超过PictureBox的话,会被自动截除。 下面的代码你可以参考一下:
private void Circle(PaintEventArgs e) { Graphics g1 = e.Graphics; Pen p1 = new Pen(Color.Black); g1.DrawEllipse(p1, 0, 0, 150, 150); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { Circle(e); }
或者:
private void Circle(Graphics g) { Pen p1 = new Pen(Color.Black); g.DrawEllipse(p1, 12, 12, 50, 50); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { Graphics myg = e.Graphics; Circle(myg); }



Best regards,
Zhanglong

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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