VB.NET相关代码整理

窗口双缓冲

    Public Sub New()

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        SetStyle(Windows.Forms.ControlStyles.OptimizedDoubleBuffer Or Windows.Forms.ControlStyles.ResizeRedraw Or Windows.Forms.ControlStyles.AllPaintingInWmPaint, True)

    End Sub

TextBox去除默认右键信息 

Public Class ClaTextbox

    Inherits System.Windows.Forms.TextBox

    Public Sub New()
        MyBase.New()
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg <> &H7B Then
            MyBase.WndProc(m)
        End If
    End Sub

End Class

正则表达式

'正则表达式
    Public Function GetRegex(ByVal txtStr As String, ByVal regStr As String, ByVal groupIndex As Integer) As String
        GetRegex = ""
        Dim reg As New System.Text.RegularExpressions.Regex(regStr)
        Dim matchs As System.Text.RegularExpressions.Match = reg.Match(txtStr)
        GetRegex = matchs.Groups(groupIndex).Value
    End Function
Imports System.Drawing.Drawing2D
Public Class RoundPanel
    Inherits Panel

    Private mMatrixRound As Integer = 8
    Private mBack As Color

    Public Property Back() As Color
        Get
            Return mBack
        End Get
        Set(ByVal value As Color)
            If value = Nothing Then
                mBack = Control.DefaultBackColor
            Else
                mBack = value
            End If
            MyBase.Refresh()
        End Set
    End Property

    Public Property MatrixRound() As Integer
        Get
            Return mMatrixRound
        End Get
        Set(ByVal value As Integer)
            mMatrixRound = value
            MyBase.Refresh()
        End Set
    End Property

    Private Function CreateRound(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
        Dim RoundRect As New GraphicsPath
        RoundRect.AddLine(rect.Left + radius - 1, rect.Top - 1, rect.Right - radius, rect.Top - 1)          '顶端 
        RoundRect.AddArc(rect.Right - radius, rect.Top - 1, radius, radius, 270, 90)                        '右上角 
        RoundRect.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius)                  '右边 
        RoundRect.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90)                  '右下角 
        RoundRect.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom)                '底边 
        RoundRect.AddArc(rect.Left - 1, rect.Bottom - radius, radius, radius, 90, 90)                       '左下角 
        RoundRect.AddLine(rect.Left - 1, rect.Top + radius, rect.Left - 1, rect.Bottom - radius)            '左边 
        RoundRect.AddArc(rect.Left - 1, rect.Top - 1, radius, radius, 180, 90)                              '左上角 
        Return RoundRect
    End Function

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim W As Integer = MyBase.Width - MyBase.Margin.Left - MyBase.Margin.Right
        Dim H As Integer = MyBase.Height - MyBase.Margin.Top - MyBase.Margin.Bottom
        Dim Rec As New Rectangle(MyBase.Margin.Left, MyBase.Margin.Top, W, H)
        Dim Round As GraphicsPath = CreateRound(Rec, mMatrixRound)
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
        e.Graphics.FillPath(DirectCast(New SolidBrush(mBack), Brush), Round)
    End Sub

    Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
        MyBase.Refresh()
    End Sub
End Class
--------------------- 
作者:localcms 
来源:CSDN 
原文:https://blog.csdn.net/localcms/article/details/1883493 
版权声明:本文为博主原创文章,转载请附上博文链接!

操作Excel时,在ExcelApplication关闭时对其后台进程进行关闭

GC.Collect

操作Excel时,打开文件提示"服务器出现意外"时,将Excel中的福昕阅读器的加载项去掉即可。

多进程委托处理代码

    '多线程进度条委托
    Dim tdProgressBar As Threading.Thread '进度条线程
    Delegate Sub dgProgressBar()

    Sub dgSubProgressBar()
        Dim newdgProgressBar As New dgProgressBar(AddressOf SetProgressBar) '实例化委托,指向实际执行进度条的过程
        Me.Invoke(newdgProgressBar) '将进度条数据传至进度条过程中
    End Sub

    Sub SetProgressBar()
        With pgbChildProgress
            .PerformStep()
            lblChildProgressInfo.Text = Format(.Value / .Maximum, "0 %")
            Threading.Thread.Sleep(10)
        End With
    End Sub

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值