这段代码放到自己项目全局代码里面,保存时会报:”编译错误,UserCode不明确“
多次测试,发现只要把末尾部分蓝色字体代码注释掉,就能顺利保存了,但是为何会这种错误?求指教!
Public Class FoxSplitContainerEx
Public _ColorSplitterStandard As Color = Color.White
Public _ColorSplitterActivation As Color = Color.Black
Public _ColorSplitterBack As Color = Color.LightGray
Private WithEvents _sp As Windows.Forms.SplitContainer
Private _foxFrm As WinForm.Form
Sub New(sp As Foxtable.WinForm.SplitContainer)
_foxfrm = sp.Form
_sp = sp.BaseControl
Dim myPropInfo As System.Reflection.MethodInfo = _
_sp.Gettype().GetMethod("SetStyle", System.Reflection.BindingFlags.Public Or _
System.Reflection.BindingFlags.Instance Or _
System.Reflection.BindingFlags.NonPublic)
myPropInfo.Invoke(_sp, New Object() {Windows.Forms.ControlStyles.UserPaint Or _
Windows.Forms.ControlStyles.AllPaintingInWmPaint Or _
Windows.Forms.ControlStyles.OptimizedDoubleBuffer, True})
_sp.SplitterWidth = 9
_sp.Panel1MinSize = 0
_sp.Panel2MinSize = 0
If _sp.FixedPanel = Windows.Forms.FixedPanel.Panel2 Then
CollpasePanel = SplitterPanelEnum.Panel2
Else
CollpasePanel = SplitterPanelEnum.Panel1
End If
_sp.BackColor = _ColorSplitterBack
_sp.Refresh()
End Sub
Private mCollpased As Boolean = False
Private Enum SplitterPanelEnum
Panel1
Panel2
End Enum
Private mCollpasePanel As SplitterPanelEnum = SplitterPanelEnum.Panel2
Private Property CollpasePanel As SplitterPanelEnum
Get
Return mCollpasePanel
End Get
Set(value As SplitterPanelEnum)
If (value <> mCollpasePanel) Then
mCollpasePanel = value
_sp.Invalidate(Me.ControlRect)
End If
End Set
End Property
Private mRect As Rectangle = New Rectangle
Private ReadOnly Property ControlRect As Rectangle
Get
If (_sp.Orientation = Windows.Forms.Orientation.Horizontal) Then
If _sp.Width <= 80 Then
mRect.X = 0
Else
mRect.X = _sp.Width / 2 - 40
End If
mRect.Y = _sp.SplitterDistance
mRect.Width = 80
mRect.Height = 9
Else
mRect.X = _sp.SplitterDistance
If _sp.Height <= 80 Then
mRect.Y = 0
Else
mRect.Y = _sp.Height / 2 - 40
End If
mRect.Width = 9
mRect.Height = 80
End If
Return mRect
End Get
End Property
Private Enum MouseState
Normal
Hover
End Enum
Private mMouseState As MouseState = MouseState.Normal
Public Shadows Property IsSplitterFixed As Boolean
Get
Return _sp.IsSplitterFixed
End Get
Set(ByVal value As Boolean)
_sp.IsSplitterFixed = value
If (value AndAlso (mIsSplitterFixed = False)) Then
mIsSplitterFixed = True
End If
End Set
End Property
Private mIsSplitterFixed As Boolean = True
Private _HeightOrWidth As Integer
Public Sub CollpaseOrExpand()
_foxfrm.StopRedraw
If mCollpased Then
mCollpased = False
_sp.SplitterDistance = _HeightOrWidth
Else
mCollpased = True
_HeightOrWidth = _sp.SplitterDistance
If (CollpasePanel = SplitterPanelEnum.Panel1) Then
_sp.SplitterDistance = 0
ElseIf (_sp.Orientation = Windows.Forms.Orientation.Horizontal) Then
_sp.SplitterDistance = (_sp.Height - 9)
Else
_sp.SplitterDistance = (_sp.Width - 9)
End If
End If
_sp.Invalidate(Me.ControlRect)
_foxfrm.ResumeRedraw
End Sub
Private Sub _sp_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles _sp.MouseClick
If Me.ControlRect.Contains(e.Location) Then
CollpaseOrExpand()
End If
End Sub
Private Sub _sp_MouseLeave(sender As Object, e As System.EventArgs) Handles _sp.MouseLeave
_sp.Cursor = Windows.Forms.Cursors.Default
mMouseState = MouseState.Normal
_sp.Invalidate(Me.ControlRect)
End Sub
Private Sub _sp_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles _sp.Paint
e.Graphics.Clear(_ColorSplitterBack)
Dim collpase As Boolean = False
If (Me.CollpasePanel = SplitterPanelEnum.Panel1 AndAlso mCollpased = False) _
OrElse (Me.CollpasePanel = SplitterPanelEnum.Panel2 AndAlso mCollpased) Then
collpase = True
End If
Dim _color As Color
If mMouseState = MouseState.Normal Then
_color = _ColorSplitterStandard
Else
_color = _ColorSplitterActivation
End If
Dim bmp As Bitmap = CreateControlImage(collpase, _color)
If (sender.Orientation = Windows.Forms.Orientation.Vertical) Then
bmp.RotateFlip(RotateFlipType.Rotate90FlipX)
End If
e.Graphics.SetClip(sender.SplitterRectangle)
e.Graphics.DrawImage(bmp, Me.ControlRect)
End Sub
Private Function CreateControlImage(ByVal collapse As Boolean, ByVal color As Color) As Bitmap
Dim bmp As Bitmap = New Bitmap(80, 9)
Dim x As Integer = 5
Do While (x <= 30)
Dim y As Integer = 1
Do While (y <= 7)
bmp.SetPixel(x, y, color)
y = (y + 3)
Loop
x = (x + 5)
Loop
x = 50
Do While (x <= 75)
Dim y As Integer = 1
Do While (y <= 7)
bmp.SetPixel(x, y, color)
y = (y + 3)
Loop
x = (x + 5)
Loop
If collapse Then
Dim k As Integer = 0
Dim y As Integer = 7
Do While (y >= 1)
x = (35 + k)
Do While (x <= (45 - k))
bmp.SetPixel(x, y, color)
x = (x + 1)
Loop
k = (k + 1)
y = (y - 1)
Loop
Else
Dim k As Integer = 0
Dim y As Integer = 1
Do While (y <= 7)
x = (35 + k)
Do While (x <= (45 - k))
bmp.SetPixel(x, y, color)
x = (x + 1)
Loop
k = (k + 1)
y = (y + 1)
Loop
End If
Return bmp
End Function
Private Sub _sp_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles _sp.MouseMove
If sender.SplitterRectangle.Contains(e.Location) Then
If Me.ControlRect.Contains(e.Location) Then
If (Me.IsSplitterFixed = False) Then
Me.IsSplitterFixed = True
mIsSplitterFixed = False
End If
sender.Cursor = Windows.Forms.Cursors.Hand
mMouseState = MouseState.Hover
sender.Invalidate(Me.ControlRect)
Else
If (mIsSplitterFixed = False) Then
Me.IsSplitterFixed = False
If (sender.Orientation = Windows.Forms.Orientation.Horizontal) Then
sender.Cursor = Windows.Forms.Cursors.HSplit
Else
sender.Cursor = Windows.Forms.Cursors.VSplit
End If
Else
sender.Cursor = Windows.Forms.Cursors.Default
End If
mMouseState = MouseState.Normal
sender.Invalidate(Me.ControlRect)
End If
End If
End Sub
Public Shared Sub UpRefresh()
RaiseEvent Ref()
End Sub
Private Shared Event Ref()
Private Sub FoxSplitContainerEx_Ref() Handles Me.Ref
_sp.Refresh()
End Sub
End Class
[此贴子已经被作者于2018/8/30 16:26:20编辑过]