Clif
asked on
Screen Size Issues
Using VB.Net 2010 (Pro)
I have an interesting issue that has cropped up.
In my application, when the app shuts down (in the main form's Form_Closing event), I save the position of the form. The next time the app starts, the setting are read and the form is (supposed to be) returned to it's last location.
However, occasionally, I will get a report that someone has started the app, but the form is not showing. The task bar button is visible, but it seemingly does nothing when it's clicked. After pulling on my hair for a few weeks, I finally looked at the settings XML file and saw that the top and left positions were being saved as -32000 for each. Once I deleted the Top and Left settings, the app worked again no prob.
So what might cause this?
A couple of points that may be significant...
1. This is intermittent.
2. The engineers who use my app all have dual-monitor set-ups
I have an interesting issue that has cropped up.
In my application, when the app shuts down (in the main form's Form_Closing event), I save the position of the form. The next time the app starts, the setting are read and the form is (supposed to be) returned to it's last location.
However, occasionally, I will get a report that someone has started the app, but the form is not showing. The task bar button is visible, but it seemingly does nothing when it's clicked. After pulling on my hair for a few weeks, I finally looked at the settings XML file and saw that the top and left positions were being saved as -32000 for each. Once I deleted the Top and Left settings, the app worked again no prob.
So what might cause this?
A couple of points that may be significant...
1. This is intermittent.
2. The engineers who use my app all have dual-monitor set-ups
ASKER
I am getting the app (form, actually) position with this code:
With frmMain
nTop = .Top
nLeft = .Left
End With
clsSettings.SetSetting("MainFormTop", nTop.ToString(), sXMLFilename)
clsSettings.SetSetting("MainFormLeft", nLeft.ToString(), sXMLFilename)
And I retrieve it this way:
nTop = Val(clsSettings.GetSetting("MainFormTop", sXMLFilename))
nLeft = Val(clsSettings.GetSetting("MainFormLeft", sXMLFilename))
With frmMain
.Left = nLeft
.Top = nTop
End With
Pretty straight forward, actually
Why "frmMain" and not "Me". Where is this code running from? It's possible that you are not referencing the correct instance of your form.
How does your app start? Using the default "Startup Object"?...or have you modded it to start from Sub Main()?
How does your app start? Using the default "Startup Object"?...or have you modded it to start from Sub Main()?
ASKER
The code is running from a module. The code is actually part of a subroutine where the form is passed in.
The app starts using the main form (whatever the default was, it's working fine). To tell you the truth, I can't find where I would set it up to start with Sub Main()
The app starts using the main form (whatever the default was, it's working fine). To tell you the truth, I can't find where I would set it up to start with Sub Main()
So "frmMain" is the name of the local variable in the Module?
Why not just run that code directly in the FormClosing() event?...and the Load() event when it opens.
Why not just run that code directly in the FormClosing() event?...and the Load() event when it opens.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Code Reuse.
I have a bunch of commonly called procedures in a module. That way, whenever I write a new app, I don't have to retype all the code (potentially forgetting something, or getting the wrong stuff in the wrong place).
The procedure that saves the Top/Left also has a lot more stuff from the app that it's saving (previous worked on documents, etc).
I have a bunch of commonly called procedures in a module. That way, whenever I write a new app, I don't have to retype all the code (potentially forgetting something, or getting the wrong stuff in the wrong place).
The procedure that saves the Top/Left also has a lot more stuff from the app that it's saving (previous worked on documents, etc).
ASKER
JamesBurger,
Thanks for the code snippet. My previous post was actually addressed to Idle_Mind.
Thanks for the code snippet. My previous post was actually addressed to Idle_Mind.
Hello, Clif,
Restoring the form position to it's previous location can also cause a problem when the user moves from a computer with a larger screen to one with a smaller screen, or possibly in the case of your users, to a system with only one screen.
I would recommend that, when restoring the position, you compare the position with the size (and number) of the user's current screen(s). Then if necessary, reset the form position to ensure it appears within the current screen. I guess this would also handle the current intermittent problem.
Cheers,
Randy
Restoring the form position to it's previous location can also cause a problem when the user moves from a computer with a larger screen to one with a smaller screen, or possibly in the case of your users, to a system with only one screen.
I would recommend that, when restoring the position, you compare the position with the size (and number) of the user's current screen(s). Then if necessary, reset the form position to ensure it appears within the current screen. I guess this would also handle the current intermittent problem.
Cheers,
Randy
@omegaomega and Clif
Omega is right, and that would be one more reason to use the settings system built into the framework. Since it records the settings at the user level on each computer, moving the project around would not be a problem, each environment would have its own set of settings.
Omega is right, and that would be one more reason to use the settings system built into the framework. Since it records the settings at the user level on each computer, moving the project around would not be a problem, each environment would have its own set of settings.
ASKER
The app, and as such the settings, are limited to one computer. That is, no one copies the settings file to another computer.
As far as dropping a screen, I suppose it is possible, since some of the engineers are running laptops with a second monitor, but the one I did notice the bad settings on was a desktop model.
As far as dropping a screen, I suppose it is possible, since some of the engineers are running laptops with a second monitor, but the one I did notice the bad settings on was a desktop model.
ASKER
Thanks
Are you getting the virtual screen size and then position for example?