Gatt Posted February 3, 2010 Posted February 3, 2010 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..
PiqueABoo Posted February 3, 2010 Posted February 3, 2010 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? 1
Gatt Posted February 3, 2010 Author Posted February 3, 2010 Yeah thats what i've been thinking - gonna try in the morning
AngryTechnician Posted February 4, 2010 Posted February 4, 2010 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.: 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!)
powdarrmonkey Posted February 4, 2010 Posted February 4, 2010 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. 1
Gatt Posted February 4, 2010 Author Posted February 4, 2010 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....
powdarrmonkey Posted February 4, 2010 Posted February 4, 2010 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?
powdarrmonkey Posted February 4, 2010 Posted February 4, 2010 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)
mac_shinobi Posted February 4, 2010 Posted February 4, 2010 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
Gatt Posted February 4, 2010 Author Posted February 4, 2010 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
AngryTechnician Posted February 4, 2010 Posted February 4, 2010 Any reason you haven't moved to Reader 9?
Gatt Posted February 4, 2010 Author Posted February 4, 2010 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
AngryTechnician Posted February 4, 2010 Posted February 4, 2010 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?
localzuk Posted February 4, 2010 Posted February 4, 2010 have you thought about integrating it using PDF Clown or similar open source PDF viewing libraries? PDF Clown | Get PDF Clown at SourceForge.net
mac_shinobi Posted February 4, 2010 Posted February 4, 2010 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]
Gatt Posted February 4, 2010 Author Posted February 4, 2010 @AngryTechnician : Yeah if its manually set - reader 9 takles over - its finding out hw to change that in all my PCs now
mac_shinobi Posted February 4, 2010 Posted February 4, 2010 @AngryTechnician : Yeah if its manually set - reader 9 takles over - its finding out hw to change that in all my PCs now You could integrate it into this app your doing with the button System File Association - CodeProject
Gatt Posted February 4, 2010 Author Posted February 4, 2010 Yay! It works Downloaded the Adobe Installation customizer thingy and MST's Reader 9 so that it defaults over Acrobat my little app now works Will do some fine tuning, and then maybe get it up here!
powdarrmonkey Posted February 5, 2010 Posted February 5, 2010 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...
Gatt Posted February 5, 2010 Author Posted February 5, 2010 Hmm, shame you totally ignored this advice in your actual release... Err... Ignored no - forgot would be a better word ... Will get it sorted though
Gatt Posted February 5, 2010 Author Posted February 5, 2010 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]
powdarrmonkey Posted February 5, 2010 Posted February 5, 2010 Sorry, that should be || (logical or). I'd keep the brackets in though, if only to make it easier to read.
LosOjos Posted February 5, 2010 Posted February 5, 2010 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
powdarrmonkey Posted February 5, 2010 Posted February 5, 2010 otherwise the form will go ahead and close either way This is the desired behaviour.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now