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

  • 问题

  • 本人新手,想问一下 Graphcis 类如果要在 PictureBox 控件上画图,怎么使 Graphcis 类的绘图范围与 PictureBox 控件的范围一致?
    2018年8月5日 10:23


  • 你好,

    我不太清楚你指的范围一致是什么意思, 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)


    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;

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    2018年8月8日 2:43
  • 那么,我想问,如果要限定 Graphcis 的绘图范围,是不是只需要将它的绘图范围设置成 pictureBox 控件的窗口大小就可以了?
    2018年8月8日 10:01
  • 直接从picturebox中取graphics

    Graphics g=picturebox.CreateGraphics();

    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2018年8月9日 0:26