未能正确加载“RoslynPackage”包

在安装完DexExpress后,启动VS2015每次创建新项目都弹出“未能正确加载“RoslynPackage”包”的对话框,解决方法如下:

1、删除以下文件夹%appdata%\Local\Microsoft\VisualStudio\14.0\ComponentModelCache (以防万一,请做好备份)

2、删除以下文件夹%appdata%\Local\Microsoft\VisualStudio\14.0\Extensions (以防万一,请做好备份)。P.S.无法删除的话就删除文件夹内的文件。

3、重新打开VS2015,程序自动扫描已安装的扩展并重新生成新的文件夹

【VB.NET】带关闭按钮的选项卡

'来源:http://www.vbforums.com/showthread.php?622242-TabControl-with-Close-button-on-TabPages-(with-Design-Time-support)

Option Strict On
Imports System.ComponentModel



<ToolboxBitmap(GetType(System.Windows.Forms.TabControl))>
Public Class TabControlEx
    Inherits System.Windows.Forms.TabControl

    Private Declare Auto Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    Protected CloseButtonCollection As New Dictionary(Of Button, TabPage)
    Private _ShowCloseButtonOnCurrentTab As Boolean = True
    Private _ShowCloseButtonOnTabs As Boolean = False


    <Browsable(True), DefaultValue(True), Category("Behavior"), Description("Indicates whether a close button should be shown on each TabPage")>
    Public Property ShowCloseButtonOnCurrentTab() As Boolean
        Get
            Return _ShowCloseButtonOnCurrentTab
        End Get
        Set(ByVal value As Boolean)
            _ShowCloseButtonOnCurrentTab = value
            For Each btn In CloseButtonCollection.Keys
                btn.Visible = _ShowCloseButtonOnCurrentTab
            Next
            RePositionCloseButtons()
        End Set
    End Property


    <Browsable(True), DefaultValue(True), Category("Behavior"), Description("Indicates whether a close button should be shown on each TabPage")>
    Public Property ShowCloseButtonOnTabs() As Boolean
        Get
            Return _ShowCloseButtonOnTabs
        End Get
        Set(ByVal value As Boolean)
            _ShowCloseButtonOnTabs = value

            RePositionCloseButtons()
        End Set
    End Property

    Protected Overrides Sub OnCreateControl()
        MyBase.OnCreateControl()


        For Each item In CloseButtonCollection
            item.Value.Text = item.Value.Text.Trim & Space(4)
        Next

        RePositionCloseButtons()
    End Sub

    Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
        MyBase.OnControlAdded(e)
        Dim tp As TabPage = DirectCast(e.Control, TabPage)
        Dim rect As Rectangle = Me.GetTabRect(Me.TabPages.IndexOf(tp))
        Dim btn As Button = AddCloseButton(tp)
        btn.Size = New Size(rect.Height - 1, rect.Height - 1)
        btn.Location = New Point(rect.X + rect.Width - rect.Height - 1, rect.Y + 1)
        SetParent(btn.Handle, Me.Handle)
        AddHandler btn.Click, AddressOf OnCloseButtonClick
        CloseButtonCollection.Add(btn, tp)
    End Sub

    Protected Overrides Sub OnControlRemoved(ByVal e As System.Windows.Forms.ControlEventArgs)
        Dim btn As Button = CloseButtonOfTabPage(DirectCast(e.Control, TabPage))
        RemoveHandler btn.Click, AddressOf OnCloseButtonClick
        CloseButtonCollection.Remove(btn)
        SetParent(btn.Handle, Nothing)
        btn.Dispose()
        MyBase.OnControlRemoved(e)
    End Sub

    Protected Overrides Sub OnLayout(ByVal levent As System.Windows.Forms.LayoutEventArgs)
        MyBase.OnLayout(levent)
        RePositionCloseButtons()
    End Sub

    Public Event CloseButtonClick As CancelEventHandler
    Protected Overridable Sub OnCloseButtonClick(ByVal sender As Object, ByVal e As EventArgs)
        If Not DesignMode Then
            Dim btn As Button = DirectCast(sender, Button)
            Dim tp As TabPage = CloseButtonCollection(btn)
            Dim ee As New CancelEventArgs
            RaiseEvent CloseButtonClick(sender, ee)

            If Not ee.Cancel Then
                If MsgBox("是否关闭 " + tp.Text.Trim + "标签?") = MsgBoxResult.Ok Then
                    Me.TabPages.Remove(tp)
                    RePositionCloseButtons()
                End If
            End If
            End If
    End Sub

    Protected Overridable Function AddCloseButton(ByVal tp As TabPage) As Button
        Dim closeButton As New Button
        With closeButton
            '' TODO: Give a good visual appearance to the Close button, maybe by assigning images etc.
            ''       Here I have not used images to keep things simple.
            .Text = "X"
            .FlatStyle = FlatStyle.Flat
            .BackColor = Color.FromKnownColor(KnownColor.ButtonFace)
            .ForeColor = Color.White
            .Font = New Font("Microsoft Sans Serif", 6, FontStyle.Bold)
        End With
        Return closeButton
    End Function

    Public Sub RePositionCloseButtons()
        For Each item In CloseButtonCollection
            RePositionCloseButtons(item.Value)
        Next
    End Sub

    Public Sub RePositionCloseButtons(ByVal tp As TabPage)
        Dim btn As Button = CloseButtonOfTabPage(tp)
        If btn IsNot Nothing Then
            Dim tpIndex As Integer = Me.TabPages.IndexOf(tp)
            If tpIndex >= 0 Then
                Dim rect As Rectangle = Me.GetTabRect(tpIndex)
                If Me.SelectedTab Is tp Then
                    btn.BackColor = Color.Red
                    btn.Size = New Size(rect.Height - 1, rect.Height - 1)
                    btn.Location = New Point(rect.X + rect.Width - rect.Height, rect.Y + 1)
                    btn.Visible = ShowCloseButtonOnCurrentTab
                Else
                    btn.BackColor = Color.FromKnownColor(KnownColor.ButtonFace)
                    btn.Size = New Size(rect.Height - 3, rect.Height - 3)
                    btn.Location = New Point(rect.X + rect.Width - rect.Height - 1, rect.Y + 1)
                    btn.Visible = Me.ShowCloseButtonOnTabs
                End If

                btn.BringToFront()
            End If
        End If
    End Sub

    Protected Function CloseButtonOfTabPage(ByVal tp As TabPage) As Button
        Return (From item In CloseButtonCollection Where item.Value Is tp Select item.Key).FirstOrDefault
    End Function
End Class

 

【VB.NET】TabControl有关事件

事件: Deselecting               e.TabPage.Text=TabPage1
标签: SelectedTab               TabPage1
——————–
事件: Deselected               e.TabPage.Text=TabPage1
标签: SelectedTab               TabPage1
——————–
事件: Selecting               e.TabPage.Text=TabPage2
标签: SelectedTab               TabPage2
——————–
事件: Selected               e.TabPage.Text=TabPage2
标签: SelectedTab               TabPage2
——————–
事件: SelectedIndexChanged               TabPage2
标签: SelectedTab               TabPage2

【VB.NET】自定义TextBox类,添加显示下划线属性

实现功能:
a.ShowLine 参数:设置下划线是否可见
b.LineColor参数:设置下划线颜色
c.LineWidth参数:设置下划线粗细
d.LineOffset参数:设置下划线偏移量

Imports System.ComponentModel

<ToolboxBitmap(GetType(System.Windows.Forms.TextBox))>
Public Class TextBoxEx
    Inherits System.Windows.Forms.TextBox

    Protected _lineColor As Color = Color.Black
    Protected _lineWidth As Integer = 1
    Protected _lineOffset As Integer = 3
    Protected _showLine As Boolean = False
    Protected WithEvents Line As New Control()

    <DefaultValue(GetType(Color), "Black")>
    <Description("下划线颜色")>
    Public Property LineColor As Color
        Get
            Return _lineColor
        End Get
        Set(value As Color)
            If _lineColor <> value Then
                _lineColor = value
                RaiseEvent LineColorChanged(Me, Nothing)
            End If
        End Set
    End Property

    <DefaultValue(1)>
    <Description("下划线宽度")>
    Public Property LineWidth As Integer
        Get
            Return _lineWidth
        End Get
        Set(value As Integer)
            If _lineWidth <> value Then
                _lineWidth = value
                RaiseEvent LineWidthChanged(Me, Nothing)
            End If
        End Set
    End Property

    <DefaultValue(3)>
    <Description("下划线偏移量")>
    Public Property LineOffset As Integer
        Get
            Return _lineOffset
        End Get
        Set(value As Integer)
            If _lineOffset <> value Then
                _lineOffset = value
                RaiseEvent LineOffsetChanged(Me, Nothing)
            End If
        End Set
    End Property

    <DefaultValue(False)>
    <Description("指示控件是否显示下划线")>
    Public Property ShowLine As Boolean
        Get
            Return _showLine
        End Get
        Set(value As Boolean)
            _showLine = value
            RaiseEvent ShowLineChanged(Me, Nothing)
        End Set
    End Property

    ''' <summary>
    ''' 在 TextBoxEx.LineColor 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event LineColorChanged(ByVal sender As Object, e As EventArgs)

    ''' <summary>
    ''' 在 TextBoxEx.LineWidth 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event LineWidthChanged(ByVal sender As Object, e As EventArgs)

    ''' <summary>
    ''' 在 TextBoxEx.ShowLine 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event ShowLineChanged(ByVal sender As Object, e As EventArgs)
    ''' <summary>
    ''' 在 TextBoxEx.LineOffset 属性值发生更改时发生
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Event LineOffsetChanged(ByVal sender As Object, e As EventArgs)

    Public Sub onLineWidthChanged(ByVal sender As Object, e As EventArgs) Handles Me.LineWidthChanged, Me.LineOffsetChanged, Me.LineColorChanged
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub

    Public Sub onShowLineChanged() Handles Me.ShowLineChanged
        If Me.ShowLine Then
            BorderStyle = BorderStyle.None
            BackColor = Color.FromKnownColor(KnownColor.Control)
            rePosLine()
        Else
            BorderStyle = BorderStyle.Fixed3D
            BackColor = Color.FromKnownColor(KnownColor.Window)
            If Not IsNothing(Line) Then
                Line.Visible = False
            End If
        End If
    End Sub

    Protected Overrides Sub OnParentChanged(e As EventArgs)
        MyBase.OnParentChanged(e)
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub

    Protected Overrides Sub OnLocationChanged(e As EventArgs)
        MyBase.OnLocationChanged(e)
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub

    Protected Sub rePosLine()
        If Not IsNothing(Me.Parent) Then
            If Not Me.Parent.Controls.Contains(Line) Then
                Me.Parent.Controls.Add(Line)
            End If
            Line.Width = Me.Width
            Line.Height = Me.LineWidth
            Line.BackColor = Me.LineColor
            Line.Location = New Point(Me.Location.X, Me.Location.Y + Me.Height + Me.LineOffset)
            Line.Visible = True
            Line.BringToFront()
        End If
    End Sub

    Protected Overrides Sub Dispose(disposing As Boolean)
        MyBase.Dispose(disposing)
        If disposing Then
            If Not IsNothing(Line) Then
                Line.Dispose()
            End If
        End If
    End Sub

    Protected Overrides Sub OnLayout(levent As LayoutEventArgs)
        MyBase.OnLayout(levent)
        If Me.ShowLine Then
            rePosLine()
        End If
    End Sub
End Class

 

“向程序发送命令时出现问题”解决方案

之前用着好好的,最近不知为啥,双击打开Flash、xls、word等文档时,弹出窗口“向程序发送命令时出现问题”,如图:

“向程序发送命令式出现问题”截图
“向程序发送命令式出现问题”解决方案

经过多番百度一下、谷歌一下之后,找到解决方案:在程序快捷方式上单击鼠标右键,选择【属性】,转到【兼容性】选项卡,勾选【以兼容模式运行这个程序】,选择【Windows7】。如果勾选了【以管理员身份运行此程序】,请去掉。如图:

“向程序发送命令时出现问题”解决方案截图
“向程序发送命令时出现问题”解决方案