ChooseFont

 

Nachdem die beschreibbare Oberfläche von Userforms sich auf die Kopfzeile beschränkt, ist die Routine eher von geringem Nutzen.

Der Vollständigkeit halber dennoch hier demonstriert.

Die Funktionen und Deklarationen sind wieder in einem Modul zusammengefasst.

Eine Userform mit einem (zusätzlichen) Command Button (CommandButton2) anlegen und folgenden Code hinein kopieren:


Option Explicit

Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" _
   (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, _
   ByVal nCount As Long) As Long
Private Declare Function ExtTextOut Lib "gdi32" Alias "ExtTextOutA" _
   (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal wOptions As Long, _
   ByVal lpRect As Any, ByVal lpString As String, ByVal nCount As Long, lpDx As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
   
Private Sub CommandButton2_Click()
   Dim UF_hWnd As Long
   Dim UF_hDC As Long
   Dim strTest As String
   
   UF_hWnd = FindWindow("ThunderDFrame", UserForm1.Caption)
   UF_hDC = GetWindowDC(UF_hWnd)
   If CDlgChooseFont(UF_hWnd, UF_hDC) Then
      FontSetFont UF_hWnd
      strTest = "Font Test on Form"
      ExtTextOut UF_hDC, 0&, 0&, 0&, 0&, strTest, Len(strTest), ByVal 0&
   End If

End Sub


Um ChooseFont aufzurufen ist ein Device Context (DC) und somit ein Besitzer-Handle notwendig.

Das Ergebnis der Routine unter CommandButton2_Click sieht dann so aus ... (je nach Betriebssystem):

 

 

Zum Seitenanfang