Click here to Skip to main content
14,937,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed application in console application. I want to call mainform function inside another method. i have tried but error throws as
"Error 2 'System.Drawing.Graphics' is a 'type' but is used like a 'variable'"

C#
      private void MainForm_Paint(object sender, PaintEventArgs e)
      {
          Render_Plot(e.Graphics, 0);

      }

private void timer1_Tick(object sender, EventArgs e)
      {
                Render_Plot(Graphics, 0); //Error--how to call render_plot function here
      }


What I have tried:

C#
      private void MainForm_Paint(object sender, PaintEventArgs e)
      {
          Render_Plot(e.Graphics, 0);

      }

private void timer1_Tick(object sender, EventArgs e)
      {
                Render_Plot(Graphics, 0); //Error--how to call render_plot function here
      }
Posted
Updated 25-Aug-16 23:19pm

1 solution

Don't. You could do it - but it means creating and disposing the Graphics context yourself, and that may limit what else you can do. Instead, in your Tick event handler, just call Invalidate:
C#
private void MainForm_Paint(object sender, PaintEventArgs e)
      {
          Render_Plot(e.Graphics, 0);
      }
 private void timer1_Tick(object sender, EventArgs e)
      {
          Invalidate();
      }

That will cause the system to issue a Paint request, which will trigger your Paint event handler.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900