An odd predicament with windows forms
-
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten. Making a new button... Button newButton = new Button(); (tell me if this is even works, because I'm not really all that sure if it does). And that's all I can come up with. I've tried really hard to make that button appear after the others ones are disposed and I THINK it might have something to do with newButton.Location.X/Y. But that's just a guess. So it would be greatly appreciated if anyone could offer me any help. I do not ask for code I simple ask for a little guidance to my next step. Thanks, Nik!
-
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten. Making a new button... Button newButton = new Button(); (tell me if this is even works, because I'm not really all that sure if it does). And that's all I can come up with. I've tried really hard to make that button appear after the others ones are disposed and I THINK it might have something to do with newButton.Location.X/Y. But that's just a guess. So it would be greatly appreciated if anyone could offer me any help. I do not ask for code I simple ask for a little guidance to my next step. Thanks, Nik!
-
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten. Making a new button... Button newButton = new Button(); (tell me if this is even works, because I'm not really all that sure if it does). And that's all I can come up with. I've tried really hard to make that button appear after the others ones are disposed and I THINK it might have something to do with newButton.Location.X/Y. But that's just a guess. So it would be greatly appreciated if anyone could offer me any help. I do not ask for code I simple ask for a little guidance to my next step. Thanks, Nik!
-
After you create the button Button newButton = new Button() you have to set its x and y coordinates, width and height, and add it to the form: this.Controls.Add(newButton);
Well I thank you greatly for that much of help and I must say that it helped but I am not sure how to set the X and Y variables. I have tried newButton.Location.X, but when I try setting it equal to an int it says that I can't modify the return variable of Location because it is not a variable. Do you know a way to go around it?
-
Maybe you should have a look at the code that the winforms designer generates - it explains how you'd have to do it manually. (expand the Form.cs file and open the Form.designer.cs file, then expand the "Windows Form Designer generated code" region)
-
Well I thank you greatly for that much of help and I must say that it helped but I am not sure how to set the X and Y variables. I have tried newButton.Location.X, but when I try setting it equal to an int it says that I can't modify the return variable of Location because it is not a variable. Do you know a way to go around it?
It probably returns a struct (Point), modifying a field of the struct would be kinda useless since as soon as you leave the current scope that struct will be gone (or even if isn't, it's not the same struct as the control has, but a copy) So, what should work: copy the Location to a local, change the X, assign it back to newButton.Location. hey, who downvoted this :| It would work. Nothing bad about it either.
Last modified: 11hrs 5mins after originally posted --
-
Wow I can't believe I didn't think of that. Thank you very much you helped me greatly!!! :)
-
Well I thank you greatly for that much of help and I must say that it helped but I am not sure how to set the X and Y variables. I have tried newButton.Location.X, but when I try setting it equal to an int it says that I can't modify the return variable of Location because it is not a variable. Do you know a way to go around it?
Hi, to set the location of a Control do one of these:
myControl.Location=new Point(x,y);
myControl.Bounds=new Rectangle(x,y,width,height);Both Location and Bounds are structs, i.e. value types; gettin such struct and modifying it won't cut it, you have to provide a struct with the new values. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten. Making a new button... Button newButton = new Button(); (tell me if this is even works, because I'm not really all that sure if it does). And that's all I can come up with. I've tried really hard to make that button appear after the others ones are disposed and I THINK it might have something to do with newButton.Location.X/Y. But that's just a guess. So it would be greatly appreciated if anyone could offer me any help. I do not ask for code I simple ask for a little guidance to my next step. Thanks, Nik!
-
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten. Making a new button... Button newButton = new Button(); (tell me if this is even works, because I'm not really all that sure if it does). And that's all I can come up with. I've tried really hard to make that button appear after the others ones are disposed and I THINK it might have something to do with newButton.Location.X/Y. But that's just a guess. So it would be greatly appreciated if anyone could offer me any help. I do not ask for code I simple ask for a little guidance to my next step. Thanks, Nik!
nik121 wrote:
When that happens I am trying to make a different button take its place.
Why not just add the "new" button at design time and set its visibility to hidden? When the time comes to "create" it, just show the button. That will save you having to set all its properties at run time. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten. Making a new button... Button newButton = new Button(); (tell me if this is even works, because I'm not really all that sure if it does). And that's all I can come up with. I've tried really hard to make that button appear after the others ones are disposed and I THINK it might have something to do with newButton.Location.X/Y. But that's just a guess. So it would be greatly appreciated if anyone could offer me any help. I do not ask for code I simple ask for a little guidance to my next step. Thanks, Nik!
nik121 wrote:
Hello I'm new to C# so you might have to bear with me a little bit but here is my problem. I am trying to make a windows form so that when you press a button, all the buttons disappear from the form. When that happens I am trying to make a different button take its place. You might find this a strange thing to do... but I have my reasons ;P. This is as far as I have gotten.
Another way to go is add all the buttons your going to use the first time around. Then decide which are to be visible and which are not. If you're putting to a form, all the buttons will have they're properties shown in the properties tab. There you can get the individual poperties, including visiblity. I've got my properties in alphabetical order, just to find them, I hate searching. Then just program behavoir of the buttons Have a good time L.