Home > Back-end >  Change Text in Button As Program Runs using value changing as timer runs
Change Text in Button As Program Runs using value changing as timer runs

Time:12-29

I am trying to create a timer system, that shows the time taken by the player as they spend time on a level, that updates in real time (using the form timer). I have used a timer (mnTimer) in the form to account for movement etc. I created a private float value at the top of the program, called game_Ticks:

public partial class Tutorial : Form
{
    private float game_Ticks;
    public Tutorial()
    {
        InitializeComponent();
    }

I then set this value to increement as the form timer ticks;

private void mnTimer(object sender, EventArgs e)
    {
        game_Ticks  ;

I am trying to make the text shown on a button (called time_Display) change to the current value of the timer, by using the value game_Ticks. I have tried using button constructors and using code such as time_Display.Text(game_Ticks) but it says that it cannot be used as a method.

time_Display.Text(game_Ticks / 50);

CodePudding user response:

If time_Display is a UI control with a .Text property then that is indeed not a method, it's a property:

time_Display.Text = (game_Ticks / 50).ToString();
  • Related