VB의 TextBox 텍스트 상자를 중앙에 수직으로 표시하는 방법
구체적인 기능 코드는 다음과 같다.
'================================================================================
'| | TextBoxMiddle
'| |
'=================================================================================
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private 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 Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const EM_GETRECT = &HB2
Private Const EM_SETRECTNP = &HB4
Private Const GWL_WNDPROC = (-4)
Private Const WM_CHAR = &H102
Private Const WM_PASTE As Long = &H302
Private prevWndProc As Long
Public ClipText As String
Public Sub DisableAbility(TargetTextBox As TextBox)
prevWndProc = GetWindowLong(TargetTextBox.hwnd, GWL_WNDPROC)
SetWindowLong TargetTextBox.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
Private 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 Select
End Function
Sub 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 mText
End Sub
'///////////////////////////////////////////////////////
'
'///////////////////////////////////////////////////////
Private Sub Form_Load()
'================ !!!=================
' , Text1.MultiLine = True
' ,
' ,
'===========================================
'
VerMiddleText Me, Text1
Caption = Len(Text1)
End Sub
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
SendKeys.Send()에서 확인란을 확인하는 Wazap그대로 타이틀대로 SendKeys.Send() 메소드를 사용해 체크 박스를 체크하는 방법이 됩니다. 업무에서 사용하고 있는 Windows Form의 어플리케이션의 조작을 자동화하고 싶다고 하는 이야기가 있어, 여러 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.