I wrote a code to draw a line in form by clicking on a button.
Please download in and tell me why it does not work.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Jul 23, 2010, 3:22 AM EDT
add use invalidate() function for curing this problem..
you can cal this function on button click event like this
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
base.Paint+=new PaintEventHandler(Form1_Paint);
this.Invalidate();
}
thanks
Please mark as answer if it helps
Kirtan PatelRank #292 · 8.6K reputationPosted Jul 22, 2010, 6:14 AM EDT
void Form1_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 1.0f);
g.DrawLine(p, 10, 40, 100, 100);
}
it will work
Mahesh ChandRank #1 · 393.3K reputationPosted Jul 22, 2010, 7:03 AM EDT
I added a line to Kirtan's code.
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red, 1.0f);
g.DrawLine(p, 10, 40, 100, 100);
g.Dipose();
}
Majid KamaliRank #6,453 · 266 reputationPosted Jul 22, 2010, 8:07 AM EDT
I want to do that with PaintEventArgs way to not to become cleaned.
2. What does Dispose() do ?
3. Sorry for bad English ;-)
Majid KamaliRank #6,453 · 266 reputationPosted Jul 23, 2010, 3:13 AM EDT
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Jul 23, 2010, 3:33 AM EDT
Majid KamaliRank #6,453 · 266 reputationPosted Jul 24, 2010, 7:53 AM EDT