Hi Greg,
Regarding this code snippet, I have helped you to translate it. Yes, it
seems the converter tool will use the old style VB6 syntax to for the
p/invoke APIs. Anyway, I have converted it with the new VB.net syntaxt:
Imports System.Runtime.InteropServices
Public Class Form1
Class WinApi
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function GetSystemMetrics(ByVal nIndex As Integer) As
Integer
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal
hWndInsertAfter As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cx
As Integer, ByVal cy As Integer, ByVal flags As Integer) As Boolean
End Function
Private Shared SM_CXSCREEN As Integer = 0
Private Shared SM_CYSCREEN As Integer = 1
Private Shared HWND_TOP As IntPtr = IntPtr.Zero
Private Shared SWP_SHOWWINDOW As Integer = 64 '
Public Shared ReadOnly Property ScreenX() As Integer
Get
Return GetSystemMetrics(SM_CXSCREEN)
End Get
End Property
Public Shared ReadOnly Property ScreenY() As Integer
Get
Return GetSystemMetrics(SM_CYSCREEN)
End Get
End Property
Public Shared Sub SetWinFullScreen(ByVal hwnd As IntPtr)
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY,
SWP_SHOWWINDOW)
End Sub 'SetWinFullScreen
End Class 'WinApi
Private frmState As New FormState()
Public Class FormState
Private winState As FormWindowState
Private brdStyle As FormBorderStyle
Private topMost As Boolean
Private bounds As Rectangle
Private IsMaximized As Boolean = False
Public Sub Maximize(ByVal targetForm As Form)
If Not IsMaximized Then
IsMaximized = True
Save(targetForm)
targetForm.WindowState = FormWindowState.Maximized
targetForm.FormBorderStyle = FormBorderStyle.None
targetForm.TopMost = True
WinApi.SetWinFullScreen(targetForm.Handle)
End If
End Sub 'Maximize
Public Sub Save(ByVal targetForm As Form)
winState = targetForm.WindowState
brdStyle = targetForm.FormBorderStyle
topMost = targetForm.TopMost
bounds = targetForm.Bounds
End Sub 'Save
Public Sub Restore(ByVal targetForm As Form)
targetForm.WindowState = winState
targetForm.FormBorderStyle = brdStyle
targetForm.TopMost = topMost
targetForm.Bounds = bounds
IsMaximized = False
End Sub 'Restore
End Class 'FormState
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
frmState.Maximize(Me)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
frmState.Restore(Me)
End Sub
End Class
Finally, for such VB.net syntax issue, I would recommend you to post in
microsoft.public.dotnet.languages.vb because there will be more VB.net
developers there.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.