找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 154|回复: 3

最简化unicode Label控件,没有HWND

[复制链接]
发表于 2025-10-28 22:06:54 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
最简化unicode Label控件,没有HWND!!!!傻瓜式

1.JPG

VERSION 5.00
Begin VB.UserControl ULabel
   AutoRedraw      =   -1  'True
   BackColor       =   &H00FFFFFF&
   ClientHeight    =   3600
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   4800
   FillStyle       =   0  'Solid
   BeginProperty Font
      Name            =   "宋体"
      Size            =   9
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   ForeColor       =   &H00000000&
   ScaleHeight     =   240
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   320
End
Attribute VB_Name = "ULabel"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Type RECT ' 定义矩形区域结构
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function DrawText Lib "user32" Alias "DrawTextW" (ByVal hDC As Long, ByVal lpStr As Long, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Const DT_CENTER As Long = &H1
Private Const DT_SINGLELINE As Long = &H2
Private Const DT_RIGHT As Long = &H6
Private Const DT_LEFT As Long = &H0



Private m_Text As String, m_Align As Integer



Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
      
    With PropBag
         Caption = .ReadProperty("Caption", m_Text)
         BackColor = .ReadProperty("BackColor", UserControl.BackColor)
         ForeColor = .ReadProperty("ForeColor", UserControl.ForeColor)
         Set Font = .ReadProperty("Font", UserControl.Font)
         Visible = .ReadProperty("Visible", UserControl.BackStyle)
         TextAlign = .ReadProperty("TextAlign", m_Align)
    End With
End Sub



Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    With PropBag
         .WriteProperty "Caption", m_Text
         .WriteProperty "BackColor", UserControl.BackColor
         .WriteProperty "ForeColor", UserControl.ForeColor
         .WriteProperty "Font", UserControl.Font
         .WriteProperty "Visible", UserControl.BackStyle
         .WriteProperty "TextAlign", m_Align
    End With
End Sub

Public Property Get Caption() As String
     Caption = m_Text

End Property

Public Property Let Caption(ByVal NewStr As String)
    m_Text = NewStr
  UserControl.Cls
Dim lRect As RECT
   With lRect
     .Left = 0
     .Top = 0
     .Right = UserControl.ScaleWidth
     .Bottom = UserControl.ScaleHeight
   End With
   Select Case m_Align
          Case 0
               DrawText UserControl.hDC, StrPtr(m_Text), Len(m_Text), lRect, DT_LEFT ' DT_CENTER Or DT_SINGLELINE
          Case 1
               DrawText UserControl.hDC, StrPtr(m_Text), Len(m_Text), lRect, DT_CENTER
          Case 2
               DrawText UserControl.hDC, StrPtr(m_Text), Len(m_Text), lRect, DT_RIGHT
   End Select
  PropertyChanged "Caption"
End Property


Public Property Let BackColor(ByVal newColor As OLE_COLOR)
    UserControl.BackColor = newColor
    PropertyChanged "BackColor"
End Property

Public Property Get BackColor() As OLE_COLOR
    BackColor = UserControl.BackColor
End Property

Public Property Let ForeColor(ByVal newColor As OLE_COLOR)
   ' SendMessageW hDC, &H6, newColor, 0
    UserControl.ForeColor = newColor
    PropertyChanged "ForeColor"
End Property


Public Property Get ForeColor() As OLE_COLOR
    ForeColor = UserControl.ForeColor
End Property


Public Property Get Visible() As Integer
     Visible = UserControl.BackStyle
End Property



Public Property Let Visible(ByVal NewStyle As Integer)
    UserControl.BackStyle = NewStyle
    PropertyChanged "BackStyle"
End Property



Public Property Get Font() As Font
  Set Font = UserControl.Font
End Property



Public Property Set Font(ByVal NewFont As StdFont)
   Set UserControl.Font = NewFont
   PropertyChanged "Font"
End Property



Public Property Let TextAlign(ByVal NewStyle As Integer)
    m_Align = NewStyle
    PropertyChanged "TextAlign"
End Property

Public Property Get TextAlign() As Integer
    TextAlign = m_Align
End Property





















回复

使用道具 举报

 楼主| 发表于 2025-10-30 20:08:34 | 显示全部楼层

超级简化的unicode label 控件,没有句柄(hWnd)
回复 赞! 靠!

使用道具 举报

发表于 2025-11-6 16:41:57 | 显示全部楼层
感谢大佬分享~~
回复 赞! 靠!

使用道具 举报

 楼主| 发表于 2025-11-13 09:03:29 | 显示全部楼层
布客气
回复

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2025-11-25 12:51 , Processed in 0.036237 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表