Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am sure the answer to this is pretty simple. I am in the middle of a course from 3D buzz about C# and XNA game development. So I am new to programming in general. I have learned that with a class you can create an object and give that object properties but we have only done this from a console standpoint. And we created our own objects. What I am trying to do is setup a class that defines a button. A standard windows button. But I do not know how to tell this object that it is indeed a button. I guess what I am asking is what is the correct way to create a class that defines a button on a GUI that I can use multiple times and have multiple copies of without having to manually code every button in. Just reuse the class to "Spawn" more? Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Jun-11 21:39pm    
Do you mean raw Windows API button?
--SA

There is a button class, why on earth would you create a new one ?

Any class is a factory, you can create a class called 'frog', then create multiple variables of type 'frog'. This should have been at the core of the class you took. To create a class that is a control, derive it from the Control class, so that the framework knows it is a control, and can treat it as such. Reading articles on custom controls is probably a good place to start, but you may find that you can just use, or modify the existing button classes.
 
Share this answer
 
Comments
False Chicken 4-Jun-11 21:32pm    
I guess my terminology is just wrong. Sorry about that. I didn't mean literally create a entirely new button. One of the small sample apps we worked on was to just have a button bounce around in the form then have a button to apply simple gravity. I was thinking about adding more buttons to bounce around. I guess I am just asking of how to create more of the same button without manually naming all of them.
Christian Graus 4-Jun-11 21:35pm    
You can create an array of buttons, and then create new buttons and add them to the array/list. Then they all have the one name, and are accessed by index.
False Chicken 4-Jun-11 21:37pm    
Ah. Thats what I was looking for. Thanks.
Espen Harlinn 5-Jun-11 5:42am    
It's the answer, OP's happy, my 5
A class is a type. It means it is used to define multiple objects by definition (such class should be non-static). What is "multiple copies" and why?

I think you're not getting a very essence of programming. Nobody needs multiple copies of the same object. Multiple objects are needed to be different. However, if you have two objects of reference type a copy statement creates another reference to the same object, in contrast to value type: a copy of the object of value type creates a copy of the object itself. Before getting XNA programming and asking completely unclear questions about buttons, you really need to learn basics. The best tool for learning basics is development of really small and simple console application. Start from this: take a language and .NET manual and read it to the end doing simple exercises.

Don't try to develop anything before you understand type systems, classes (even without OOP), structures and their members, variables (stack, static, members—), methods and method parameters with all method of passing them.

See my past answer: I have a problem with my program. Please help![^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 5-Jun-11 5:46am    
Good point, it's usually a good idea to learn to walk before you can run, starting out with 3D, while not impossible, is certainly quite ambitious - my 5
Sergey Alexandrovich Kryukov 5-Jun-11 12:52pm    
Exactly. Thank you, Espen.
--SA

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