+ Post New Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 36
Coding Thread, C# - Button delay timer in Coding and Web Development; Anyone know how to disable a button until a certain time has passed (eg 30 seconds) - then enable it? ...
  1. #1

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,678
    Thank Post
    861
    Thanked 650 Times in 431 Posts
    Rep Power
    499

    C# - Button delay timer

    Anyone know how to disable a button until a certain time has passed (eg 30 seconds) - then enable it?

    Have been asked to create an app to force staff to read our bulletins on their PC so we can stop the paper ones..

  2. #2

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115
    Never done it, but guessing: Have the button hidden/disabled to begin with, use a Timer (that fires after 30 secs) pointing at a little function to make the button visible/work?

  3. Thanks to PiqueABoo from:

    Gatt (3rd February 2010)

  4. #3

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,678
    Thank Post
    861
    Thanked 650 Times in 431 Posts
    Rep Power
    499
    Yeah thats what i've been thinking - gonna try in the morning

  5. #4

    AngryTechnician's Avatar
    Join Date
    Oct 2008
    Posts
    3,730
    Thank Post
    698
    Thanked 1,212 Times in 761 Posts
    Rep Power
    395
    PiqueABoo's technical solution is absolutely spot on.

    Personally I would go for the non-technical solution of asking SMT to inform staff that reading the bulletin is a non-optional part of their job, but we all know how management love to take the technical solution because it's easier... for them.

    You will also need to look into a way of stopping staff from closing the window using the X in the top right, or by closing it from the taskbar, or using Alt+F4. They may not know those tricks immediately, but eventually someone will find them. To do this, you should define a handler for the form's FormClosing event to test if the button is still disabled and cancel the window close if it is, e.g.:

    Code:
    private void FormName_FormClosing(object sender, FormClosingEventArgs e)
    {
    
    if (CloseButton.Disabled)
    {
    e.Cancel = true;
    }
    
    }
    (Written outside the IDE, so it may not be 100% correct!)

  6. #5

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    You need to check e.CloseReason for a user value first, in case there's a good reason that it's actually closing (see http://msdn.microsoft.com/en-us/libr...ereason.aspx):

    Code:
    private void FormName_FormClosing(object sender, FormClosingEventArgs e)
    {
       if (e.CloseReason == CloseReason.UserClosing)
       {
          e.Cancel = true;
       }
    }
    (also written from outside the IDE, so check it carefully).


    However, this is one more thing that isn't better solved with technology. If staff aren't reading the notes and making themselves aware of the information they need to do their job, there should be disciplinary repercussions - then the people that do toe the line aren't being punished for nothing.

  7. Thanks to powdarrmonkey from:

    AngryTechnician (4th February 2010)

  8. #6

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,678
    Thank Post
    861
    Thanked 650 Times in 431 Posts
    Rep Power
    499
    I have a simple form (FixedDialog Modal) with all the min/max/close buttons turned off and "Close" button

    I have tried using System.Theading.Thread.Sleep(30000); to delay the button - problem is in trying to figure out where to place it.. so far i have managed todelay opening the form for 30 seconds... put it anywhere else and it either doesnt build or doesnt run....

  9. #7

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    You need to:

    - declare a timer object member of the class
    - in initialisation, allocate it and hook up an event handler to it
    - handle the Show event and in there, set the timer to 30s and activate it
    - when the event fires, make your close button active

    I also realised your need to combine my snippet with AngryTechnician's, I didn't spot the logic flaw - do you?

  10. #8

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Here:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace RamNotesDownThroat
    {
        public partial class NotesForm : Form
        {
            private System.Timers.Timer closeTimer = new System.Timers.Timer(10000) { AutoReset = false };
    
            public NotesForm()
            {
                InitializeComponent();
                closeTimer.Elapsed += new System.Timers.ElapsedEventHandler(closeTimer_Elapsed);
                closeTimer.SynchronizingObject = this;
                closeTimer.Enabled = true;
                btnClose.Enabled = false;
            }
    
            void closeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                if (!btnClose.Enabled)
                    btnClose.Enabled = true;
            }
    
            private void btnClose_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void NotesForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                if ((!btnClose.Enabled) && (e.CloseReason == CloseReason.UserClosing))
                    e.Cancel = true;
            }
        }
    }
    (I grant this code to the public domain subject to no liability or warranty express or implied)

  11. #9

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,811
    Thank Post
    3,327
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365
    Quote Originally Posted by powdarrmonkey View Post
    Here:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace RamNotesDownThroat
    {
        public partial class NotesForm : Form
        {
            private System.Timers.Timer closeTimer = new System.Timers.Timer(10000) { AutoReset = false };
    
            public NotesForm()
            {
                InitializeComponent();
                closeTimer.Elapsed += new System.Timers.ElapsedEventHandler(closeTimer_Elapsed);
                closeTimer.SynchronizingObject = this;
                closeTimer.Enabled = true;
                btnClose.Enabled = false;
            }
    
            void closeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                if (!btnClose.Enabled)
                    btnClose.Enabled = true;
            }
    
            private void btnClose_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void NotesForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                if ((!btnClose.Enabled) && (e.CloseReason == CloseReason.UserClosing))
                    e.Cancel = true;
            }
        }
    }
    (I grant this code to the public domain subject to no liability or warranty express or implied)
    lmao @ the name space

  12. #10

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,678
    Thank Post
    861
    Thanked 650 Times in 431 Posts
    Rep Power
    499
    Cheers guys - got the timer button working

    But got another issue.

    Adobe Acrobat 8 vs Windows 7 = problem :|

    basically Acrobat 8 brings up the error highlighted here - Adobe Forums: "Cannot use adobe reader to view pdf in...

    whhich kinda breaks the app (using the webBrowser component to view a PDF file) until the user clicks ok (whcih is hidden behind my app!)

    Now trying t find alternate ways to display the PDF...

    Tried FOXIT - but it doesn't seem to want to integrate with IE when deployed via GPO

  13. #11

    AngryTechnician's Avatar
    Join Date
    Oct 2008
    Posts
    3,730
    Thank Post
    698
    Thanked 1,212 Times in 761 Posts
    Rep Power
    395
    Any reason you haven't moved to Reader 9?

  14. #12

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,678
    Thank Post
    861
    Thanked 650 Times in 431 Posts
    Rep Power
    499
    Reader 9 is installed

    but so is CS3 on all our machines - and it seems to default to using Acrobat 8 Pro for all PDFs

  15. #13

    AngryTechnician's Avatar
    Join Date
    Oct 2008
    Posts
    3,730
    Thank Post
    698
    Thanked 1,212 Times in 761 Posts
    Rep Power
    395
    Right, I see. Acrobat does take precedence regardless of version, unless you override it in your deployment using the Adobe Customization Wizard.

    Are you able to set Reader 9 to handle PDFs in a browser manually on one machine, to at least test whether that would make a difference?

  16. #14

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,885
    Thank Post
    518
    Thanked 2,489 Times in 1,930 Posts
    Blog Entries
    24
    Rep Power
    839
    have you thought about integrating it using PDF Clown or similar open source PDF viewing libraries?

    PDF Clown | Get PDF Clown at SourceForge.net

  17. #15

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,811
    Thank Post
    3,327
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365
    Just thought that the following Wikipedia link would be of use with ref to other suggestions for pdf viewers etc

    [ame=http://en.wikipedia.org/wiki/List_of_PDF_software]List of PDF software - Wikipedia, the free encyclopedia[/ame]

SHARE:
+ Post New Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. Anybody got free countdown timer?
    By Hightower in forum Educational Software
    Replies: 17
    Last Post: 19th December 2009, 01:56 PM
  2. LANSchool - inactivity timer kicking in
    By googlemad in forum Network and Classroom Management
    Replies: 3
    Last Post: 19th February 2009, 09:31 PM
  3. First timer
    By Simcfc73 in forum BETT 2014
    Replies: 7
    Last Post: 1st December 2008, 08:23 AM
  4. HELP:::Internet Timer
    By bats in forum Downloads
    Replies: 5
    Last Post: 13th June 2008, 11:23 PM
  5. Countdown Timer to School Holidays
    By mattpant in forum Coding
    Replies: 4
    Last Post: 17th January 2007, 11:42 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •