[RESOLVED] Is this possible?
Is it possible to replace "button1.backcolor" or just "button1" in this code with a variable(which will contain a buttons name):
private sub()
button1.backcolor = color.blue
end sub
So instead the code would be :
private sub()
variablename = color.blue
end sub
Thanks!
Re: [RESOLVED] Is this possible?
I know that this post isn't in the c# section, but what's the C# way of doing this exact thing?
Re: [RESOLVED] Is this possible?
((button)this.controls("button name")).backcolor = color.blue;
Re: [RESOLVED] Is this possible?
Quote:
Originally Posted by
.paul.
((button)this.controls("button name")).backcolor = color.blue;
@JM. is the cast situation the same in c#?
Re: [RESOLVED] Is this possible?
Quote:
Originally Posted by
.paul.
@JM. is the cast situation the same in c#?
Yes it is.
Re: [RESOLVED] Is this possible?
Re: [RESOLVED] Is this possible?
Quote:
Originally Posted by
.paul.
((button)this.controls("button name")).backcolor = color.blue;
Code:
block15.Top = ((Panel)this.controls(posY)).Top;
This doesnt seem to work..
Re: [RESOLVED] Is this possible?
Quote:
Originally Posted by
ErikJohansson
Code:
block15.Top = ((Panel)this.controls(posY)).Top;
This doesnt seem to work..
Then you're doing it wrong. What's the value of posY? Does it contain the name of a Panel on your form? What actually happens when you run that code? Is an exception thrown? Please provide us with all the relevant information rather than expect us to divine it from one line of code that we know would work if used properly.
Re: [RESOLVED] Is this possible?
Quote:
Originally Posted by
jmcilhinney
Then you're doing it wrong. What's the value of posY? Does it contain the name of a Panel on your form? What actually happens when you run that code? Is an exception thrown? Please provide us with all the relevant information rather than expect us to divine it from one line of code that we know would work if used properly.
posY is a string and it's value is "panel16". "controls" in the line of code is underlined red and the error in the Error List is:
Error 1 'Slider_Puzzle.Form1' does not contain a definition for 'controls' and no extension method 'controls' accepting a first argument of type 'Slider_Puzzle.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\Erik\documents\visual studio 2010\Projects\Slider Puzzle\Slider Puzzle\Form1.cs 32 44 Slider Puzzle
Re: [RESOLVED] Is this possible?
Aha, you're coding in C#, which is case-sensitive, and you just copied and pasted .paul.'s code. If you had typed it then Intellisense would have shown you that, like all properties, Controls begins with an upper case letter. It does in VB as well but VB is not case-sensitive so the IDE changes the case for you.
Re: [RESOLVED] Is this possible?
Quote:
Originally Posted by
jmcilhinney
Aha, you're coding in C#, which is case-sensitive, and you just copied and pasted .paul.'s code. If you had typed it then Intellisense would have shown you that, like all properties, Controls begins with an upper case letter. It does in VB as well but VB is not case-sensitive so the IDE changes the case for you.
hmmm... I'm getting this error now:
Non-invocable member 'System.Windows.Forms.Control.Controls' cannot be used like a method.
Re: [RESOLVED] Is this possible?
This is why you should post C# questions in the C# forum. Do you know how to write C# code or not? Controls is a collection and if you want to index a collection in C# you use brackets [], not parentheses ().