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
 
LVL 10
ClifAsked:
Who is Participating?
 
Jacques Bourgeois (James Burger)PresidentCommented:
It is usually possible to get negative values for those settings when the form is moved so that that is upper left corner is outside of the screen. But a value of 32000 is to huge for that, unless you have a form that is 32000 pixels wide. Very nice screens you would have :-)

It could be easily be done through code however.

Could be some artefact of the dual monitor driver for you graphic card.

Is the value always 32000? If so, I would look in the code or something wrong with the driver.

If you do not find the source of the problem, simply check for the condition when retrieving the values and adjust accordingly:
nTop = Val(clsSettings.GetSetting("MainFormTop", sXMLFilename))
nLeft = Val(clsSettings.GetSetting("MainFormLeft", sXMLFilename))

if nTop < 0 then nTop=0
if nLeft < 0 then nLeft=0

With frmMain
    .Left = nLeft
    .Top = nTop
End With

Open in new window

And it probably does not have anything to do with your questions, but why don't you use the standard settings mechanism built into Visual Studio instead of using your own. It would save the position as a Point object, not Strings that you need to convert back and forth between Integer ans String.

If multiple users are working on the same computer, it would also automatically save a unique settings for each individual user.
0
 
athomsfereCommented:
Can you post the code you are using to get the apps positions? And also to restore?

Are you getting the virtual screen size and then position for example?
0
 
ClifAuthor Commented:
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)

Open in new window

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

Open in new window

Pretty straight forward, actually
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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()?
0
 
ClifAuthor Commented:
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()
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
0
 
ClifAuthor Commented:
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).
0
 
ClifAuthor Commented:
JamesBurger,
Thanks for the code snippet.  My previous post was actually addressed to Idle_Mind.
0
 
omegaomegaDeveloperCommented:
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
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
@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.
0
 
ClifAuthor Commented:
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.
0
 
ClifAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.