?
Solved

Screen Size Issues

Posted on 2011-10-05
12
Medium Priority
?
237 Views
Last Modified: 2012-05-12
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
 
0
Comment
Question by:Clif
  • 6
  • 2
  • 2
  • +2
12 Comments
 
LVL 14

Expert Comment

by:athomsfere
ID: 36916935
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
 
LVL 10

Author Comment

by:Clif
ID: 36917254
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36917542
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:Clif
ID: 36917681
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36917710
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 36917774
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
 
LVL 10

Author Comment

by:Clif
ID: 36917801
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
 
LVL 10

Author Comment

by:Clif
ID: 36917834
JamesBurger,
Thanks for the code snippet.  My previous post was actually addressed to Idle_Mind.
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 36918120
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
 
LVL 40
ID: 36918165
@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
 
LVL 10

Author Comment

by:Clif
ID: 36918264
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
 
LVL 10

Author Closing Comment

by:Clif
ID: 36925428
Thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question