473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1816
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.