How to call protected override void OnPaint(PaintEventArgs e) in another method in C#
-
Hi all, I need some help since I searched thru all of the blogs and could not find the answer. I have the following code in C# and will like to call ONPaint() in the DrawEventHandler(object sender, DrawHandler.DrawEventArgs e) I get this error: Error 1 The best overloaded method match for 'System.Windows.Forms.Control.OnPaint(System.Windows.Forms.PaintEventArgs)' has some invalid arguments Error 2 Argument '1': cannot convert from 'mobile.DrawSHandler.DrawEventArgs' to 'System.Windows.Forms.PaintEventArgs' namespace mobile { public partial class SV : UserControl { code for declaring variables public SV() { code........ } private void DrawEventHandler(object sender, DrawHandler.DrawEventArgs e) { OnPaint(); } protected override void OnPaint(PaintEventArgs e) { Bitmap b = new Bitmap(this.Width, this.Height); Graphics g = Graphics.FromImage(b); Brush bg = new SolidBrush(BackColor); Region bgr = new Region(new Rectangle(0, 0, this.Width, this.Height)); g.FillRegion(bg, bgr); DrawBg(g); DrawSV(g); e.Graphics.DrawImage(b, 0, 0); b.Dispose(); g.Dispose(); } protected void DrawBg(Graphics g) { code........ } protected void DrawSV(Graphics g) { code........ } } }
-
Hi all, I need some help since I searched thru all of the blogs and could not find the answer. I have the following code in C# and will like to call ONPaint() in the DrawEventHandler(object sender, DrawHandler.DrawEventArgs e) I get this error: Error 1 The best overloaded method match for 'System.Windows.Forms.Control.OnPaint(System.Windows.Forms.PaintEventArgs)' has some invalid arguments Error 2 Argument '1': cannot convert from 'mobile.DrawSHandler.DrawEventArgs' to 'System.Windows.Forms.PaintEventArgs' namespace mobile { public partial class SV : UserControl { code for declaring variables public SV() { code........ } private void DrawEventHandler(object sender, DrawHandler.DrawEventArgs e) { OnPaint(); } protected override void OnPaint(PaintEventArgs e) { Bitmap b = new Bitmap(this.Width, this.Height); Graphics g = Graphics.FromImage(b); Brush bg = new SolidBrush(BackColor); Region bgr = new Region(new Rectangle(0, 0, this.Width, this.Height)); g.FillRegion(bg, bgr); DrawBg(g); DrawSV(g); e.Graphics.DrawImage(b, 0, 0); b.Dispose(); g.Dispose(); } protected void DrawBg(Graphics g) { code........ } protected void DrawSV(Graphics g) { code........ } } }
You can't just omit parameters; the compiler will look for a method without parameters and says, correctly, that there is none. Call
[Invalidate](https://msdn.microsoft.com/en-us/library/598t492a\(v=vs.110\).aspx)[[^](https://msdn.microsoft.com/en-us/library/598t492a\(v=vs.110\).aspx "New Window")]
to have the control repaint.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
You can't just omit parameters; the compiler will look for a method without parameters and says, correctly, that there is none. Call
[Invalidate](https://msdn.microsoft.com/en-us/library/598t492a\(v=vs.110\).aspx)[[^](https://msdn.microsoft.com/en-us/library/598t492a\(v=vs.110\).aspx "New Window")]
to have the control repaint.Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
thanks, this works private void DrawEventHandler(object sender, DrawHandler.DrawEventArgs e) { this.Invalidate(); }