时间:2021-05-20
本文实例代码可以实现让VB的TextBox文本框垂直居中显示效果。此处需要注意:Form_Load()窗体代码中的多行属性设置必须为真,即Text1.MultiLine = True,该属性为只读属性,请在设计时修改,换行会被之后的代码屏蔽,不想屏蔽可自行修改,调用此函数就好了。
具体的功能代码如下:
'================================================================================'| 模 块 名 | TextBoxMiddle'| 说 明 | 文本框居中显示'=================================================================================Option ExplicitPrivate Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePrivate Declare Function SendMessage Lib "user32 " Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPrivate Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const EM_GETRECT = &HB2Private Const EM_SETRECTNP = &HB4Private Const GWL_WNDPROC = (-4)Private Const WM_CHAR = &H102Private Const WM_PASTE As Long = &H302Private prevWndProc As LongPublic ClipText As StringPublic Sub DisableAbility(TargetTextBox As TextBox) prevWndProc = GetWindowLong(TargetTextBox.hwnd, GWL_WNDPROC) SetWindowLong TargetTextBox.hwnd, GWL_WNDPROC, AddressOf WndProcEnd SubPrivate Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Dim Temp As String Select Case Msg Case WM_CHAR If wParam <> 13 Then WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam) Case WM_PASTE ClipText = Clipboard.GetText Temp = Replace(ClipText, Chr(10), "") Temp = Replace(Temp, Chr(13), "") Clipboard.Clear Clipboard.SetText Temp WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam) Clipboard.Clear Clipboard.SetText ClipText Case Else WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam) End SelectEnd FunctionSub VerMiddleText(mForm As form, mText As TextBox) If mText.MultiLine = False Then Exit Sub Dim rc As RECT, tmpTop As Long, tmpBot As Long SendMessage mText.hwnd, EM_GETRECT, 0, rc With mForm.Font .Name = mText.Font.Name .Size = mText.Font.Size .Bold = mText.Font.Bold End With tmpTop = ((rc.Bottom - rc.Top) - _ (mText.Parent.TextHeight("H ") \ Screen.TwipsPerPixelY)) \ 2 + 2 tmpBot = ((rc.Bottom - rc.Top) + _ (mText.Parent.TextHeight("H ") \ Screen.TwipsPerPixelY)) \ 2 + 2 rc.Top = tmpTop rc.Bottom = tmpBot mText.Alignment = vbCenter SendMessage mText.hwnd, EM_SETRECTNP, 0&, rc mText.Refresh DisableAbility mTextEnd Sub'///////////////////////////////////////////////////////'以下为窗体代码'///////////////////////////////////////////////////////Private Sub Form_Load() '================注意!!!================= '多行属性必须为真,暨Text1.MultiLine = True '该属性为只读属性,请在设计时修改 '换行会被之后的代码屏蔽,不想屏蔽可自行修改 '=========================================== '调用此函数就好了 VerMiddleText Me, Text1 Caption = Len(Text1)End Sub声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
word文档字体竖排居中的方法: 1、打开一份空白的word文档。 2、点击插入选项中的文本框。 3、选择插入简单垂直文本框。 4、文本框中输入文字。
文本框里的字居中显示的方法如下: 1、设置上下居中需要单击页面布局选项卡右下角的按钮; 2、弹出页面设置对话框,选择版式选项卡,在垂直对齐方式处选择居中即可
本文以实例形式展示了C#与js实现去除textbox文本框里面重复记录的方法!具体方法如下:现有如下问题:页面有一个textbox文本框(是多行的),比如我在文
以word为例,竖向文本框里的字居中方法: 1、让竖排文本框中的文字在水平方向上居中对齐。首先,右键竖排文本框的边框线,在弹出的右键菜单中选择“设置文本框格式
以word2007为例,word文本框文字居中的方法是: 1、鼠标点击选中要居中文字的文本框,再将鼠标指针指向文本框的边框。当鼠标指针变成图中所示形状后,点击