472,954 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

WORKAROUND: Screen.PrimaryScreen.WorkingArea

Situation 1 (erroneous):
TaskBar changes
Screen.PrimaryScreen.WorkingArea still returns the old rectangle

Situation 2 (OK)
TaskBar changes
Form Quits and Reloads
Screen.PrimaryScreen.WorkingArea returns the new rectangle

How to correct the 1st situation?

Nov 20 '05 #1
11 7835
Arcer,
What do you mean by "Form Quits & Reloads"?

I only see the WorkingArea change when the application itself quits &
reexecute it, that is when I am only changing the size of the TaskBar.

Or put another way: The WorkingArea is only updated for the DisplayChanged
event & app start. I would expect the WorkingArea to change if the size of
the TaskBar changes. Also I'm getting in consist changes on
DisplayChanged...

I'm not seeing anything in the KB about this, if you clarify what you are
seeing I will report it to MS.

Hope this helps
Jay

"Arcer P" <No@Spam.Com> wrote in message
news:OG****************@TK2MSFTNGP12.phx.gbl...
Situation 1 (erroneous):
TaskBar changes
Screen.PrimaryScreen.WorkingArea still returns the old rectangle

Situation 2 (OK)
TaskBar changes
Form Quits and Reloads
Screen.PrimaryScreen.WorkingArea returns the new rectangle

How to correct the 1st situation?

Nov 20 '05 #2
Hi Arcer

It seems that you are right and it appears that the .NET Framework is caching the working screen size at application startup so if you change the working area after your application has been loaded (i.e. by increasing the size of the taskbar or adding the office shortcut bar etc.), Screen.PrimaryScreen.WorkingArea still returns the original cached size. I would suggest that this behaviour is probably a bug in the framework

A workaround would be to p/invoke the 'SystemParametersInfo' Win32 API which will get you the working area in realtime..

\
Private Const SPI_GETWORKAREA As Integer = 4

Private Structure REC
Public Left As Intege
Public Top As Intege
Public Right As Intege
Public Bottom As Intege
End Structur

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA"
(ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As RECT, ByVal fuWinIni As Integer) As Intege
//

\
Dim rectDesktop As REC

If (SystemParametersInfo(SPI_GETWORKAREA, 0, rectDesktop, 0) <> 0) The
Console.WriteLine("Desktop Working Width = " & CType(rectDesktop.Right - rectDesktop.Left, String)
Console.WriteLine("Desktop Working Height = " & CType(rectDesktop.Bottom - rectDesktop.Top, String)
End I
//

HTH
Gary
Nov 20 '05 #3
Jay B. Harlow [MVP - Outlook] wrote:
Arcer,
What do you mean by "Form Quits & Reloads"?

Step by step

1. Create a new solution with a single form

2. Write the Click event as follows:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click

Me.Text = Screen.PrimaryScreen.WorkingArea.ToString

End Sub
3. On the menu Debug click Start

4. Click the form that shows in the screen
and write down the form text (formely named caption)

5. Change the size and/or position of the task bar

6. Click the form again
notice that the form text did not change

7. Close the program

8. Start the program again

9. Click the form again
notice that the caption reflects the new screen working area


Is it clear now?


Nov 20 '05 #4
Actually, don't use the p/invoke method. I just discovered that 'System.Windows.Forms.SystemInformation.WorkingAre a' works dynamically in the same way as the p/invoke method so use this instead

Gar
Nov 20 '05 #5
Thank you very much for your sample code :)
I was not expecting to give so much trouble
Gary Milton wrote:
Hi Arcer,

It seems that you are right and it appears that the .NET Framework is caching the working screen size at application startup so if you change the working area after your application has been loaded (i.e. by increasing the size of the taskbar or adding the office shortcut bar etc.), Screen.PrimaryScreen.WorkingArea still returns the original cached size. I would suggest that this behaviour is probably a bug in the framework.

A workaround would be to p/invoke the 'SystemParametersInfo' Win32 API which will get you the working area in realtime...

\\
Private Const SPI_GETWORKAREA As Integer = 48

Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As RECT, ByVal fuWinIni As Integer) As Integer
///
\\
Dim rectDesktop As RECT

If (SystemParametersInfo(SPI_GETWORKAREA, 0, rectDesktop, 0) <> 0) Then
Console.WriteLine("Desktop Working Width = " & CType(rectDesktop.Right - rectDesktop.Left, String))
Console.WriteLine("Desktop Working Height = " & CType(rectDesktop.Bottom - rectDesktop.Top, String))
End If
///

HTH,
Gary


Nov 20 '05 #6
Gary,
Thanks for the work around!

I'm curious how well it works in a multi-monitor environment, as the
System.Windows.Forms.Screen object represents each monitor attached to your
computer.

Either way I will report something to MS as
System.Windows.Forms.Screen.PrimaryScreen.WorkingA rea is not working
correctly.

Thanks
Jay

"Gary Milton" <an*******@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Actually, don't use the p/invoke method. I just discovered that 'System.Windows.Forms.SystemInformation.WorkingAre a' works dynamically in
the same way as the p/invoke method so use this instead.
Gary

Nov 20 '05 #7
Thanks again
I was about writting the same as you did
It seems to be a very strange behaviour

Do you know if VC++ has this behaviour too?
Gary Milton wrote:
Actually, don't use the p/invoke method. I just discovered that 'System.Windows.Forms.SystemInformation.WorkingAre a' works dynamically in the same way as the p/invoke method so use this instead.

Gary


Nov 20 '05 #8
Arcer,
7. Close the program
8. Start the program again Thanks that is the part I needed, Gary gave a good work around.

I will report something to Microsoft.

Hope this helps
Jay

"Arcer P" <No@Spam.Com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Jay B. Harlow [MVP - Outlook] wrote:
Arcer,
What do you mean by "Form Quits & Reloads"?

Step by step

1. Create a new solution with a single form

2. Write the Click event as follows:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click

Me.Text = Screen.PrimaryScreen.WorkingArea.ToString

End Sub
3. On the menu Debug click Start

4. Click the form that shows in the screen
and write down the form text (formely named caption)

5. Change the size and/or position of the task bar

6. Click the form again
notice that the form text did not change

7. Close the program

8. Start the program again

9. Click the form again
notice that the caption reflects the new screen working area


Is it clear now?


Nov 20 '05 #9
Thanks
I was in a hurry and made an erroneous test
It works fine as well as your new approach
You are really kind

Gary Milton wrote:
Actually, don't use the p/invoke method. I just discovered that 'System.Windows.Forms.SystemInformation.WorkingAre a' works dynamically in the same way as the p/invoke method so use this instead.

Gary


Nov 20 '05 #10
How do you report to MicroSoft?
Jay B. Harlow [MVP - Outlook] wrote:
Arcer,
7. Close the program
8. Start the program again


Thanks that is the part I needed, Gary gave a good work around.

I will report something to Microsoft.

Hope this helps
Jay

"Arcer P" <No@Spam.Com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Jay B. Harlow [MVP - Outlook] wrote:
Arcer,
What do you mean by "Form Quits & Reloads"?


Step by step

1. Create a new solution with a single form

2. Write the Click event as follows:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click

Me.Text = Screen.PrimaryScreen.WorkingArea.ToString

End Sub
3. On the menu Debug click Start

4. Click the form that shows in the screen
and write down the form text (formely named caption)

5. Change the size and/or position of the task bar

6. Click the form again
notice that the form text did not change

7. Close the program

8. Start the program again

9. Click the form again
notice that the caption reflects the new screen working area


Is it clear now?




Nov 20 '05 #11
Arcer,
MVPs, such as myself, have a channel available to us to report bugs.

For details on being or becoming an MVP see:
http://mvp.support.microsoft.com/

Hope this helps
Jay

"Arcer P" <No@Spam.Com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
How do you report to MicroSoft?
Jay B. Harlow [MVP - Outlook] wrote:
Arcer,
7. Close the program
8. Start the program again


Thanks that is the part I needed, Gary gave a good work around.

I will report something to Microsoft.

Hope this helps
Jay

"Arcer P" <No@Spam.Com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Jay B. Harlow [MVP - Outlook] wrote:

Arcer,
What do you mean by "Form Quits & Reloads"?
Step by step

1. Create a new solution with a single form

2. Write the Click event as follows:

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click

Me.Text = Screen.PrimaryScreen.WorkingArea.ToString

End Sub
3. On the menu Debug click Start

4. Click the form that shows in the screen
and write down the form text (formely named caption)

5. Change the size and/or position of the task bar

6. Click the form again
notice that the form text did not change

7. Close the program

8. Start the program again

9. Click the form again
notice that the caption reflects the new screen working area


Is it clear now?



Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Me | last post by:
I am about to roll out a vb.net 2003 app for screens using 1024x768. However some users will only have 800x600. Is there a quick method of scaling down the screens already written (e.g....
0
by: Arcer P | last post by:
Situation 1 (erroneous): TaskBar changes Screen.PrimaryScreen.WorkingArea still returns the old rectangle Situation 2 (OK) TaskBar changes Form Quits and Reloads...
2
by: Chen | last post by:
I want to know the screen resolution before launch my VB .NET windows form so the form can fit the screen nicely. Is that possible? Thanks.
3
by: Dino Buljubasic | last post by:
How can I get programmatically screen width of my screen when I start my application? Thank you, Dino
3
by: Bala | last post by:
Hi, My current vb code having screen keyword. can anyone tell me what is the equalent in vb.net? frm.Top = (Screen.Height - frm.Height) / 2 frm.Left = (Screen.Width - frm.Width) / 2 thanks...
7
by: FabriceG | last post by:
I'm french, and I would like find the screen width and height without using the screen object. Can you Help me ?
4
by: Bill Nguyen | last post by:
My VB.Net app requires a minimum monitor resolution of 1024 x 768. How to get user's screen resolution and set it to the minimum at runtime? Thanks Bill
15
by: iwdu15 | last post by:
hi, is there anyway i can make my windows form to be full screen? thanks
10
by: ManwSloHand | last post by:
ARGH! I have a c#.net web application. I need to retrieve screen height and width into a variable. I know this is incredibly stupid but HOW THE HECK DO I DO IT??!?!?! A copy to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.