Can't change a button't text at runtime anymore??????
-
Hi I can't see any difference. Here is my code.
private void btn_Click(object sender, EventArgs e)
{
if (folder.Visible==true )
{
btn.Text = "Hi";
}
else
{
btn.Text = "By";
}
}The variable folder is just a bool variable. When I debug my code I can see that it runs as it should, but still the button's Text doesn't change. I don't know if it has anything to do with the problem, but I have a FileLListbox and a FolderListBox from Alva on the form. Should that be the problem. Many Thanks Fia
Try something quick: Put a breakpoint on the
if
line of the handler, and change teh button text in the designer to "TEST". Run your app, and press the button. Look at btn.Text in the debugger - is it "TEST"?Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Try something quick: Put a breakpoint on the
if
line of the handler, and change teh button text in the designer to "TEST". Run your app, and press the button. Look at btn.Text in the debugger - is it "TEST"?Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Hi I tried that and the text is "Test". I tried also to remove all Alva controls, but I still can't change the text on the button. :( Thanks Fia
So at least we can be absolutely sure that the right button is hooked up - if you replace the handler content with
btn.Text = "WTF!";
and single step over that one instruction, is the text still "Test" or "WTF!" - I'm just wondering if the text is being changed back somewhere else (which would be a weird thing to do automatically)
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
So at least we can be absolutely sure that the right button is hooked up - if you replace the handler content with
btn.Text = "WTF!";
and single step over that one instruction, is the text still "Test" or "WTF!" - I'm just wondering if the text is being changed back somewhere else (which would be a weird thing to do automatically)
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Hi It changes to "WTF" in the code, but after the event. The buttons text is "Test"????? Thanks Fia
:wtf: Something has got to be changing it back! Delete it. Rebuild. That should give you any errors that refer to it. If there aren't any, put it back and repeat the above, see if it works. Either that or you have a PC full of malevolent pixies... :laugh:
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Hi When I could change the text at runtime, I think the property was called Capture. How do you do in Visual Studio 2010? If I set the button btn's property Text to "By" and try the below
btn.Text="Hi"
nothing happens. How do I do it nowadays :confused: Many Thanks Fia
private void btn_Click(object sender, EventArgs e)
{
if (folder.Visible==true )
{
btn.Text = "Hi";
}
else
{
btn.Text = "By";
}}
Make sure your property folder.Visible is change when click state btn.Text = folder.Visible?"Hi":By; folder.Visible=!folder.Visible; // reset state here
TU
-
private void btn_Click(object sender, EventArgs e)
{
if (folder.Visible==true )
{
btn.Text = "Hi";
}
else
{
btn.Text = "By";
}}
Make sure your property folder.Visible is change when click state btn.Text = folder.Visible?"Hi":By; folder.Visible=!folder.Visible; // reset state here
TU
-
Hi When I could change the text at runtime, I think the property was called Capture. How do you do in Visual Studio 2010? If I set the button btn's property Text to "By" and try the below
btn.Text="Hi"
nothing happens. How do I do it nowadays :confused: Many Thanks Fia
Given all the responses above, clearly something very weird is happening here. Are you talking about a standard WinForms Button object here ? Also: what is "folder," exactly: that's an odd name for a Control. And, if "folder" has a boolean "visible" property, you can use it directly : if (folder.Visible) ... You mention: "I don't know if it has anything to do with the problem, but I have a FileLListbox and a FolderListBox from Alva on the form. Should that be the problem." Is "folder" by chance an "Alva" control ? What are the "Alva" controls, and, is it possible your use of them has introduced some kind of modification that is indirectly changing the way other controls behave ? good luck, Bill
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
-
Hi It changes to "WTF" in the code, but after the event. The buttons text is "Test"????? Thanks Fia
Put a breakpoint in your code in this routine. Search through your code for all instances of the word Test and put breakpoints on them all - each and everyone. Run the program again and note each breakpoint you hit - you must be resetting the text back to Test after you have left this routine.
Forgive your enemies - it messes with their heads
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Given all the responses above, clearly something very weird is happening here. Are you talking about a standard WinForms Button object here ? Also: what is "folder," exactly: that's an odd name for a Control. And, if "folder" has a boolean "visible" property, you can use it directly : if (folder.Visible) ... You mention: "I don't know if it has anything to do with the problem, but I have a FileLListbox and a FolderListBox from Alva on the form. Should that be the problem." Is "folder" by chance an "Alva" control ? What are the "Alva" controls, and, is it possible your use of them has introduced some kind of modification that is indirectly changing the way other controls behave ? good luck, Bill
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare