|
-
Oct 2nd, 2012, 03:17 PM
#1
Thread Starter
Member
[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!
-
Oct 2nd, 2012, 03:27 PM
#2
Re: Is this possible?
try this:
vb.net Code:
directcast(me.controls("button name"), button).backcolor = color.blue
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 2nd, 2012, 03:35 PM
#3
Thread Starter
Member
Re: Is this possible?
Thank you paul for another great answer, will try this tomorrow!
-
Oct 3rd, 2012, 02:16 AM
#4
Re: Is this possible?
 Originally Posted by .paul.
try this:
vb.net Code:
directcast(me.controls("button name"), button).backcolor = color.blue
Just one point to note: the Controls collection returns a Control reference and BackColor is a property of the Control class, so no cast is actually required. It's only if you wanted to use a member of that specific type of control that you'd have to cast.
-
Oct 19th, 2012, 12:23 PM
#5
Thread Starter
Member
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?
-
Oct 19th, 2012, 01:27 PM
#6
Re: [RESOLVED] Is this possible?
((button)this.controls("button name")).backcolor = color.blue;
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 19th, 2012, 09:00 PM
#7
Re: [RESOLVED] Is this possible?
 Originally Posted by .paul.
((button)this.controls("button name")).backcolor = color.blue;
@JM. is the cast situation the same in c#?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 19th, 2012, 09:11 PM
#8
Re: [RESOLVED] Is this possible?
 Originally Posted by .paul.
@JM. is the cast situation the same in c#?
Yes it is.
-
Oct 19th, 2012, 09:18 PM
#9
Re: [RESOLVED] Is this possible?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 20th, 2012, 03:38 AM
#10
Thread Starter
Member
Re: [RESOLVED] Is this possible?
 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..
-
Oct 20th, 2012, 03:43 AM
#11
Re: [RESOLVED] Is this possible?
 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.
-
Oct 20th, 2012, 04:14 AM
#12
Thread Starter
Member
Re: [RESOLVED] Is this possible?
 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
-
Oct 20th, 2012, 04:34 AM
#13
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.
-
Oct 20th, 2012, 04:37 AM
#14
Thread Starter
Member
Re: [RESOLVED] Is this possible?
 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.
-
Oct 20th, 2012, 06:45 AM
#15
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 ().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|