zoukankan      html  css  js  c++  java
  • 设置文本框的九种对齐方式(左上,中上,右上,左中,中中,右中,左下,中下,右下)

    'Add a commandbutton and a textbox( multiline=true) and copy the following codes to form1:

    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 Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Const EM_SETRECT As Long = &HB3
    Private Const EM_SETRECTNP As Long = &HB4
    Dim i As Integer

    Sub alignment(ByVal txtbox As TextBox, ByVal index As Integer, ByVal txt As String)
    Dim r As RECT, atop As Long, h As Long
    SendMessage txtbox.hwnd, EM_GETRECT, 0, r
    Me.FontName = txtbox.FontName
    Me.FontSize = txtbox.FontSize
    Me.FontBold = txtbox.FontBold
    txtbox.Text = txt
    h = Me.TextHeight("H") / Screen.TwipsPerPixelY
    If index / 3 = 0 Then atop = 0
    If index / 3 = 1 Then atop = r.Bottom / 2 - h
    If index / 3 = 2 Then atop = r.Bottom - h
    r.Top = atop
    Debug.Print r.Top; r.Bottom
    txtbox.alignment = Array(vbLeftJustify, vbCenter, vbRightJustify)(index Mod 3)
    SendMessage txtbox.hwnd, EM_SETRECTNP, 0, r
    txtbox.Refresh
    End Sub

    Private Sub Command1_Click()
    Dim x() As String
    x = Split("左上,中上,右上,左中,中中,右中,左下,中下,右下", ",")
    alignment Text1, i, x(i)
    i = (i + 1) Mod 9
    End Sub

  • 相关阅读:
    洛谷 P2023 BZOJ 1798 [AHOI2009]维护序列
    洛谷 P1640 BZOJ 1854 [SCOI2010]连续攻击游戏
    洛谷 P4300 BZOJ 1266 [AHOI2006]上学路线route
    洛谷 P1886 滑动窗口
    洛谷 P1063 能量项链
    洛谷 P1156 垃圾陷阱
    洛谷 P1854 花店橱窗布置
    洛谷 P3800 Power收集
    洛谷 P2285 BZOJ 1207 [HNOI2004]打鼹鼠
    day31
  • 原文地址:https://www.cnblogs.com/fengju/p/6336332.html
Copyright © 2011-2022 走看看