Foxtable(狐表)用户栏目专家坐堂 → [求助]RichTextBox窗口段落首行缩进如何设置


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

主题:[求助]RichTextBox窗口段落首行缩进如何设置

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


加好友 发短信
等级:四尾狐 帖子:962 积分:8505 威望:0 精华:0 注册:2012/10/3 13:25:00
[求助]RichTextBox窗口段落首行缩进如何设置  发帖心情 Post By:2017/6/25 17:44:00 [只看该作者]

前期的帖子: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

 

 

 


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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/25 18:43:00 [只看该作者]

 没有方法直接设置缩进的,只能填充空格进去。

 

 在你绑定的TextChanged事件,再把空格去掉即可。


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


加好友 发短信
等级:四尾狐 帖子:962 积分:8505 威望:0 精华:0 注册:2012/10/3 13:25:00
  发帖心情 Post By:2017/6/26 20:59:00 [只看该作者]

按照版主的提示,可以达到缩进的效果,但是感到变换单元格时,显示速度比较慢,好像等一下的感觉,定时器设置为100。請版主看看代码是否有问题,谢谢!

 

1、在RichTextBox窗口的TimerTick事件设置的添加空格代码:

Dim rt = e.form.Controls("Panel1").basecontrol.Controls("mytxt")

static ps As String = Nothing
Dim s As String = CurrentTable.RowSel & "," & CurrentTable.ColSel
If ps <> s Then
    Dim str As String = CurrentTable.Value
    str = str.Replace(chr(10), "").replace("    ", "")
    str = "    " & str.Replace(chr(13), vbcrlf & "    ").trim()
    CurrentTable.Value = str
    rt.text = CurrentTable.Current(CurrentTable.ColSel)
End If
ps = s

2、然后在当前表的AfterSelChange事件设置下列代码:

For Each r As Row In CurrentTable.Rows    '清除多余空格
    For Each c As Col In CurrentTable.Cols
            
            If r.IsNull(c.Name) =  False AndAlso c.IsString Then r(c.Name) = r(c.Name).replace(" ","")
    Next

Next


 


 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110614 积分:562972 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/6/26 21:44:00 [只看该作者]

代码看不出什么问题

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/27 8:37:00 [只看该作者]

 具体实例发上来测试。

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/27 8:41:00 [只看该作者]

以下是引用jyh7081在2017/6/26 20:59:00的发言:

 

2、然后在当前表的AfterSelChange事件设置下列代码:

For Each r As Row In CurrentTable.Rows    '清除多余空格
    For Each c As Col In CurrentTable.Cols
            
            If r.IsNull(c.Name) =  False AndAlso c.IsString Then r(c.Name) = r(c.Name).replace(" ","")
    Next

Next

 

AfterSelChange 事件不能写太耗时的代码,你对全表进行操作,肯定慢。建议改成修改当前单元格的值就好了。


 回到顶部