473,500 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7912
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
1302
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
322
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
1250
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
2236
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
5673
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
1647
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
22075
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
11347
by: iwdu15 | last post by:
hi, is there anyway i can make my windows form to be full screen? thanks
10
4460
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
7156
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7248
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7409
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5511
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4941
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3117
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3115
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1446
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.