Guest Brody Posted October 21, 2004 Report Posted October 21, 2004 To keep my program running in the background I have used the .Hide() method as can be seen below: alarm.Hide(); So here's my question, how do i get this form visible again!? The .Show() method seems to do nothing? Anyone got any ideas? I am aiming to unltimately stop my program being closed by the phone when it tries to reclaim memory so if you can suggest an alternative to .Hide() to achieve this then I am open to suggestions! Cheers in advance, Marc
Guest Brody Posted October 21, 2004 Report Posted October 21, 2004 OK it looks like the .Show() method is the one to use so my issue must be where I am putting the .Show() method, any suggestions as to where to put the method so that it shows the form when clicking the shortcut to the program?
Guest dh Posted October 21, 2004 Report Posted October 21, 2004 I've implemented something similar, but I don't want to show the form. When the app loads I hide it with this.Visible = false;. When the app is loaded again I do a this.Visible = false; again in the GotFocus function. If the GotFocus isn't called you may need to use the Activated function which gets called before GotFocus. Code as folows in the private void InitializeComponent() section of the Windows Form Designer generated code add the following lines this.GotFocus += new EventHandler(formname_GotFocus); //replace formname with your form name this.Activated += new System.EventHandler(formname_Activated); //replace formname with your form name Then in the main sections create two functions or whatever the are called public void FormBacklight_GotFocus(object sender, System.EventArgs e) { do stuff to show form, may not get called as form is hidden } public void FormBacklight_Activated(object sender, System.EventArgs e) { try it do a show here as well, Activated gets called first I think } Hope this helps
Guest Brody Posted October 21, 2004 Report Posted October 21, 2004 Neither of the GotFocus or Activated methods are reached when i click the EXE in a file manager to try and show the form again ^_^
Guest dh Posted October 21, 2004 Report Posted October 21, 2004 Strange, is it because you are using the .hide method? When I was trying to get my app to work I got the app to log on every function etc so I could see what was / wasn't being called. Where are you setting the .hide, maybe the problem is that the .hide is being called every time, could you do a test to see if the form had been hidden before and not do .hide if it had.
Guest Brody Posted October 21, 2004 Report Posted October 21, 2004 Break point added to the first line of EVERY method I have, the timer continues to tick in the background when the program is hidden but when i try and run the exe again to wake the program (name.Show()) NO method gains focus!? Any ideas?
Guest Paul [MVP] Posted October 22, 2004 Report Posted October 22, 2004 How about me.bringtofront in the form, and lostfocus and gotfocus events to determine if you have focus. P
Guest dh Posted October 22, 2004 Report Posted October 22, 2004 Just put the this.Hide(); in my app, the following happens. App loads and does a this.hide(); in the load. When I run the app again, (the app is running in the background), one of the first calls after resize is Activated, I place this.show(); in Activated and the form shows. Strangely I don't get a GotFocus when the app runs again. From what I've read a main form should use Activated / Deactivate rather than Got / Lost Focus.
Guest ultimasnake Posted January 7, 2005 Report Posted January 7, 2005 (edited) Well just had a look, i think it's correct that the main form doesn't raise a onfocus/lost focus event because mainly it doesn't recieve any why you ask? A form is focused is usually called when a user clicks on it.. which in the fact of a smartphone is not raised since you can't click it :D. Also note that once you have ANY control that does accept focus you can never focus the form/unfocus the control. I think this has to do with the fact that you just can't do anything you could do with a touchscreen/mousepointer I just tried it out for you... just use this.hide() and then this.showDialog(); to show it.. seems to work in C#, only problem i seem to have is showing the application again after hiding it just after the showDialog has been called ones...... just looked into this for a small amound of time but ok :S I do think i got a solution for you... so hangon :D update: Ok the following is rather primitive and i'm not sure if it works for you (in the way you wish to use it BUT) also this is in C# forgot all about vb.net BUT people can help you surely :D You have a main application on a certian point (let's say the timer has a tick event) and you wish to tell something to the person using the phone you could do the following Create a new form (containing all the information needed) Form2 test = new Form2() Show that form (which will be displayed no matter what using showdialog) test.showDialog() then after test is closed you "unload" the loaded form test = null; :D.. this should work nicely... hope i managed to help :P Edited January 7, 2005 by ultimasnake
Guest gaplayer26 Posted January 8, 2005 Report Posted January 8, 2005 To keep my program running in the background I have used the .Hide() method as can be seen below: alarm.Hide(); So here's my question, how do i get this form visible again!? The .Show() method seems to do nothing? Anyone got any ideas? I am aiming to unltimately stop my program being closed by the phone when it tries to reclaim memory so if you can suggest an alternative to .Hide() to achieve this then I am open to suggestions! Cheers in advance, Marc <{POST_SNAPBACK}> Hi, As far as I am aware, .Hide() will not prevent the OS from closing your application. To prevent the OS from doing this, use: Dim ApplicationClosing As Boolean = False '---Determine if user wants application closed (as opposed to the OS) Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs) '---Prevent OS from automatically closing our application If ApplicationClosing = True Then e.Cancel = False Else e.Cancel = True End If End Sub You will need to make a way for the user to actually close the application - (i.e. Menu > Exit): Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click '---Set flag indicating user is closing the application ApplicationClosing = True Me.Close() System.Windows.Forms.Application.Exit() End Sub The only way I've managed to 'unhide' a form/app is by using a separate 'loader' to send a windows message to the application (eg. WM_SHOW) I've used both the above on Smartphone... HTH and let us know if you get it working! :D
Guest Brody Posted January 8, 2005 Report Posted January 8, 2005 Thanks for the response, I should have posted in here that I had implemented an OnClosing method successfully already :D Thanks for the input though!
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now