Jump to content

Recommended Posts

Posted

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..

Posted
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?
  • Thanks 1
Posted

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. :D

 

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.:

 

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!)

Posted

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/library/system.windows.forms.closereason.aspx):

 

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.

  • Thanks 1
Posted

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....

Posted

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?

Posted

Here:

 

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)

Posted
Here:

 

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;

[b]namespace RamNotesDownThroat[/b]
{
   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 :D

Posted

Cheers guys - got the timer button working :D

 

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 :(

Posted

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 :(

Posted

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]

Posted
@AngryTechnician : Yeah if its manually set - reader 9 takles over - its finding out hw to change that in all my PCs now :(
Posted

Yay! It works :D

Downloaded the Adobe Installation customizer thingy and MST's Reader 9 so that it defaults over Acrobat

 

my little app now works :D

 

Will do some fine tuning, and then maybe get it up here!

Posted
You need to check e.CloseReason for a user value first, in case there's a good reason that it's actually closing

 

Hmm, shame you totally ignored this advice in your actual release...

Posted
Hmm, shame you totally ignored this advice in your actual release...

 

 

Err... Ignored no - forgot would be a better word :doh:

... Will get it sorted though :p

Posted

Hmm

[font=Consolas][size=2]
[/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] (!btnClose.Enabled || e.CloseReason == [/size][/font][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]CloseReason[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2].UserClosing)[/size][/font]
[size=2][font=Consolas]{[/font][/size]
[size=2][font=Consolas]e.Cancel = [/font][/size][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]true[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2];[/size][/font]
[size=2][font=Consolas]}[/font][/size]
[/size][/font]

 

or

 

[font=Consolas][size=2]
[/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] (!btnClose.Enabled && e.CloseReason == [/size][/font][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]CloseReason[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2].UserClosing)[/size][/font]
[size=2][font=Consolas]{[/font][/size]
[size=2][font=Consolas]e.Cancel = [/font][/size][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]true[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2];[/size][/font]
[size=2][font=Consolas]}[/font][/size]
[/size][/font][font=Times New Roman][size=3]

[/size][/font]

Posted
Hmm

[font=Consolas][size=2]
[/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] (!btnClose.Enabled || e.CloseReason == [/size][/font][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]CloseReason[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2].UserClosing)[/size][/font]
[size=2][font=Consolas]{[/font][/size]
[size=2][font=Consolas]e.Cancel = [/font][/size][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]true[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2];[/size][/font]
[size=2][font=Consolas]}[/font][/size]
[/size][/font]

 

or

 

[font=Consolas][size=2]
[/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]if[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] (!btnClose.Enabled && e.CloseReason == [/size][/font][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]CloseReason[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2].UserClosing)[/size][/font]
[size=2][font=Consolas]{[/font][/size]
[size=2][font=Consolas]e.Cancel = [/font][/size][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]true[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2];[/size][/font]
[size=2][font=Consolas]}[/font][/size]
[/size][/font][font=Times New Roman][size=3]

[/size][/font]

 

The second option, otherwise the form will go ahead and close either way

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...