+ 1

I want to change the text of a text box with a button click see description for task!

i have a textbox and two buttons in visual studio c# what if i want to change the text of textbox with a click on button i have 3 colors and by default text in text box is green i want that if i click next text will change to red and on another next it will changed to blue and at this level if i click previous it will changed to red and another previous click will change it to green again i want to fluctuate between these colors but the main task is to do this all without using variable or logical condition

19th Apr 2018, 3:47 PM
komal shehzadi
komal shehzadi - avatar
2 Answers
0
It sounds like you want to do some event-driven programming. I don't know if you are working in WPF, UWP, or Windows Forms. No matter this video link will help with your problem. https://www.youtube.com/watch?v=yt_rsgFBxzk
20th Apr 2018, 9:48 PM
ODLNT
ODLNT - avatar
0
If you created a WPF or UWP app, the code would be like this: XAML <TextBlock x:Name="MyTxtBlock" Foreground="Green"/> <Button Click="MyButton_Clicked"/> C# code-behind // Use the intellisense to include // the right namespaces, as I don't // recall them SolidColorBrush MyColors { get { yield return new SolidColorBrush (Colors.Red); yield return new SolidColorBrush (Colors.Blue); yield return new SolidColorBrush (Colors.Green); } } // I can't remember by heart the params // of this event handler, but VS writes it // automatically, so you should have no // problems private void MyButton_Clicked (object sender, EventArgs e) { MyTxtBlock.Foreground = MyColors.Next(); } Note that I'm writing this just by heart, without any testing, so I don't know if it fully works. It should tho. And yet, sorry for the bad indentation, can't do much for that
24th Apr 2018, 5:43 PM
Mante
Mante - avatar