Foxtable(狐表)用户栏目专家坐堂 → 同样的全局代码,放到自己的项目中,保存会报错?


  共有1607人关注过本帖树形打印复制链接

主题:同样的全局代码,放到自己的项目中,保存会报错?

帅哥哟,离线,有人找我吗?
bahamute
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1421 积分:11294 威望:0 精华:0 注册:2008/9/1 22:20:00
同样的全局代码,放到自己的项目中,保存会报错?  发帖心情 Post By:2018/8/30 16:26:00 [只看该作者]

这段代码放到自己项目全局代码里面,保存时会报:”编译错误,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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/30 16:37:00 [只看该作者]

1、我拷贝粘贴进去没问题;

 

2、你全局代码肯定有别的代码影响导致的。


 回到顶部
帅哥哟,离线,有人找我吗?
bahamute
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1421 积分:11294 威望:0 精华:0 注册:2008/9/1 22:20:00
  发帖心情 Post By:2018/8/30 16:54:00 [只看该作者]

我也是这么认为的,所以把全局代码里面其它的全都注释掉,然后粘贴上面的代码进去,结果还是报 ”编译错误,UserCode不明确“。

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/30 17:09:00 [只看该作者]

以下是引用bahamute在2018/8/30 16:54:00的发言:
我也是这么认为的,所以把全局代码里面其它的全都注释掉,然后粘贴上面的代码进去,结果还是报 ”编译错误,UserCode不明确“。

 

1、你确定全部全局代码都注释、删除掉了?你尝试把其余代码删除后测试。

 

2、是不是和你引用的dll文件夹冲突?

 

3、主要是看定义的东西是否重名。


 回到顶部