Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6318429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:38:13+00:00 2026-05-24T15:38:13+00:00

I have a WPF user control called TimerUserControl where contains a timer. And I

  • 0

I have a WPF user control called TimerUserControl where contains a timer. And I have another user control where show questions, this one has a NextQuestion function.

The timer has 2 minutes like an interval, and I’d like to invoke the NextQuestion function when it has done. I think I have to use delegates, but I’m not sure.

UPDATE 1:

public partial class TimeUserControl : UserControl
{
    public int _totalSeconds;
    public int _secondsRemaining;
    public DispatcherTimer timerSecondsLeft;

    public TimeUserControl()
    {
        InitializeComponent();

        timerSecondsLeft = new DispatcherTimer();
        timerSecondsLeft.Tick += new EventHandler(timerSecondsLeft_Tick);
        timerSecondsLeft.Interval = new TimeSpan(0, 0, 1);
    }

    public bool TimesUp
    {
        get;
        set;
    }

    public void SetSeconds(int seconds)
    {
        timerSecondsLeft.Stop();

        if (seconds == 0)
        {
            TimeTextBlock.Text = "There's no time! Hurray";
        }
        else
        {
            _totalSeconds = seconds;
            _secondsRemaining = seconds;

            TimeTextBlock.Text = string.Format("It remains {0} seconds. Don't take long!", _totalSeconds);
            timerSecondsLeft.Start();
        }
    }

    public void timerSecondsLeft_Tick(object sender, EventArgs e)
    {
        _secondsRemaining--;

        if (_secondsRemaining <= 0)
        {
            timerSecondsLeft.Stop();

            TimesUp = true;
            TimeTextBlock.Text = "Time's up. Press Enter to next problem.";

            // HERE WILL INVOKE NEXTQUESTION FUNCTION
        }
        else
        {
            TimeTextBlock.Text = string.Format("It remains {0} seconds. Don't take long!", _secondsRemaining);
        }
    }
}

Look in the code, the comment is this possible ussing delegates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:38:14+00:00Added an answer on May 24, 2026 at 3:38 pm

    So you need to do a few things. You have to add some code to you’re user control.

    // Declare this outside your usercontrol class
    public delegate void TimerExpiredEventHandler(object sender, EventArgs e);
    

    This is what needs to be added to your code for the user control.

    public partial class TimerUserControl : UserControl
    {
        public event TimerExpiredEventHandler Expired;
    
        public void OnExpired(EventArgs e)
        {
            if (Expired != null)
                Expired(this, e);
        }
    
    public void timerSecondsLeft_Tick(object sender, EventArgs e)
    {
        _secondsRemaining--;
    
        if (_secondsRemaining <= 0)
        {
            timerSecondsLeft.Stop();
    
            TimesUp = true;
            TimeTextBlock.Text = "Time's up. Press Enter to next problem.";
    
            // Fire the event here.
            OnExpired(EventArgs.Empty);
        }
        else
        {
            TimeTextBlock.Text = string.Format("It remains {0} seconds. Don't take long!", _secondsRemaining);
        }
    }
    
    }
    

    Now you need to subscribe to this event inside whatever is calling this usercontrol in the first place.

    public partial class ParentForm : Form
    {
        private void ParentForm_Load(object sender, EventArgs e)
        {
             var timer = new TimerUserControl();
             //Subscribe to the expired event that we defined above.
             timer.Expired += new EventArgs(Timer_Expired);
        }
    
        public void Timer_Expired(object sender, EventArgs e)
        {
            //Handle the timer expiring here. Sounds like you are calling another function, so do that here.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF user control with a number of textboxes, this is hosted
I have a newbie WPF question. Imagine my user control has a namespace declaration
I am developing a WPF application, and I have created a user control called
I have a user control which contains a textbox. I have a class called
I'm using VB.Net. I have a WPF User Control called NavigationPanel which I created
I have a custom WPF user control called a TimeoutPanel that I am trying
This one has me beat; I have a WPF window with two (important for
I have a WPF window which has a ItemsControl which contains list of User
I have a WPF User Control that really contains only a template expander. And
I have a wpf user control which exposes an IEnumerable ItemsSource DependencyProperty. I bind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.