rgn2121
asked on
Windows API, VB.Net help...catching Maximize
I am trying to catch when a user maximizes a form, set the coordinates to what I want them to be and then continue on. I just want to be able to set the size of the window myself instead of the system controlling it.
I have the code below to catch the maximize, but I am not sure what to do from this point and have never done any api coding.
Thanks,
rgn
I have the code below to catch the maximize, but I am not sure what to do from this point and have never done any api coding.
Thanks,
rgn
Set the MaximizedBounds() Property on your Form:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.maximizedbounds.aspx
Simple example:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.maximizedbounds.aspx
Simple example:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim wa As Rectangle = Screen.GetWorkingArea(Me)
Me.MaximizedBounds = New Rectangle(wa.Location, New Size(wa.Width / 2, wa.Height)) ' left 1/2 of the working area
End Sub
End Class
ASKER
Thanks for the code, but I can't use this because the apps are running through Citrix. I posted a question similar to this a while back and you gave me a link that led me to the code I have above, but I don't know what to do from there.
Citrix is treating dual screens like one large monitor, so I want to catch the call to maximize the window, determine the window dimensions myself and then carry on...
Citrix is treating dual screens like one large monitor, so I want to catch the call to maximize the window, determine the window dimensions myself and then carry on...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will give this a shot and test...Citrix may limit me here so we will see...I will try it local and Citrix and let you know.
Thanks
Thanks
ASKER
Running the code above locally on dual screens both set at 1280 x 1024, the form displays somwhere off the right of the right monitor...
The ptMaxTrackSize when I debug is above 2500 for the X coord.
The ptMaxTrackSize when I debug is above 2500 for the X coord.
ASKER
Maybe you meant for the code above to only be used if it was in the citrix situation...I will try that.
ASKER
I will work through what you gave and post back when I can...I have some previous code to move around so that the local stuff is not messed up...Thanks again.
ASKER
Okay...this is where I'm at.... It might be that I have no control over the form where citrix is concerned. At least as far as the maximizing is concerned. When running in Citrix, it still covers both screens...
Imports System.Runtime.InteropServices
Public Class Form1
Private Const WM_GETMINMAXINFO As Integer = &H24
Private _firstLoad As Boolean = True
Private _isCitrix As Boolean = False
Private _isMultiMonitor As Boolean = False
Private Structure POINTAPI
Public x As Integer
Public y As Integer
End Structure
Private Structure MINMAXINFO
Public ptReserved As POINTAPI
Public ptMaxSize As POINTAPI
Public ptMaxPosition As POINTAPI
Public ptMinTrackSize As POINTAPI
Public ptMaxTrackSize As POINTAPI
End Structure
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If _firstLoad Then
'Check for a Citrix Session
If Environment.GetEnvironmentVariable("SESSIONNAME") <> "Console" AndAlso _
String.IsNullOrEmpty(Environment.GetEnvironmentVariable("CLIENTNAME")) Then
_isCitrix = True
End If
'Check screen configuration
Dim s As Screen
For Each s In Screen.AllScreens
If _isCitrix Then
If Screen.AllScreens.Length = 1 Then
'Assume anything greater than 1600 width in Citrix is 2 screens
If Screen.PrimaryScreen.Bounds.Width >= 1600 Then
_isMultiMonitor = True
End If
ElseIf Screen.AllScreens.Length > 1 Then
MsgBox("Citrix is seeing 2 screens!!")
End If
ElseIf Screen.AllScreens.Length > 1 Then
_isMultiMonitor = True
End If 'END _isCitrix
Next
End If 'END _firstLoad
'Execute only if it is on dual screens and in citrix
If _isCitrix AndAlso _isMultiMonitor Then
Select Case m.Msg
Case WM_GETMINMAXINFO
Dim wa As Rectangle = Screen.GetWorkingArea(Me)
Dim mmi As MINMAXINFO = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(MINMAXINFO)), MINMAXINFO)
' set the size/location of "mmi":
mmi.ptMaxPosition.x = wa.Location.X
mmi.ptMaxPosition.y = wa.Location.Y
mmi.ptMaxSize.x = CInt(wa.Size.Width / 2)
mmi.ptMaxSize.y = wa.Size.Height
Marshal.StructureToPtr(mmi, m.LParam, True)
End Select
End If
_firstLoad = False
End Sub
Private Sub SetLocalMultiScreenDimensions(ByVal scrn As Screen)
_firstLoad = False
If Me.Bounds.Width < scrn.Bounds.Width AndAlso _
Me.Bounds.Height < scrn.Bounds.Height Then
'Find the center of the designed form...
Dim myX As Integer = CInt(Me.Bounds.Width / 2)
Dim myY As Integer = CInt(Me.Bounds.Height / 2)
'Find the location that will center the designed form...
Dim pntX As Integer = CInt((scrn.Bounds.Location.X + (scrn.Bounds.Location.X / 2))) - myX
Dim pnt As New System.Drawing.Point(pntX, CInt(scrn.Bounds.Height / 2) - myY)
Me.Location = pnt
Else
Me.Bounds = scrn.Bounds
Me.WindowState = FormWindowState.Normal
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not _isCitrix Then
If Not _isMultiMonitor Then
'Just let the form load
Else
Dim s As Screen
For Each s In Screen.AllScreens
If Not s.Primary Then
SetLocalMultiScreenDimensions(s)
Exit For
End If 'END Not s.Primary
Next
End If
End If
End Sub
End Class
ASKER
Any updates or thoughts...??
I don't have any experience with Citrix so I'm not sure where to go next...sorry. =\
ASKER
But you don't see any issues with the code correct...? As long as someone more experienced than me feels comfortable with the code, I can at least feel more confident in the fact that the server guys would have to make a change if they do anything at all.
Thanks,
Thanks,
It looks ok to me...
ASKER
This could not solve my problem because of Citrix. The code provided did allow me to learn some API code and control window events locally.
Thanks...
Thanks...
ASKER
Open in new window