c# timer

Still working on that multibutton thing, and getting there. Now
Id like to display a form only after a certain time has elapsed.
I have a button which has a built in hover event, it all works ok, how can I delay that hover event for say a couple of seconds.

If You need some of my code to give any hints, Ill be watching this site.

thanks

Comments

  • Hi

    You can use the
    window.setTimeout("showBanner()", speed);

    Look at
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/settimeout.asp

    also see the cleartimeout method.
  • : Hi
    :
    : You can use the
    : window.setTimeout("showBanner()", speed);
    :
    : Look at
    : http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/settimeout.asp
    :
    : also see the cleartimeout method.
    :
    Thanks for Your reply, I was wondering when Youd answer to one of my qusetions, You seem to be very active when it comes to answering questions.
    I still have little experience in C# and programming in general, I started my training August last year, English is not my mothertongue.

    That is probably why Your hint doesnt help me along. The application Im writing with Visual C# is not for html pages.

    Greetings from Germany
  • [b][red]This message was edited by lyubo at 2003-5-2 9:24:27[/red][/b][hr]
    [b][red]This message was edited by lyubo at 2003-5-2 9:15:36[/red][/b][hr]
    : Still working on that multibutton thing, and getting there. Now
    : Id like to display a form only after a certain time has elapsed.
    : I have a button which has a built in hover event, it all works ok, how can I delay that hover event for say a couple of seconds.
    :
    : If You need some of my code to give any hints, Ill be watching this site.
    :
    : thanks
    :
    Q: How can I delay that hover event for say a couple of seconds
    A: One way is to override the event handler :)
    Q:If You need some of my code to give any hints, Ill be watching this site.
    A: yes, i may get things clearer and give you better advise.

    P.S: You learn C# since August 2002? Well that's a lotta time compared to me :). I learn C# for two months now, here is my first project's Beta version. I call it Cryptographer .NET Tester's Beta: http://lmilev.hit.bg/CSFX.exe
    I got two web services on the way thought.
    One for dictionary translation Bulgarian to English and vica versa. Built on that dict. ws i'm doing many interfaces like MobileWeb, other ASP.NET Web sites, Desktop interfaces, PocketPC interfaces, that all use the web to contact my web service and retrieve data from the dictionary.
    And one for text transformation Bulgarian to Latin and vica versa.

  • Thanks for Your answer,
    No its not c# Im learning since August, first its been C++, a bit of html and SQL, a lot about network and plenty of other computer basics.
    Ive never done any programming before, so You still reckon Im a bit slow? However, Ill get there.
    Back to my question.

    here is some of the code
    public class ChocolateForm : System.Windows.Forms.Form
    {.....................
    private System.ComponentModel.Container components = null;
    private System.Windows.Forms.ImageList mImageList = null;
    private int mCntColums = 0;
    private PartialButton[,] mButtons = null;
    private MButton mMultibtn = null;

    //construction
    public ChocolateForm(System.Windows.Forms.ImageList imageList, int cntColums, MButton father)
    {
    mImageList = imageList;
    mCntColums = cntColums;
    mMultibtn = father;
    .....

    mButtons = new PartialButton[ mCntColums, lines ];
    int imageIndex = 0;
    for ( int il = 0; il < lines; il++ )
    {
    for ( int ic = 0; ic < mCntColums; ic++ )
    {
    // button properties
    mButtons[ic, il] = new PartialButton( imageIndex );
    mButtons[ic, il].Size = new System.Drawing.Size( 22, 22 );
    mButtons[ic, il].Location = new Point(ic * 23, il * 23);
    mButtons[ic, il].ImageList = this.mImageList;
    mButtons[ic, il].ImageIndex = imageIndex;
    mButtons[ic, il].Click += new System.EventHandler( this.buttonClick );
    //declare another eventHandler for click event to close chocolate and display clicked pic

    mButtons[ic, il].Click += new System.EventHandler( this.chocoClick );
    this.Controls.Add( mButtons[ic,il] );
    imageIndex++;
    }
    }//end construction

    ...............
    //
    public class MButton : System.Windows.Forms.Button
    {

    private System.Windows.Forms.Timer myTicker;
    private System.ComponentModel.IContainer components;
    private int mColuns = 2;
    private ChocolateForm mChocolateForm = null;
    ....................
    //methode in MButton Class
    private void onMyMouseHover(object sender, EventArgs ea)
    {
    if ( mChocolateForm == null )
    {

    mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);

    //set location of chocolate, transform this.Location into screen point
    //and set screen point of chocolate to that
    Point ChocPos = this.Location; ChocPos.X = this.Size.Width;
    ChocPos.Y = this.Size.Height - this.Size.Height; //strange but works

    ChocPos = this.PointToScreen(ChocPos);
    mChocolateForm.Location = ChocPos;
    mChocolateForm.BringToFront();
    // myTicker.Enabled = true; How to set the timer to display chocolate only after time elapsed
    // myTicker.Stop();
    mChocolateForm.ShowInTaskbar = true; //set to false when finished with button
    mChocolateForm.Show();
    }
    }
    Does that make things clearer?
    greetings
  • here is my solution to my problem.

    start timer in mouse hover methode and create chocolate in timer tick methode, it seems to work

    private void onMyMouseHover(object sender, EventArgs ea)
    {
    this.myTicker.Enabled = true;
    this.myTicker.Interval = 1000; myTicker.Tick += new EventHandler(myTimerTicks);
    }

    private void myTimerTicks(object obj, EventArgs ea)
    {
    if ( mChocolateForm == null )
    {
    mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);

    //set location of chocolate, transform this.Location into screen point
    //and set screen point of chocolate to that
    Point ChocPos = this.Location;
    ChocPos.X = this.Size.Width;
    ChocPos.Y = this.Size.Height - this.Size.Height; //strange but works

    ChocPos = this.PointToScreen(ChocPos);
    mChocolateForm.Location = ChocPos;
    mChocolateForm.BringToFront();

    Timer anotherT = (Timer)obj;
    anotherT.Stop();
    anotherT.Tick -= new EventHandler(myTimerTicks);

    mChocolateForm.ShowInTaskbar = true; //set on false when finished with button
    mChocolateForm.Show();
    }
    }
    what do you say
  • Cool Man.

    Sorry I assumed you were developing on the web with html.

    Your Timer mouse over event is perfect.
    Keep in that direction, You seem to be on the right track.

    Fire the timer event on the mouse over and when the timer Timeout fires you reset the timer timeout so it doesn't keep on firing and do what ever it was you wanted to delay.

    private void button1_buttonClicked()
    {
    Timer1.Timeout = 5000; // or something to make it start counting down
    }

    private void Timer1_timerTimeout()
    {
    Timer1.timeout = 0; // or something to stop it
    // Now do whatever the timer was supposed to delay
    }

    Ps. I am just coding off the top of my head.
    You should see how the logic is supposed to solve your problem.
  • : here is my solution to my problem.


    : //set location of chocolate, transform this.Location into screen point
    : //and set screen point of chocolate to that
    : Point ChocPos = this.Location;
    : ChocPos.X = this.Size.Width;
    : ChocPos.Y = this.Size.Height - this.Size.Height; //strange but works
    :
    : ChocPos = this.PointToScreen(ChocPos);
    : mChocolateForm.Location = ChocPos;
    : mChocolateForm.BringToFront();
    :
    : Timer anotherT = (Timer)obj;
    : anotherT.Stop();
    : anotherT.Tick -= new EventHandler(myTimerTicks);
    :
    : mChocolateForm.ShowInTaskbar = true; //set on false when finished with button
    : mChocolateForm.Show();
    : }
    : }
    : what do you say
    :
    I bet your solution works, here is my way, see if you find it more attractive
    private void onMyMouseHover(object sender, EventArgs ea)
    { // begin handler
    // i luve threads ;p
    Thread chocFormCreating = new Thread(new ThreadStart(this.ChocolateFormCreator));
    chocFormCreating.Start();
    } // end handler

    private void CholocateFormCreator()
    { // begin Creator
    // wait 1 second and then create the chocolf
    Thread.Sleep(1000);
    mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);
    if ( mChocolateForm == null )
    { // begin if statement
    mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);

    //set location of chocolate, transform this.Location into screen point
    //and set screen point of chocolate to that
    Point ChocPos = this.Location;
    ChocPos.X = this.Size.Width;
    ChocPos.Y = this.Size.Height - this.Size.Height; //strange but works

    ChocPos = this.PointToScreen(ChocPos);
    mChocolateForm.Location = ChocPos;
    mChocolateForm.BringToFront();

    mChocolateForm.ShowInTaskbar = true; //set on false when finished with button
    mChocolateForm.Show();

    }// end if
    }// end creator

    Greetings from Bulgaria ;-)
  • goodonya mate, looks good and I even understand it, howzat?
    Im going to try it out. Only thing I find strange is, You creating a chocolate and then compare if null and create it again, well Ill see.
    And Ill be posting more questions.
    thanks

    : private void CholocateFormCreator()
    : { // begin Creator
    : // wait 1 second and then create the chocolf
    : Thread.Sleep(1000);
    ?????????????????
    : mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    : mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);

    : if ( mChocolateForm == null )
    : { // begin if statement
    : mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    : mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);
    :
    : //set location of chocolate, transform this.Location into screen point
    : //and set screen point of chocolate to that
    : Point ChocPos = this.Location;
    : ChocPos.X = this.Size.Width;
    : ChocPos.Y = this.Size.Height - this.Size.Height; //strange but works
    :
    : ChocPos = this.PointToScreen(ChocPos);
    : mChocolateForm.Location = ChocPos;
    : mChocolateForm.BringToFront();
    :
    : mChocolateForm.ShowInTaskbar = true; //set on false when finished with button
    : mChocolateForm.Show();
    :
    : }// end if
    : }// end creator
    :
    : Greetings from Bulgaria ;-)
    :

  • : goodonya mate, looks good and I even understand it, howzat?
    : Im going to try it out. Only thing I find strange is, You creating a chocolate and then compare if null and create it again, well Ill see.
    : And Ill be posting more questions.
    : thanks
    :
    : : private void CholocateFormCreator()
    : : { // begin Creator
    : : // wait 1 second and then create the chocolf
    : : Thread.Sleep(1000);
    : ?????????????????
    : : mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    : : mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);
    :
    : : if ( mChocolateForm == null )
    : : { // begin if statement
    : : mChocolateForm = new ChocolateForm( ImageList, mColuns, this );
    : : mChocolateForm.Closing += new System.ComponentModel.CancelEventHandler(this.chocoClosing);
    : :
    : : //set location of chocolate, transform this.Location into screen point
    : : //and set screen point of chocolate to that
    : : Point ChocPos = this.Location;
    : : ChocPos.X = this.Size.Width;
    : : ChocPos.Y = this.Size.Height - this.Size.Height; //strange but works
    : :
    : : ChocPos = this.PointToScreen(ChocPos);
    : : mChocolateForm.Location = ChocPos;
    : : mChocolateForm.BringToFront();
    : :
    : : mChocolateForm.ShowInTaskbar = true; //set on false when finished with button
    : : mChocolateForm.Show();
    : :
    : : }// end if
    : : }// end creator
    : :
    : : Greetings from Bulgaria ;-)
    : :
    :
    :
    I just copied and pasted your code with some modifications, i didn't notice the comparement you're talking about, i was just giving an example of the threading use and tryed to implement your code without really reading it thought ;-)
    I bet you can fix the code, it's peace of cake, and give it a go. Good Luck!

    Greetings from Bulgaria ;-)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories