Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Option Infer On
' See the LICENSE file in the project root for more information.

Imports System.Security
Imports System.Windows.Forms

Namespace Microsoft.VisualBasic.ApplicationServices

Expand All @@ -18,7 +19,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' last form closes, depending on the mode this application is running in.
''' </summary>
Private Class WinFormsAppContext
Inherits Windows.Forms.ApplicationContext
Inherits ApplicationContext

Private ReadOnly _app As WindowsFormsApplicationBase

Expand All @@ -38,7 +39,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
If _app.ShutdownStyle = ShutdownMode.AfterMainFormCloses Then
MyBase.OnMainFormClosed(sender, e)
Else 'identify a new main form so we can keep running
Dim forms As Windows.Forms.FormCollection = Windows.Forms.Application.OpenForms
Dim forms As FormCollection = Application.OpenForms

If forms.Count > 0 Then
'Note: Initially I used Process::MainWindowHandle to obtain an open form. But that is bad for two reasons:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Threading
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.CompilerServices
Imports Microsoft.VisualBasic.CompilerServices.Utils

Expand Down Expand Up @@ -129,7 +130,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
' has expired and it is OK to close the splash screen.
Private _splashScreenCompletionSource As TaskCompletionSource(Of Boolean)
Private _formLoadWaiter As AutoResetEvent
Private _splashScreen As Windows.Forms.Form
Private _splashScreen As Form

' Minimum amount of time to show the splash screen. 0 means hide as soon as the app comes up.
Private _minimumSplashExposure As Integer = MINIMUM_SPLASH_EXPOSURE_DEFAULT
Expand All @@ -140,7 +141,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
Private _saveMySettingsOnExit As Boolean

' The HighDpiMode the user picked from the AppDesigner or assigned to the ApplyHighDpiMode's Event.
Private _highDpiMode As Windows.Forms.HighDpiMode = Windows.Forms.HighDpiMode.SystemAware
Private _highDpiMode As HighDpiMode = HighDpiMode.SystemAware

#Enable Warning IDE0032 ' Use auto property

Expand Down Expand Up @@ -233,7 +234,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices

' Only add the listener once so we don't fire the UnHandledException event over and over for the same exception
If _unhandledExceptionHandlers.Count = 1 Then
AddHandler Windows.Forms.Application.ThreadException, AddressOf OnUnhandledExceptionEventAdaptor
AddHandler Application.ThreadException, AddressOf OnUnhandledExceptionEventAdaptor
End If
End AddHandler

Expand All @@ -244,7 +245,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices

' Last one to leave, turn out the lights...
If _unhandledExceptionHandlers.Count = 0 Then
RemoveHandler Windows.Forms.Application.ThreadException, AddressOf OnUnhandledExceptionEventAdaptor
RemoveHandler Application.ThreadException, AddressOf OnUnhandledExceptionEventAdaptor
End If
End If
End RemoveHandler
Expand Down Expand Up @@ -367,20 +368,20 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' affinity meaning that this is the WinForms collection that contains Forms that may
''' have been opened on another thread then the one we are calling in on right now.
''' </summary>
Public ReadOnly Property OpenForms() As Windows.Forms.FormCollection
Public ReadOnly Property OpenForms() As FormCollection
Get
Return Windows.Forms.Application.OpenForms
Return Application.OpenForms
End Get
End Property

''' <summary>
''' Provides access to the main form for this application
''' </summary>
Protected Property MainForm() As Windows.Forms.Form
Protected Property MainForm() As Form
Get
Return _appContext?.MainForm
End Get
Set(value As Windows.Forms.Form)
Set(value As Form)
If value Is Nothing Then
Throw ExceptionUtils.GetArgumentNullException("MainForm", SR.General_PropertyNothing, "MainForm")
End If
Expand All @@ -394,11 +395,11 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' <summary>
''' Provides access to the splash screen for this application
''' </summary>
Public Property SplashScreen() As Windows.Forms.Form
Public Property SplashScreen() As Form
Get
Return _splashScreen
End Get
Set(value As Windows.Forms.Form)
Set(value As Form)

' Allow for the case where they set splash screen = nothing and mainForm is currently nothing.
If value IsNot Nothing AndAlso value Is _appContext.MainForm Then
Expand Down Expand Up @@ -450,7 +451,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' Provides the WinForms application context that we are running on
''' </summary>
<EditorBrowsable(EditorBrowsableState.Advanced)>
Public ReadOnly Property ApplicationContext() As Windows.Forms.ApplicationContext
Public ReadOnly Property ApplicationContext() As ApplicationContext
Get
Return _appContext
End Get
Expand All @@ -472,7 +473,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' Processes all windows messages currently in the message queue
''' </summary>
Public Sub DoEvents()
Windows.Forms.Application.DoEvents()
Application.DoEvents()
End Sub

''' <summary>
Expand Down Expand Up @@ -510,27 +511,27 @@ Namespace Microsoft.VisualBasic.ApplicationServices
RaiseEvent ApplyApplicationDefaults(Me, applicationDefaultsEventArgs)

If (applicationDefaultsEventArgs.Font IsNot Nothing) Then
Windows.Forms.Application.SetDefaultFont(applicationDefaultsEventArgs.Font)
Application.SetDefaultFont(applicationDefaultsEventArgs.Font)
End If

MinimumSplashScreenDisplayTime = applicationDefaultsEventArgs.MinimumSplashScreenDisplayTime

' This creates the native window, and that means, we can no longer apply a different Default Font.
' So, this is the earliest point in time to set the AsyncOperationManager's SyncContext.
AsyncOperationManager.SynchronizationContext = New Windows.Forms.WindowsFormsSynchronizationContext()
AsyncOperationManager.SynchronizationContext = New WindowsFormsSynchronizationContext()

_highDpiMode = applicationDefaultsEventArgs.HighDpiMode

' Then, it's applying what we got back as HighDpiMode.
Dim dpiSetResult = Windows.Forms.Application.SetHighDpiMode(_highDpiMode)
Dim dpiSetResult = Application.SetHighDpiMode(_highDpiMode)
If dpiSetResult Then
_highDpiMode = Windows.Forms.Application.HighDpiMode
_highDpiMode = Application.HighDpiMode
End If
Debug.Assert(dpiSetResult, "We could net set the HighDpiMode.")

' And finally we take care of EnableVisualStyles.
If _enableVisualStyles Then
Windows.Forms.Application.EnableVisualStyles()
Application.EnableVisualStyles()
End If

' We'll handle "/nosplash" for you.
Expand Down Expand Up @@ -590,8 +591,8 @@ Namespace Microsoft.VisualBasic.ApplicationServices

' Activate the original instance.
If eventArgs.BringToForeground = True AndAlso MainForm IsNot Nothing Then
If MainForm.WindowState = Windows.Forms.FormWindowState.Minimized Then
MainForm.WindowState = Windows.Forms.FormWindowState.Normal
If MainForm.WindowState = FormWindowState.Minimized Then
MainForm.WindowState = FormWindowState.Normal
End If

MainForm.Activate()
Expand Down Expand Up @@ -627,7 +628,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
' (see Public Custom Event UnhandledException) which will raise our UnhandledException Event.
' If our user didn't write an UnhandledException event, then we land in the try/catch handler for Forms.Application.Run().
Try
Windows.Forms.Application.Run(_appContext)
Application.Run(_appContext)
Finally

' When Run() returns, the context we pushed in our ctor (which was a WindowsFormsSynchronizationContext)
Expand Down Expand Up @@ -680,7 +681,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
' We don't put a try/catch around the handler event so that exceptions in there will
' bubble out - else we will have a recursive exception handler.
RaiseEvent UnhandledException(Me, e)
If e.ExitApplication = True Then Windows.Forms.Application.Exit()
If e.ExitApplication = True Then Application.Exit()

' User handled the event.
Return True
Expand Down Expand Up @@ -787,11 +788,11 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' Gets or sets the HighDpiMode for the Application.
''' </summary>
<EditorBrowsable(EditorBrowsableState.Never)>
Protected Property HighDpiMode() As Windows.Forms.HighDpiMode
Protected Property HighDpiMode() As HighDpiMode
Get
Return _highDpiMode
End Get
Set(value As Windows.Forms.HighDpiMode)
Set(value As HighDpiMode)
_highDpiMode = value
End Set
End Property
Expand Down Expand Up @@ -841,7 +842,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
_splashTimer.Enabled = True
End If

Windows.Forms.Application.Run(_splashScreen)
Application.Run(_splashScreen)
End Sub

''' <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Option Strict On
Option Explicit On

Imports Microsoft.VisualBasic.MyServices
Imports System.Windows.Forms

Namespace Microsoft.VisualBasic.Devices

Expand Down Expand Up @@ -82,12 +83,12 @@ Namespace Microsoft.VisualBasic.Devices
''' This property returns the primary display screen.
''' </summary>
''' <value>A System.Windows.Forms.Screen object as the primary screen.</value>
Public ReadOnly Property Screen() As System.Windows.Forms.Screen
Public ReadOnly Property Screen() As Screen
Get
'Don't cache this. The Screen class responds to display resolution changes by nulling out AllScreens, which
'PrimaryScreen relies on to find the primary. So we always need to access the latest PrimaryScreen so we
'will get the current resolution reported.
Return Windows.Forms.Screen.PrimaryScreen
Return Screen.PrimaryScreen
End Get
End Property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Namespace Microsoft.VisualBasic.Devices
''' <param name="wait">Wait for messages to be processed before returning.</param>
Public Sub SendKeys(keys As String, wait As Boolean)
If wait Then
Windows.Forms.SendKeys.SendWait(keys)
System.Windows.Forms.SendKeys.SendWait(keys)
Else
Windows.Forms.SendKeys.Send(keys)
System.Windows.Forms.SendKeys.Send(keys)
End If
End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Imports System.Windows.Forms
Namespace Microsoft.VisualBasic.CompilerServices

Friend NotInheritable Class VBInputBox
Inherits Windows.Forms.Form
Inherits Form

#Disable Warning IDE1006 ' Naming Styles, Justification:=<VBInputBox.resx depends on these names>
Private ReadOnly components As Container
Private TextBox As Windows.Forms.TextBox
Private Label As Windows.Forms.Label
Private OKButton As Windows.Forms.Button
Private MyCancelButton As Windows.Forms.Button
Private TextBox As TextBox
Private Label As Label
Private OKButton As Button
Private MyCancelButton As Button
#Enable Warning IDE1006 ' Naming Styles
Public Output As String = ""

Expand All @@ -44,10 +44,10 @@ Namespace Microsoft.VisualBasic.CompilerServices

Private Sub InitializeComponent()
Dim resources As ComponentResourceManager = New ComponentResourceManager(GetType(VBInputBox))
OKButton = New Windows.Forms.Button
MyCancelButton = New Windows.Forms.Button
TextBox = New Windows.Forms.TextBox
Label = New Windows.Forms.Label
OKButton = New Button
MyCancelButton = New Button
TextBox = New TextBox
Label = New Label
SuspendLayout()
'
'OKButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Text
Imports System.Threading
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.CompilerServices
Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Imports Microsoft.VisualBasic.CompilerServices.Utils
Expand Down Expand Up @@ -244,10 +245,10 @@ Namespace Microsoft.VisualBasic
Private ReadOnly _xPos As Integer
Private ReadOnly _yPos As Integer
Private _result As String
Private ReadOnly _parentWindow As Windows.Forms.IWin32Window
Private ReadOnly _parentWindow As IWin32Window
Private _exception As Exception

Sub New(Prompt As String, Title As String, DefaultResponse As String, XPos As Integer, YPos As Integer, ParentWindow As Windows.Forms.IWin32Window)
Sub New(Prompt As String, Title As String, DefaultResponse As String, XPos As Integer, YPos As Integer, ParentWindow As IWin32Window)
_prompt = Prompt
_title = Title
_defaultResponse = DefaultResponse
Expand Down Expand Up @@ -279,7 +280,7 @@ Namespace Microsoft.VisualBasic

Public Function InputBox(Prompt As String, Title As String, DefaultResponse As String, XPos As Integer, YPos As Integer) As String
Dim vbhost As IVbHost
Dim ParentWindow As Windows.Forms.IWin32Window = Nothing
Dim ParentWindow As IWin32Window = Nothing

vbhost = CompilerServices.HostServices.VBHost
If vbhost IsNot Nothing Then 'If we are hosted then we want to use the host as the parent window. If no parent window that's fine.
Expand Down Expand Up @@ -341,7 +342,7 @@ Namespace Microsoft.VisualBasic

End Function

Private Function InternalInputBox(Prompt As String, Title As String, DefaultResponse As String, XPos As Integer, YPos As Integer, ParentWindow As Windows.Forms.IWin32Window) As String
Private Function InternalInputBox(Prompt As String, Title As String, DefaultResponse As String, XPos As Integer, YPos As Integer, ParentWindow As IWin32Window) As String
Dim Box As VBInputBox = New VBInputBox(Prompt, Title, DefaultResponse, XPos, YPos)
Box.ShowDialog(ParentWindow)

Expand All @@ -353,7 +354,7 @@ Namespace Microsoft.VisualBasic
Dim sPrompt As String = Nothing
Dim sTitle As String
Dim vbhost As IVbHost
Dim ParentWindow As Windows.Forms.IWin32Window = Nothing
Dim ParentWindow As IWin32Window = Nothing

vbhost = CompilerServices.HostServices.VBHost
If vbhost IsNot Nothing Then
Expand Down Expand Up @@ -405,10 +406,10 @@ Namespace Microsoft.VisualBasic
End Try

Return CType(System.Windows.Forms.MessageBox.Show(ParentWindow, sPrompt, sTitle,
CType(Buttons And &HF, Windows.Forms.MessageBoxButtons),
CType(Buttons And &HF0, Windows.Forms.MessageBoxIcon),
CType(Buttons And &HF00, Windows.Forms.MessageBoxDefaultButton),
CType(Buttons And &HFFFFF000, Windows.Forms.MessageBoxOptions)),
CType(Buttons And &HF, MessageBoxButtons),
CType(Buttons And &HF0, MessageBoxIcon),
CType(Buttons And &HF00, MessageBoxDefaultButton),
CType(Buttons And &HFFFFF000, MessageBoxOptions)),
MsgBoxResult)
End Function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
''' A dialog that shows progress used for Network.Download and Network.Upload
''' </summary>
Friend Class ProgressDialog
Inherits Windows.Forms.Form
Inherits Form

''' <summary>
''' Event raised when user cancels the dialog or closes it before the operation is completed
Expand Down Expand Up @@ -151,7 +151,7 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
''' We listen for this event since we want to make closing the dialog before it's
''' finished behave the same as a cancel
'''</remarks>
Private Sub ProgressDialog_FormClosing(sender As Object, e As Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Private Sub ProgressDialog_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing And Not _closeDialogInvoked Then
' If the progress bar isn't finished and the user hasn't already canceled
If ProgressBarWork.Value < 100 And Not _canceled Then
Expand Down Expand Up @@ -224,9 +224,9 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents LabelInfo As Windows.Forms.Label
Friend WithEvents ProgressBarWork As Windows.Forms.ProgressBar
Friend WithEvents ButtonCloseDialog As Windows.Forms.Button
Friend WithEvents LabelInfo As Label
Friend WithEvents ProgressBarWork As ProgressBar
Friend WithEvents ButtonCloseDialog As Button

'Required by the Windows Form Designer
Private ReadOnly _components As System.ComponentModel.IContainer
Expand All @@ -237,9 +237,9 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
<DebuggerStepThrough()>
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ProgressDialog))
LabelInfo = New Windows.Forms.Label
ProgressBarWork = New Windows.Forms.ProgressBar
ButtonCloseDialog = New Windows.Forms.Button
LabelInfo = New Label
ProgressBarWork = New ProgressBar
ButtonCloseDialog = New Button
SuspendLayout()
'
'LabelInfo
Expand Down
Loading