在创建新项目时,VB.NET IDE 默认自动将 Option Strict 设置为 Off。
因此,我经常将Option Strict On放在我的文件顶部作为一种良好的编程习惯,并且对于该文件应用 Option Strict 规则。
现在(一段时间),当创建一个新项目时,我在项目的属性/编译下将 Option Strict 设置为 On,以便应用于整个项目,而无需在每个文件上指定。
但是现在我在我的项目下使用了一个外国程序,其中数据类型对我来说并不完全了解,我想为项目中的所有文件保留 Option Strict,除了那个。
我尝试在该文件顶部使用Option Strict Off,但这似乎还不够。在我的 IDE/Errors 选项卡下列出了许多典型错误。
如何在项目的编译器属性下只为一个在项目下打开选项严格的文件关闭选项严格?
Public Class ApplicationBar
Inherits NativeWindow
' Debugging Mode On/Off
#Const DEBUG_MODE = False
' SetWindowLong selectors
Const GWL_WNDPROC = -4&
' Windows messages
Const WM_ACTIVATE = &H6
Const WM_GETMINMAXINFO = &H24
Const WM_ENTERSIZEMOVE = &H231
Const WM_EXITSIZEMOVE = &H232
Const WM_MOVING = &H216
Const WM_NCHITTEST = &H84
Const WM_NCMOUSEMOVE = &HA0
Const WM_SIZING = &H214
Const WM_TIMER = &H113
Const WM_WINDOWPOSCHANGED = &H47
' WM_SIZING Selectors
Const WMSZ_LEFT = 1
Const WMSZ_RIGHT = 2
Const WMSZ_TOP = 3
Const WMSZ_TOPLEFT = 4
Const WMSZ_TOPRIGHT = 5
Const WMSZ_BOTTOM = 6
Const WMSZ_BOTTOMLEFT = 7
Const WMSZ_BOTTOMRIGHT = 8
' Appbar messages
Const ABM_NEW = &H0
Const ABM_REMOVE = &H1
Const ABM_QUERYPOS = &H2
Const ABM_SETPOS = &H3
Const ABM_GETSTATE = &H4
Const ABM_GETTASKBARPOS = &H5
Const ABM_ACTIVATE = &H6
Const ABM_GETAUTOHIDEBAR = &H7
Const ABM_SETAUTOHIDEBAR = &H8
Const ABM_WINDOWPOSCHANGED = &H9
Const ABM_SETSTATE = &HA
' Appbar edges
Const ABE_LEFT = 0
Const ABE_TOP = 1
Const ABE_RIGHT = 2
Const ABE_BOTTOM = 3
Const ABE_UNKNOWN = 4
Const ABE_FLOAT = 5
'Appbar allowed floats
Const ABF_ALLOWLEFT = 1
Const ABF_ALLOWRIGHT = 2
Const ABF_ALLOWTOP = 4
Const ABF_ALLOWBOTTOM = 8
Const ABF_ALLOWFLOAT = 16
' The ABN_* constants are defined here as follows:
'Const ABN_STATECHANGE = &H0
Const ABN_POSCHANGED = &H1
Const ABN_FULLSCREENAPP = &H2
Const ABN_WINDOWARRANGE = &H3
' GetKeyState and GetAsyncKeyState Selectors
Const VK_LBUTTON = &H1
Const VK_RBUTTON = &H2
Const VK_CONTROL = &H11
' MessageBox Selectors
Const MB_OK = &H0&
Const MB_ICONINFORMATION = &H40&
' ModifyStyle Selectors
Const GWL_STYLE = (-16)
Const GWL_EXSTYLE = (-20)
Const WS_CAPTION = &HC00000
Const WS_SYSMENU = &H80000
Const WS_EX_APPWINDOW = &H40000
Const WS_BORDER = &H800000
' SetWindowPos Selectors
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOZORDER = &H4
Const SWP_NOACTIVATE = &H10
Const SWP_DRAWFRAME = &H20
Const HWND_NOTOPMOST = -2
Const HWND_TOPMOST = -1
Const HWND_BOTTOM = 1
' ShowWindow Selectors
Const SW_HIDE = 0
Const SW_SHOW = 5
' WM_ACTIVATE Selectors
Const WA_INACTIVE = 0
'Custom Defaults
Private Const AB_DEF_SIZE_INC As Integer = 1
Private Const AB_DEF_DOCK_SIZE As Integer = 32
' We need a timer to determine when the AppBar should be re-hidden
Const AUTO_HIDE_TIMER_ID = 100
Const SLIDE_DEF_TIMER_INTERVAL = 400 ' milliseconds
' Subclassing function default result
Const INHERIT_DEFAULT_CALLBACK = -1
所有这些变量都带有绿色下划线,因为没有明确声明,并且在 Option Strict On 下被视为错误。