1
Answer

Drawing on Label leads to throw exception?

Ask a question
xuke0518

xuke0518

19y
2.1k
1
Usually after drawing stuff on component, I would destroy the Graphics object. Recently I found if i call dispose() on Label Component would lead to throw exception. The exception is System.ArgumentException happens in sytem.drawing.dll. So it forces me not to call dispose() at the end. However dispose() works on other components like Form, Splitter, GroupBox, Panel. It is strange. If anyone knows why, would you please point out? Thanks. //This one leades to throw exception private void label1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { System.Drawing.Graphics g = e.Graphics; g.DrawLine(Pens.Black,1,1,6,6); e.Dispose(); } // This one is okay private void label1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { System.Drawing.Graphics g = e.Graphics; g.DrawLine(Pens.Black,1,1,6,6); }

Answers (1)