Results 1 to 19 of 19

Thread: [RESOLVED] Trouble with DrawLine

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    13

    Resolved [RESOLVED] Trouble with DrawLine

    I'm trying to draw a line in a picturebox on my form. Using System.Drawing, I would think this to be really easy but for the life of me I can't get the line to actually appear. When I run the code below, absolutely nothing happens. The form opens, I click button1, and get nothing.

    There are no compile errors, and no runtime errors. Why won't the line show up on the form?

    The code I'm using to do this is:

    Code:
    using System;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            private Point start = Point.Empty;
            private Point end = Point.Empty;
            private Random rand = new Random();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Graphics g;
                g = this.pictureBox1.CreateGraphics();
                Pen aPen = new Pen(Brushes.Black, 2);
                g.DrawLine(aPen, 0, 0, 10, 10);
    
                this.pictureBox1.Refresh();
                this.Refresh();
            }
        }
    }
    Last edited by Fedge; Apr 11th, 2007 at 10:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width