前期的帖子:RichTextBox随机单元格例子
http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=98484
希望RichTextBox窗口显示数据时段落首行缩进,数据表保持不缩进。
谢谢!
--------------
1、全局代码:
Public Class UtilsSetLineSpace
Public Const WM_USER As Integer = &H400
Public Const EM_GETPARAFORMAT As Integer = WM_USER + 61
Public Const EM_SETPARAFORMAT As Integer = WM_USER + 71
Public Const MAX_TAB_STOPS As Long = 32
Public Const PFM_LINESPACING As UInteger = &H100
<StructLayout(LayoutKind.Sequential)> _
Private Structure PARAFORMAT2
Public cbSize As Integer
Public dwMask As UInteger
Public wNumbering As Short
Public wReserved As Short
Public dxStartIndent As Integer
Public dxRightIndent As Integer
Public dxOffset As Integer
Public wAlignment As Short
Public cTabCount As Short
<MarshalAs(UnmanagedType.ByValArray, SizeConst := 32)> _
Public rgxTabs As Integer()
Public dySpaceBefore As Integer
Public dySpaceAfter As Integer
Public dyLineSpacing As Integer
Public sStyle As Short
Public bLineSpacingRule As Byte
Public bOutlineLevel As Byte
Public wShadingWeight As Short
Public wShadingStyle As Short
Public wNumberingStart As Short
Public wNumberingStyle As Short
Public wNumberingTab As Short
Public wBorderSpace As Short
Public wBorderWidth As Short
Public wBorders As Short
End Structure
<DllImport("user32", CharSet := CharSet.Auto)> _
Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lParam As PARAFORMAT2) As IntPtr
End Function
''' <summary>
''' 设置行距
''' </summary>
''' <param name="ctl">控件</param>
''' <param name="dyLineSpacing">间距</param>
Public Shared Sub SetLineSpace(ctl As Windows.Forms.Control, dyLineSpacing As Integer)
Dim fmt As New PARAFORMAT2()
fmt.cbSize = Marshal.SizeOf(fmt)
fmt.bLineSpacingRule = 4
' bLineSpacingRule;
fmt.dyLineSpacing = dyLineSpacing
fmt.dwMask = PFM_LINESPACING
Try
SendMessage(New HandleRef(ctl, ctl.Handle), EM_SETPARAFORMAT, 0, fmt)
Catch
End Try
End Sub
End Class
Public Sub mytxt_TextChanged(sender As Object, e As EventArgs)
Functions.Execute("mytxt_TextChanged", sender, e)
End Sub
-----------
2、窗口afterload:
Dim rt As new Windows.Forms.RichTextBox '定义 一个RichTextBox
rt.Dock = Windows.Forms.DockStyle.Fill '控件停靠方式为撑满父控件
rt.name = "mytxt" '设置控件名称
e.Form.Controls("Panel1").BaseControl.Controls.Add(rt) '控件放入Panel1中作为子控件
vars("xy") = ""
UtilsSetLineSpace.SetLineSpace(rt, 400)
addhandler rt.TextChanged, addressof mytxt_TextChanged
-----------------
3、窗口TimerTick:
If vars("xy") <> CurrentTable.RowSel & "," & CurrentTable.ColSel Then
vars("xy") = CurrentTable.RowSel & "," & CurrentTable.ColSel
Dim rt = e.form.Controls("Panel1").basecontrol.Controls("mytxt")
rt.text = CurrentTable.Value
rt.Select(0, rt.text.length)
rt.SelectionColor = Color.Red '背景色
rt.SelectionFont = New Font("楷体",20,FontStyle.Bold) '字体字号
End If