Can't change a button't text at runtime anymore??????
-
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
-
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
What do you mean, "Nothing Happens". If "btn" is a control on your form or webpage(depending on your solution type), then this will change the text shown on the button. I think that you have not given us a clear picture of your issue. Could you describe it a little more?
I wasn't, now I am, then I won't be anymore.
-
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
Trying that statement shouldn't even compile. Assuming you didn't complete the statement you really used (with a semi-colon,) this will normally cause the button to refresh and show "Hi" (Without quotes) like your other responder said. You can try to force a refresh with an .Invalidate Once, I tried to execute complex logic and print intermediate results by modifying text boxes' .Text property. Wanted to know why that wasn't working. Your winapp has to be idle and waiting for a response before it will render the changes. I fixed that by assigning a delegate in the winapp, running the calculations on another thread and calling the delegate.
-
What do you mean, "Nothing Happens". If "btn" is a control on your form or webpage(depending on your solution type), then this will change the text shown on the button. I think that you have not given us a clear picture of your issue. Could you describe it a little more?
I wasn't, now I am, then I won't be anymore.
Hi again What I mean with "nothing happens" is that the button btn's text is still By.Even if the bool folder's property Visible is changed to true. I have tried I have the code in the buttons click event.
private void btn_Click(object sender, EventArgs e)
{
if (folder.Visible==true )
{
btn.Text = "Hi";
}
else
{
btn.Text = "By";
}}
I have tried btn.Invalidate(); and Form1.Invalidate(); it didn't help. And I also tried with Refresh() and Update() on both btn and Form1. Dear KP Lee I don't understand how to or what you mean I should do "I fixed that by assigning a delegate in the winapp, running the calculations on another thread and calling the delegate." Many Thanks Fia
-
Hi again What I mean with "nothing happens" is that the button btn's text is still By.Even if the bool folder's property Visible is changed to true. I have tried I have the code in the buttons click event.
private void btn_Click(object sender, EventArgs e)
{
if (folder.Visible==true )
{
btn.Text = "Hi";
}
else
{
btn.Text = "By";
}}
I have tried btn.Invalidate(); and Form1.Invalidate(); it didn't help. And I also tried with Refresh() and Update() on both btn and Form1. Dear KP Lee I don't understand how to or what you mean I should do "I fixed that by assigning a delegate in the winapp, running the calculations on another thread and calling the delegate." Many Thanks Fia
-
Hi again What I mean with "nothing happens" is that the button btn's text is still By.Even if the bool folder's property Visible is changed to true. I have tried I have the code in the buttons click event.
private void btn_Click(object sender, EventArgs e)
{
if (folder.Visible==true )
{
btn.Text = "Hi";
}
else
{
btn.Text = "By";
}}
I have tried btn.Invalidate(); and Form1.Invalidate(); it didn't help. And I also tried with Refresh() and Update() on both btn and Form1. Dear KP Lee I don't understand how to or what you mean I should do "I fixed that by assigning a delegate in the winapp, running the calculations on another thread and calling the delegate." Many Thanks Fia
The other thing to check is that the click event is hooked to the event handler: put a breakpoint on the first line to make sure it is being executed, and then single step through.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
The other thing to check is that the click event is hooked to the event handler: put a breakpoint on the first line to make sure it is being executed, and then single step through.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Hi Thanks for your answers. I have already stepped through the code and it's running as it should, but the button's Text still doesn't change. I don't understand what to do????. Many Thanks Fia
OK: I took an existing form, and dropped a button on it. I double clicked the button and in the handler method that came up:
private void button1\_Click(object sender, EventArgs e) { button1.Text = button1.Text == "Hello" ? "Goodbye" : "Hello"; }
When I ran the app, the button caption was "button1". When I pressed it the first time, it changed to "Goodbye" A second click, it became "Hello". Third click, back to "Goodbye", and round and round. What am I doing that is different to you, or you doing that is different to me?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
OK: I took an existing form, and dropped a button on it. I double clicked the button and in the handler method that came up:
private void button1\_Click(object sender, EventArgs e) { button1.Text = button1.Text == "Hello" ? "Goodbye" : "Hello"; }
When I ran the app, the button caption was "button1". When I pressed it the first time, it changed to "Goodbye" A second click, it became "Hello". Third click, back to "Goodbye", and round and round. What am I doing that is different to you, or you doing that is different to me?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
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
-
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