Overriding Methods

B

Blau

I'm trying to write a library for GUI controls to use in a little
directX game I am working on, and I have run into a bit of a snag.

Here is what I have so far:

I have a base class called "Control"
I have a class called "Window" that is derived from Control
I have a class called "Button" that is derived from Control

Control has various virtual methods, e.g., "OnMouseDown"

Button uses the "Override" keyword and implements the "OnMouseDown"
method and implements a texture change and a slight animation to show
that the button was clicked......as this is something that I want each
instance of class Button to do.

Now the problem I am having is this: I don't know how to let each
instance of a Button object have a unique response to the
"OnMouseDown" event.

To put it another way I have:

public class Control
{
public virtual void OnMouseDown() { }
}

public class Button : Control
{
public override void OnMouseDown()
{
//Change texture
//move button slightly to show that button was clicked
}
}


Next I created a class called "Start Menu":

public class StartMenu
{
//create a window to form the start menu
Window myWIndow = new Window();

//create a button that will start the game
Button myStartButton = new Button();

//create a button that will exit the game
Button myExitButton = new Button();
}


So my hope would be that I can do something from WITHIN the class
Start Menu that will allow the Button click animation to happen and
will still allow me to designate the proper additional functionallity
of the buttons (i.e., each button has its own OnMouseDown method in
addition to the base class animation.

I hope that makes sense.

Anyway, I am learning this stuff on my own, so it could be that my
entire approach is wrong, but hopefully the solution simply involves a
neat new trick I haven't learned yet.

Thank you in advance for your help
 
B

Blau

Looks like you need a Click event on your button.  Google for C# events..

Pete, I did as you said and checked out "Events" and it looks like
some pretty useful stuff, and should solve my problem...........thanks
for the tip!


Blau
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top