How to enable a timer for a event of a function call?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anuhas
    New Member
    • Jan 2008
    • 23

    How to enable a timer for a event of a function call?

    Dear Experts,

    I m using a timer and I know how to enable and use it for a button click. But tell me how to enable a timer when a function is called inside a button click.

    I tried these codes but they are faulty. (Timer event was set to test_function)

    namespace test_timer
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    }

    private void button1_Click(o bject sender, EventArgs e)
    {
    this.timer1.Ena bled = true;
    test_function() ;

    }
    public void test_function()
    {
    MessageBox.Show ("Function called");
    }


    }


    Dear Experts please help me ASAP !!!!

    Anuhas......... ..
  • enggwaqas
    New Member
    • Jun 2007
    • 19

    #2
    Originally posted by Anuhas
    Dear Experts,

    I m using a timer and I know how to enable and use it for a button click. But tell me how to enable a timer when a function is called inside a button click.

    I tried these codes but they are faulty. (Timer event was set to test_function)

    namespace test_timer
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    }

    private void button1_Click(o bject sender, EventArgs e)
    {
    this.timer1.Ena bled = true;
    test_function() ;

    }
    public void test_function()
    {
    MessageBox.Show ("Function called");
    }


    }


    Dear Experts please help me ASAP !!!!

    Anuhas......... ..
    Do you want to call the timer event function on a mouse click or do you want to register an event handler (assign a function to timer) to the timer within a mouse click event handler?

    You can call the timer event function within a mouse click event, like this:

    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                t_Elapsed(sender, e);
            }
    Or if you want to register a timer event handler then try this:
    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                UBL.CRMHelper.OracleAccess objAccess = new OracleAccess();
                this.richTextBox1.Text = objAccess.Get_Bank_Name(1);
    
                Timer t = new System.Timers.Timer();
                t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
            }
    
            private void t_Elapsed(object s, EventArgs e)
            {
            }

    Comment

    Working...