C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-12-2007, 02:59 AM   #1
Registered User
 
Join Date: Sep 2006
Posts: 98
Creating an object at run-time

Is it possible to create an object such as a button or text box at run-time? For example, is it possible to start the program with an empty window, and then add all the controls in code when the program is running?
Thanks
Mavix is offline   Reply With Quote
Old 06-12-2007, 03:02 AM   #2
Registered User
 
Join Date: Sep 2006
Posts: 98
BTW, I'm using Visual C# 2005 Express edition
Mavix is offline   Reply With Quote
Old 06-12-2007, 09:19 AM   #3
Registered User
 
AtomRiot's Avatar
 
Join Date: Jan 2003
Posts: 120
like on a timer? or just from user interaction?

like if you have only one button on your form, then when clicked it would create text boxes or other buttons? something like this?

the easiest way is to right click on your InitializeComponent(); method in your main form and then go to "Go To Definition" and it will point you to the forms behind the scenes area. You can look at how things are created there like the definitions it sets like tab index, name, size, location, text and any listeners like Click or MouseMove in that area. Then you should use either this.Controls.Add(the button) like at the bottom of that function.
__________________
All Your Base Are Still Belong to Someone!!!
And you Remember that!!!
AtomRiot is offline   Reply With Quote
Old 06-12-2007, 11:51 AM   #4
Registered User
 
Join Date: Sep 2006
Posts: 98
Quote:
Originally Posted by AtomRiot View Post
like on a timer? or just from user interaction?

like if you have only one button on your form, then when clicked it would create text boxes or other buttons? something like this?

the easiest way is to right click on your InitializeComponent(); method in your main form and then go to "Go To Definition" and it will point you to the forms behind the scenes area. You can look at how things are created there like the definitions it sets like tab index, name, size, location, text and any listeners like Click or MouseMove in that area. Then you should use either this.Controls.Add(the button) like at the bottom of that function.
I will try what you said, but what I want to do is start with an empty form with nothing at all on it. Then in the code I want to add all the objects such as buttons and text boxes etc, and move them into their positions. All that must take place when the program is running.
Mavix is offline   Reply With Quote
Old 06-12-2007, 11:59 AM   #5
Registered User
 
AtomRiot's Avatar
 
Join Date: Jan 2003
Posts: 120
well thats what i was confused about, you want to start with an empty form so you run the app and then have stuff appear later?
or you just want to manually add all the controls in the code yourself without the help of the ide and then run the app?
__________________
All Your Base Are Still Belong to Someone!!!
And you Remember that!!!
AtomRiot is offline   Reply With Quote
Old 06-12-2007, 12:16 PM   #6
Registered User
 
Join Date: Sep 2006
Posts: 98
A mix of the two, actually. The form will start blank, and then at the beggining of the program some controls will be added, and then maybe later in the program some more. But not with a timer.
Mavix is offline   Reply With Quote
Old 06-12-2007, 01:19 PM   #7
Registered User
 
AtomRiot's Avatar
 
Join Date: Jan 2003
Posts: 120
ok, i see. You just dont want the GUI portion to do everything for you. You want to handle everything past the creation of the form.

in that case, i would make a test project and just drag some controls like buttons and whatnot onto your form, and then check out how it created them. That would give you a start. From there, you could go over to your app and put what you need in the form constructor and then handle the rest as you go.
__________________
All Your Base Are Still Belong to Someone!!!
And you Remember that!!!
AtomRiot is offline   Reply With Quote
Old 06-13-2007, 05:46 AM   #8
Registered User
 
Join Date: Sep 2006
Posts: 98
Quote:
Originally Posted by AtomRiot View Post
ok, i see. You just dont want the GUI portion to do everything for you. You want to handle everything past the creation of the form.

in that case, i would make a test project and just drag some controls like buttons and whatnot onto your form, and then check out how it created them. That would give you a start. From there, you could go over to your app and put what you need in the form constructor and then handle the rest as you go.
Thanks, now this is where this thread and my other one come together. How would I create, and control the controls on form2 while on form1? In the mean time I'll play around with what you said.
Mavix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to time how long a program takes to run? advancedk C Programming 2 08-18-2008 07:50 PM
Displaying Function Run Time pf732k3 C Programming 1 03-21-2008 12:36 PM
Run time differences in Linux gcc versions circuitbreaker C++ Programming 7 02-14-2008 11:09 PM
Please help - Run time error barkercs C Programming 6 05-03-2006 11:15 AM
Create class at run time muaed A Brief History of Cprogramming.com 3 04-11-2002 08:13 AM


All times are GMT -6. The time now is 05:48 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22