谈谈Unicode编码,简要解释UCS、UTF、BMP、BOM等名词 [转]

出处:http://www.fmddlmyy.cn/text6.html

这是一篇程序员写给程序员的趣味读物。所谓趣味是指可以比较轻松地了解一些原来不清楚的概念,增进知识,类似于打RPG游戏的升级。整理这篇文章的动机是两个问题:

问题一:
使用Windows记事本的“另存为”,可以在GBK、Unicode、Unicode big endian和UTF-8这几种编码方式间相互转换。同样是txt文件,Windows是怎样识别编码方式的呢?

我很早前就发现Unicode、Unicode big endian和UTF-8编码的txt文件的开头会多出几个字节,分别是FF、FE(Unicode),FE、FF(Unicode big endian),EF、BB、BF(UTF-8)。但这些标记是基于什么标准呢?

问题二:
最近在网上看到一个ConvertUTF.c,实现了UTF-32、UTF-16和UTF-8这三种编码方式的相互转换。对于Unicode(UCS2)、GBK、UTF-8这些编码方式,我原来就了解。但这个程序让我有些糊涂,想不起来UTF-16和UCS2有什么关系。

查了查相关资料,总算将这些问题弄清楚了,顺带也了解了一些Unicode的细节。写成一篇文章,送给有过类似疑问的朋友。本文在写作时尽量做到通俗易懂,但要求读者知道什么是字节,什么是十六进制。

继续阅读谈谈Unicode编码,简要解释UCS、UTF、BMP、BOM等名词 [转]

GridView.RowCount 与 GridView.DataRowCount 的区别

RowCount

GridView.RowCount Property | WinForms Controls | DevExpress Help

This property overrides the BaseView.RowCount property to increment its value in the following cases:

NoteDetail pattern Views do not contain data and they are never displayed within XtraGrid. So, the RowCount member must not be invoked for these Views. The RowCount member can only be used with real Views that are displayed within the Grid Control. The real Views with which an end-user interacts at runtime can be accessed using the following methods.

DataRowCount

BaseView.DataRowCount Property | WinForms Controls | DevExpress Help

Note that data rows can be hidden within collapsed groups when data grouping is applied. The DataRowCount property returns the total number of data rows regardless of whether they are within collapsed groups or not. Also, the property’s return value is not always the same as the number of records within the associated data source. When data filtering is applied, the DataRowCount property returns the number of rows that match the filter condition.

NoteDetail pattern Views do not contain data and they are never displayed within XtraGrid. So, the DataRowCount member must not be invoked for these Views. The DataRowCount member can only be used with real Views that are displayed within the Grid Control. The real Views with which an end-user interacts at runtime can be accessed using the following methods.

试比较:

Private Sub GridView1_MouseDown(sender As Object, e As MouseEventArgs) Handles GridView1.MouseDown
        Dim view As GridView = TryCast(sender, GridView)
        Dim hitInfo As GridHitInfo = view.CalcHitInfo(e.Location)
        Select Case hitInfo.HitTest
            Case GridHitTest.Column
                SelectColumn(view, hitInfo)
            Case Else                ' 
                view.OptionsSelection.MultiSelect = False
                view.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect
        End Select
 End Sub

 Private Sub SelectColumn(ByRef View As GridView, ByRef hitinfo As GridHitInfo)
        '全选列(不排列)
        View.OptionsSelection.MultiSelect = True
        View.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CellSelect
        View.OptionsCustomization.AllowSort = False
        View.ClearSelection()

        View.SelectCells(New GridCell(0, hitinfo.Column), New GridCell(View.DataRowCount - 1, hitinfo.Column))
        View.OptionsCustomization.AllowSort = True
End Sub

 

addhanderl与handels区别

遇到一个问题。addhandler 与 handels的区别是什么

举例:如下语句运行成功

 Private Sub 供货商IDSearchLookUpEdit_TextChanged(sender As Object, e As EventArgs) Handles 供货商IDSearchLookUpEdit.TextChanged
        MsgBox(sender.name, MsgBoxStyle.OkCancel, "测试")
End Sub

如下语句不成功

Private Sub 主界面_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    AddHandler 供货商IDSearchLookUpEdit.TextChanged, AddressOf 供货商IDSearchLookUpEdit_TextChanged
end sub

Private Sub 供货商IDSearchLookUpEdit_TextChanged(sender As Object, e As EventArgs)
        'Handles 供货商IDSearchLookUpEdit.TextChanged
        MsgBox(sender.name, MsgBoxStyle.OkCancel, "测试")
End Sub

 

如何让TreeListLookup在弹出时,自动对焦到搜索框

QQ截图20160516152712

如图所示,在弹出时,自动对焦到红框区域。

 Private Sub 商品查找品牌RepositoryItemTreeListLookUpEdit_Popup(sender As Object, e As EventArgs) Handles 商品查找品牌RepositoryItemTreeListLookUpEdit.Popup
        Dim editor As TreeListLookUpEdit = CType(sender, TreeListLookUpEdit)
        editor.Properties.TreeList.ShowFindPanel()
End Sub
 Private Sub 商品查找商品RepositoryItemSearchLookUpEdit_Popup(sender As Object, e As EventArgs) Handles 商品查找商品RepositoryItemSearchLookUpEdit.Popup
        Dim editor As SearchLookUpEdit = CType(sender, SearchLookUpEdit)
        editor.Properties.View.ShowFindPanel()
End Sub

 

使用微软语言包实现汉字(还其他非汉字字符)转拼音

微软官方语言包下载地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn

备份下载地址:链接: http://pan.baidu.com/s/1dF4oTfr 密码: dx4h

使用方法:完成之后在项目中引用安装目录中的ChnCharInfo.dll即可

实现汉字转拼音demo(原创)

Imports Microsoft.International.Converters.PinYinConverter
Module Demo
Public Enum 拼音格式
        首字母 = 0
        全拼 = 1
    End Enum

    Public Function 获取拼音码(ByVal inputText As String, Optional 拼音格式 As 拼音格式 = 拼音格式.首字母) As String
        if inputText is Nothing or inputText="" then 
            return Nothing
        end if
        Dim PY As String = ""
        For Each Cha In inputText.Trim()
            Try
                Dim chinesechar As ChineseChar = New ChineseChar(Cha)
                Select Case 拼音格式
                    Case 拼音格式.首字母
                        PY += chinesechar.Pinyins(0).Substring(0, 1).ToLower
                    Case 拼音格式.全拼
                        PY += chinesechar.Pinyins(0).ToLower
                End Select
            Catch ex As System.NotSupportedException
                PY += Cha         ‘遇到非中文字符,直接原样返回
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Next
        Return PY
End Function
End Module

多音字不知如何处理,比如:蹲(dūn、cún )的结果为cún

未能正确加载“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】自定义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