Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to call protected override void OnPaint(PaintEventArgs e) in another method in C#

How to call protected override void OnPaint(PaintEventArgs e) in another method in C#

Scheduled Pinned Locked Moved C#
graphicshelpcsharpregextutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10650102
    wrote on last edited by
    #1

    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........ } } }

    L 1 Reply Last reply
    0
    • U User 10650102

      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........ } } }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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[^]

      U 1 Reply Last reply
      0
      • L Lost User

        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[^]

        U Offline
        U Offline
        User 10650102
        wrote on last edited by
        #3

        thanks, this works private void DrawEventHandler(object sender, DrawHandler.DrawEventArgs e) { this.Invalidate(); }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups