473,469 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Overriding Methods

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
Nov 11 '08 #1
2 1819
Looks like you need a Click event on your button. Google for C# events.

--
Pete
====
http://mrpmorris.blogspot.com
http://www.capableobjects.com
Nov 11 '08 #2
On Nov 11, 1:32*pm, "Peter Morris" <mrpmorri...@SPAMgmail.comwrote:
Looks like you need a Click event on your button. *Google for C# events..

--
Pete
====http://mrpmorris.blogspot.comhttp://www.capableobjects.com
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
Nov 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andrew Durdin | last post by:
In Python, you can override the behaviour of most operators for a class, by defining __add__, __gt__, and the other special object methods. I noticed that, although there are special methods for...
5
by: Hongzheng Wang | last post by:
Hi, I have a problem about the overriding of private methods of base class. That is, if a method f() of base class is private, can the derived class overriding f() be overriding? For...
5
by: zero | last post by:
I'm having trouble with overriding methods in subclasses. I'll explain the problem using some code: class BaseClass { protected: void method2(); public: void method1();
1
by: Burkhard Perkens-Golomb | last post by:
Hi, I've a question about XML documentation of overridding methods and methods implementing an interface declaration: These methods are normally documented in the base class or interface. So I...
4
by: ORi | last post by:
Hi all ! There's a question I've been bothering for a while: I'm actually developing architectural frameworks for application developing and I think virtual methods, although needed because of...
2
by: ESPNSTI | last post by:
Hi, I'm very new to C# and .Net, I've been working with it for about a month. My experience has been mainly with Delphi 5 (not .Net). What I'm looking for is for a shortcut way to override a...
4
by: TS | last post by:
i have a class that i'm trying to understand that overrides BaseApplicationException's methods as follows. What i dont' understand is that i have never seen the inherit ":" on a method signature,...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
6
by: bryanbabula | last post by:
I have a question about overriding i was wondering if anyone could help me with, or even suggesting a better/different way. I have no idea if this can even be done or not. I was wondering if there...
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.