Jump to content
  • Advertisement
Sign in to follow this  
Fixxer

C# 2 errors with "protected override void OnPaint(PaintEventArgs e)"

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im getting these 2 errors with the code below:
protected override void OnPaint(PaintEventArgs e)

Error 1 The type or namespace name 'PaintEventArgs' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Owner\Desktop\Tankwars 2006\Tankwars 2006\Form1.Designer.cs 36 39 Tankwars 2006 Error 2 'Tankwars_2006.GameEngine.OnPaint(PaintEventArgs)': virtual or abstract members cannot be private C:\Documents and Settings\Owner\Desktop\Tankwars 2006\Tankwars 2006\Form1.Designer.cs 36 31 Tankwars 2006

Share this post


Link to post
Share on other sites
Advertisement
Are you sure you acknowledged the Forms namespace? (I.e. "using System.Windows.Forms)
protected override void OnPaint(PaintEventArgs e)
{
//...
}

should work fine if you have, or
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
will work as well.

Share this post


Link to post
Share on other sites
Hmm still getting errors:

Here is program.cs


using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.Samples.DirectX.UtilityToolkit;

namespace Tankwars_2006
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new GameEngine());
}
}
}





and here is form1.designer.cs

namespace Tankwars_2006
{
partial class GameEngine
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
public override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "GameEngine";
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
dblTime = FrameworkTimer.GetElapsedTime();
FrameworkTimer.Start();
this.Invalidate;
}

private double dblTime;

#endregion
}
}





The error:

Error 3 'Tankwars_2006.GameEngine.Dispose(bool)': cannot change access modifiers when overriding 'protected' inherited member 'System.ComponentModel.Component.Dispose(bool)' C:\Documents and Settings\Owner\Desktop\Tankwars 2006\Tankwars 2006\Form1.Designer.cs 14 30 Tankwars 2006

and the problem line:

public override void Dispose(bool disposing)




sorry for any really newbie mistakes, this is my 1st day with C#

Share this post


Link to post
Share on other sites
The error message you quoted,

Quote:
Error 3 'Tankwars_2006.GameEngine.Dispose(bool)': cannot change access modifiers when overriding 'protected' inherited member 'System.ComponentModel.Component.Dispose(bool)' C:\Documents and Settings\Owner\Desktop\Tankwars 2006\Tankwars 2006\Form1.Designer.cs 14 30 Tankwars 2006


is quite clear to me. Dispose is a protected member, but you declared it as public in the method override signature. This is an error. Change "public" to "protected" at that line in your code.

Share this post


Link to post
Share on other sites
Hi,

There are several ways of creating a main loop, using the onpaint and invalidate method I think is slower than running the method in a while loop.

There are several more clever ways to do this but I cut out some old code and you can see how a fairly decent main loop extract may look (it's not perfect).




using (MainLoop mainLoop = new MainLoop())
{
FrameworkTimer.Start();

while (mainLoop.CurrentGameState != (int)GameState.GameQuit)
{
timeElapsed = FrameworkTimer.GetElapsedTime();

mainLoop.Render(timeElapsed);
mainLoop.UpdateStats(timeElapsed);
mainLoop.UpdateScene(timeElapsed);

// this will drop the CPU usage while alt-tabbed or whatnot.
if (!mainLoop.Focused)
{
Thread.Sleep(10);
}

Application.DoEvents();
}
}


public void Render(double delta)
{
this.ClearBuffer(Color.Black);
this.BeginScene();
ship.Render(this.D3DDevice, Matrix.Identity);
this.EndScene();
this.PresentScene();
}

public void UpdateScene (double delta)
{
if (this.Focused)
{
// updates the ship through the keyboard/mouse
this.MouseUpdate(delta);
this.KeyPressUpdate(delta);
UpdateGameObjects(delta);
this.CameraSetup();
}
}


public void UpdateStats (double delta)
{
if ( (float)(FrameworkTimer.GetAbsoluteTime()) > (lastAbsoluteTime+1.0f))
{
fps = (frameCounter/ 1.0 );
lastAbsoluteTime = FrameworkTimer.GetAbsoluteTime();
frameCounter=0;
}
frameCounter +=1;
}



To make it smarter you could check the Win32 event pump/whatnot and see if there are any events/messages waiting to be processed instead of doing "Application.DoEvents();" every loop

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!