RichTextBox设置行高后,字不会垂直居中,而是在下面。如何解决?

vansoft 2006-11-01 04:35:25
RichTextBox通过API可以设置行高。但文字不能垂直居中。

OFFICE中的WORD可以。设置行高后文字在行内垂直居中。
...全文
1113 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dunzip 2006-11-02
  • 打赏
  • 举报
回复
楼上的应该可以实现

box.SelLength = length
box.SelCharOffset = ScaleY(offset, vbPoints, vbTwips)

MSDN解析:

返回或设置一个值,由它确定 RichTextBox 控件中的文本是出现在基线上(正常状态),还是作为上标出现在基线之上或作为下标出现在基线之下
zq972 2006-11-02
  • 打赏
  • 举报
回复
这样试一下
Private Sub Form_Load()
Dim pf As PARAFORMAT2
With pf
.cbSize = LenB(pf)
pf.dwMask = PFM_LINESPACING
.bLineSpacingRule = 4
.dyLineSpacing = 40 * 15
End With
Dim i As Long
i = SendMessage(RichTextBox1.hwnd, EM_SETPARAFORMAT, 0, ByVal VarPtr(pf))
OffsetRichText RichTextBox1, 0, Len(RichTextBox1.Text), 5
End Sub

Private Sub OffsetRichText(box As RichTextBox, start As Integer, length As Integer, offset As Integer)
box.SelStart = start
box.SelLength = length
box.SelCharOffset = ScaleY(offset, vbPoints, vbTwips)
box.SelStart = 0
box.SelLength = 0
End Sub
vansoft 2006-11-02
  • 打赏
  • 举报
回复
.dyLineSpacing = 40 * 15

我调整以上的值,可以做到在行内垂直居中。

现在的问题是这样的:
在WORD中,有一段图文混排的内容,全是在行内垂直居中的,
把他选中,复制粘贴到我程序的RichTextBox内,他全部变成在行内靠下了。

图片的高度是行高,字全都在下面。
这个问题怎么解决。
vansoft 2006-11-01
  • 打赏
  • 举报
回复
楼上的高人,这相当于word中的段前段后加多少。

我需要的是字在行里垂直居中,跟段前段后多少没关系。
Dunzip 2006-11-01
  • 打赏
  • 举报
回复
这个简单,把我的代码代替你的Form_Load()就可以了

这可是专利哦,要加分哦
--------------

Private Sub Form_Load()
Dim pf As PARAFORMAT2
With pf
.cbSize = LenB(pf)
.dwMask = PFM_ALIGNMENT Or PFM_LINESPACING Or PFM_SPACEAFTER '加入对齐方式
.wAlignment = PFA_LEFT '这个是控制水平左中右对齐
.bLineSpacingRule = 4
.dySpaceBefore = 30 * 15 '这个是控制在垂直的上方加多少行
.dyLineSpacing = 40 * 15
.dySpaceAfter = 30 * 15 '这个是控制在垂直的下方加多少行


End With
Dim i As Long
i = SendMessage(RichTextBox1.hwnd, EM_SETPARAFORMAT, 0, ByVal VarPtr(pf))
End Sub






vansoft 2006-11-01
  • 打赏
  • 举报
回复
Option Explicit

Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any)

Private Const WM_USER& = &H400
Private Const EM_GETPARAFORMAT = (WM_USER + 61)
Private Const EM_SETPARAFORMAT = (WM_USER + 71)
Private Const MAX_TAB_STOPS = 32&

Private Type PARAFORMAT2
'Los primeros campos coinciden con PARAFORMAT y se usan igual
cbSize As Integer
wPad1 As Integer
dwMask As Long
wNumbering As Integer
wEffects As Integer 'No usado en PARAFORMAT
dxStartIndent As Long
dxRightIndent As Long
dxOffset As Long
wAlignment As Integer
cTabCount As Integer
lTabStops(0 To MAX_TAB_STOPS - 1) As Long
' Desde aquí lo a?adido por PARAFORMAT2
dySpaceBefore As Long '/* Vertical spacing before para */
dySpaceAfter As Long '/* Vertical spacing after para */
dyLineSpacing As Long '/* Line spacing depending on Rule */
sStyle As Integer ' /* Style handle */
bLineSpacingRule As Byte '/* Rule for line spacing (see tom.doc) */
bOutlineLevel As Byte '/* Outline Level*/'antes bCRC As Byte
wShadingWeight As Integer '/* Shading in hundredths of a per cent */
wShadingStyle As Integer '/* Byte 0: style, nib 2: cfpat, 3: cbpat*/
wNumberingStart As Integer '/* Starting value for numbering */
wNumberingStyle As Integer ' /* Alignment, Roman/Arabic, (), ), ., etc.*/
wNumberingTab As Integer '/* Space bet 1st indent and 1st-line text*/
wBorderSpace As Integer ' /* Border-text spaces (nbl/bdr in pts) */
wBorderWidth As Integer '/* Pen widths (nbl/bdr in half twips) */
wBorders As Integer '/* Border styles (nibble/border) */
End Type

' /* PARAFORMAT mask values */
Private Const PFM_STARTINDENT = &H1&
Private Const PFM_RIGHTINDENT = &H2&
Private Const PFM_OFFSET = &H4&
Private Const PFM_ALIGNMENT = &H8&
Private Const PFM_TABSTOPS = &H10&
Private Const PFM_NUMBERING = &H20&
Private Const PFM_OFFSETINDENT = &H80000000

' /* PARAFORMAT numbering options */
Private Const PFN_BULLET = &H1&

' /* PARAFORMAT alignment options */
Private Const PFA_LEFT = &H1&
Private Const PFA_RIGHT = &H2&
Private Const PFA_CENTER = &H3&

'/* PARAFORMAT 2.0 masks */
Private Const PFM_SPACEBEFORE = &H40&
Private Const PFM_SPACEAFTER = &H80&
Private Const PFM_LINESPACING = &H100&
Private Const PFM_STYLE = &H400&
Private Const PFM_NUMBERINGSTYLE = &H2000& ' /* RE 3.0 */
Private Const PFM_NUMBERINGTAB = &H4000& ' /* RE 3.0 */
Private Const PFM_NUMBERINGSTART = &H8000& ' /* RE 3.0 */
Private Const PFM_TABLE = &HC0000000 ' /* RE 3.0 */
'// The following three properties are read only
Private Const PFM_COLLAPSED = &H1000000 '/* RE 3.0 */
Private Const PFM_OUTLINELEVEL = &H2000000 '/* RE 3.0 */
Private Const PFM_BOX = &H4000000 '/* RE 3.0 */

'/* PARAFORMAT2 wNumbering options (see also PFN_BULLET) */
Private Const PFN_ARABIC = 2 '/* tomListNumberAsArabic: 0, 1, 2, ...*/
Private Const PFN_LCLETTER = 3 '/* tomListNumberAsLCLetter: a, b, c, ...*/
Private Const PFN_UCLETTER = 4 '/* tomListNumberAsUCLetter: A, B, C, ...*/
Private Const PFN_LCROMAN = 5 '/* tomListNumberAsLCRoman: i, ii, iii, ...*/
Private Const PFN_UCROMAN = 6 '/* tomListNumberAsUCRoman: I, II, III, ...*/

'/* PARAFORMAT2 wNumberingStyle options */
Private Const PFNS_PAREN = &H0 '/* default, e.g., 1) */
Private Const PFNS_PARENS = &H100 '/* tomListParentheses/256, e.g., (1) */
Private Const PFNS_PERIOD = &H200 '/* tomListPeriod/256, e.g., 1. */
Private Const PFNS_PLAIN = &H300 '/* tomListPlain/256, e.g., 1 */
Private Const PFNS_NONUMBER = &H400 '/* Used for continuation w/o number

Private Sub Form_Load()
Dim pf As PARAFORMAT2
With pf
.cbSize = LenB(pf)
pf.dwMask = PFM_LINESPACING
.bLineSpacingRule = 4
.dyLineSpacing = 40 * 15
End With
Dim i As Long
i = SendMessage(RichTextBox1.hwnd, EM_SETPARAFORMAT, 0, ByVal VarPtr(pf))
End Sub
happy_sea 2006-11-01
  • 打赏
  • 举报
回复
把设置行高的代码发上来看看?

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧