Autres Centrer verticalement et a droite/gauche un texte dans label

chaelie2015

XLDnaute Accro
Bonsoir forum
Je souhaite Centrer verticalement et a droite un texte dans label et un autre label a gauche
Merci et bonne année
 

TooFatBoy

XLDnaute Barbatruc
Bonjour,

Je crois qu'il existe une astuce utilisant une image d'un pixel transparent.
Ceci dit, je ne saurais t'en dire plus. Jamais essayé.


[edit]
Lien vers une explication :
[/edit]
 
Dernière édition:

TooFatBoy

XLDnaute Barbatruc
Je viens de tester la méthode expliquée dans le lien de #2, et ça marche super bien pour mettre au centre du Label.
Capture_2022-12-31_23-02-10.png

Ci-joint, une image d'un pixel transparent. ;)
 

Pièces jointes

  • 1pixel-transparent.gif
    1pixel-transparent.gif
    842 bytes · Affichages: 38
Dernière édition:

patricktoulon

XLDnaute Barbatruc
bonjour
il y a une astuce (la même) sans recours a une image externe de 1 pixel
1 soit avec l'image d'un bouton dans une commandbar dynamique
2 soit avec l'image d'un bouton dans une commandbar existante
demo.gif


avec une new commandbar dynamique

avec la commandbar existante
VB:
'******************************************
'sujet: centrer verticalement le texte de la caption d'un label dans un userform
'       a l'aide d'un bouton dans une commandbarre temporaire et dynamique
'date:10/11/2021
'auteur: patricktoulon sur exceldownloads
'version:2.1 (2021) sans créeation de commandbars mais en utilisant la commandbars (1)
''******************************************

Private Sub CommandButton1_Click()
   Call centrer_le_text(Label1)
End Sub

Sub centrer_le_text(obj As msforms.Label)
    Dim bout As CommandBarControl, shap As Shape
    Set bout = CommandBars(1).Controls.Add(Type:=msoControlButton)
    Set shap = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 0, 0, 1, 1)
    With shap: .Line.Visible = msoFalse: .Fill.Visible = msoFalse: .CopyPicture: .Delete: End With 'copypicture=copie en WMF(garde la transparence)
    bout.PasteFace
    With obj
        .Picture = bout.Picture
        .PicturePosition = fmPicturePositionCenter
        .TextAlign = 2
    End With
    CommandBars(1).Reset
End Sub

ci joint la version avec commandbar existante
 

Pièces jointes

  • centrer verticalement le texte d'un label by patricktoulon V 2.1 .xlsm
    25 KB · Affichages: 10

job75

XLDnaute Barbatruc
Bonsoir à tous,

Avec un Label dans un Frame on obtient le même résultat :
VB:
Private Sub UserForm_Initialize()
With Label1
    .Width = 1000
    .AutoSize = True
    .AutoSize = False
    .Top = (Frame1.Height - .Height) / 2 - 5
    .Left = (Frame1.Width - .Width) / 2
End With
End Sub
A+
 

Pièces jointes

  • Label et Frame.xlsm
    24.3 KB · Affichages: 11

Discussions similaires

Statistiques des forums

Discussions
312 209
Messages
2 086 275
Membres
103 170
dernier inscrit
HASSEN@45