Windows Develop Bookmark and Share   
 index > Windows Forms General > launching mainform to fit the width/height of primary monitor.
 

launching mainform to fit the width/height of primary monitor.

I morphed a vb6 app into .NET.

That app used to initialize the size of the form into values that made sense in twips, but not now.

Those same values (like 10,000 instead of maybe 1,000) make the app fill up all the available space on a 2 monitor display.

I would like to interogate some system setting and ask, "What is the width and height of the primary display? Something whose value would change based on whether the display dimenions were 1600 x 1200 or ?x?

Then I can change what used to be hardcoded values belowinto something that makes sense; Thanks! Greg

Call GetPrivateProfileString("App", "Width", "1000", s_ReturnValue, 255, INI_Filename)

Me.Width = CInt(s_ReturnValue.ToString)

Call GetPrivateProfileString("App", "Height", "800", s_ReturnValue, 255, INI_Filename)

Me.Height = CInt(s_ReturnValue.ToString)

Call GetPrivateProfileString("App", "WindowState", CStr(vbNormal), s_ReturnValue, 255, INI_Filename)

Select Case CInt(s_ReturnValue.ToString)

Case 0

Me.WindowState = System.Windows.Forms.FormWindowState.Normal

Case 1

Me.WindowState = System.Windows.Forms.FormWindowState.Minimized

Case 2

Me.WindowState = System.Windows.Forms.FormWindowState.Maximized

End Select


hazz  Wednesday, October 03, 2007 7:14 PM
in C#, it's

System.Windows.Forms.Screen.AllScreens[0].Bounds;

H. _冬_ Tony  Wednesday, October 03, 2007 8:13 PM
in C#, it's

System.Windows.Forms.Screen.AllScreens[0].Bounds;

H. _冬_ Tony  Wednesday, October 03, 2007 8:13 PM

Thank you!

System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width

System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, etc.

Dim Index As Integer

Dim UpperBound As Integer

' Gets an array of all the screens connected to the system.

Dim Screens() As System.Windows.Forms.Screen = _

System.Windows.Forms.Screen.AllScreens

UpperBound = Screens.GetUpperBound(0)

For Index = 0 To UpperBound

' For each screen, add the screen properties to a list box.

Debug.Print("Device Name: " + Screens(Index).DeviceName)

Debug.Print("Bounds: " + Screens(Index).Bounds.ToString())

Debug.Print("Type: " + Screens(Index).GetType().ToString())

Debug.Print("Working Area: " + Screens(Index).WorkingArea.ToString())

Debug.Print("Primary Screen: " + Screens(Index).Primary.ToString())

Next

Device Name: \\.\DISPLAY1Bounds: {X=0,Y=0,Width=1600,Height=1200}

Type: System.Windows.Forms.Screen

Working Area: {X=0,Y=0,Width=1600,Height=1200}

Primary Screen: True

Device Name: \\.\DISPLAY2Bounds: {X=1600,Y=0,Width=1280,Height=1024}

Type: System.Windows.Forms.Screen

Working Area: {X=1600,Y=0,Width=1280,Height=1024}

Primary Screen: False

hazz  Wednesday, October 03, 2007 8:50 PM

You can use google to search for other answers

Custom Search

More Threads

• COM Interop - Problem while passing OBJECT type
• get info from a switch statement
• bypass mouse scroll
• DDEML in Visual Basic 6
• WebBrowser Steals Focus
• closing/disposing of a dialog
• NumericUpDown Hex Display Formatting?
• DatagridView mysteriously makes existing display values blank when new row is added
• CheckedListBox: Reading/Setting Item Checked State Programmatically
• Make custom panel class appear in VisualStudio