For some reason my line wont draw on my windows form. If I place the code in a button event routine it works fine but it won't work when the window loads. I'm really confused! thanks:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace testForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
Pen myPen = new Pen(Color.Red);
Graphics g = this.CreateGraphics();
g.DrawLine(myPen, 20, 30, 10, 50);
//this.Refresh(); //doesn't work if I add this.
}
}
}
Loading
Mahesh ChandPosted Mar 20, 2009, 11:38 PM
You need to put this code on On_Paint event handler of the form.
George LovelessPosted Mar 21, 2009, 11:36 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace t
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen myPen = new Pen(Color.Red);
Graphics g = this.CreateGraphics();
g.DrawLine(myPen, 20, 30, 10, 50);
}
}
}
jabir eriyadenPosted Mar 21, 2009, 2:01 AM