Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7094017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:30:41+00:00 2026-05-28T08:30:41+00:00

I have a PictureBox as UserControl . I added this User Control on the

  • 0

I have a PictureBox as UserControl. I added this User Control on the main form. Now I have to press a button and create a line on the user control. On my project, every time I press this button, I want to send to user control parameters of two PointF(x and y) and draw a new line, in addition to the existent one. I have so far the Paint event when picturebox is loaded.

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
  Pen graphPen = new Pen(Color.Red, 2);
  PointF pt1D = new PointF();
  PointF pt2D = new PointF();
  pt1D.X = 0;
  pt1D.Y = 10;
  pt2D.X = 10;
  pt2D.Y = 10;

  e.Graphics.DrawLine(graphPen, pt1D, pt2D);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:30:42+00:00Added an answer on May 28, 2026 at 8:30 am

    Assuming that you want to draw the line on the click of the button, here’s a modified version of your code:

    List<PointF> points = new List<PointF>();
    Pen graphPen = new Pen(Color.Red, 2);
    
    private void btnDrawLines_Click(object sender, EventArgs e)
    {
        Graphics g = picBox.CreateGraphics();
        PointF pt1D = new PointF();
        PointF pt2D = new PointF();
        pt1D.X = 0;
        pt1D.Y = 10;
        pt2D.X = 10;
        pt2D.Y = 10;    
        g.DrawLine(graphPen, pt1D, pt2D);
        points.Add(pt1D);
        points.Add(pt2D);
    }
    
    private void picBox_Paint(object sender, PaintEventArgs e)
    {
        for (int i = 0; i < points.Count; i+=2)
            e.Graphics.DrawLine(graphPen, points[i], points[i + 1]);
    }
    

    Note that you can get a Graphics object through the PictureBox class’s CreateGraphics() method which is the same as the e.Graphics object in the Paint event handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a user control that descends from UserControl. When dropped onto the form
I want to create a listview type user control which'll have a picturebox and
I have downloaded this PictureBox ImageArray then I've added a button which will add
I have a PictureBox control on a Form that is supposed to draw something
I have a .NET PictureBox control added to a Windows.Forms.SplitterPanel. How do I do
I have added a simple .gif file into Resources folder in my project. Now
On a form I have a PictureBox , a button to load image in
I wrote a windows application, and I have a PictureBox on my form. Now,
i have picturebox control in my form that SizeMode = StretchImage when i load
I have a pictureBox on a Windows Form. I do the following to load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.