IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

[MFC] Centrer du texte dans une RichEdit


Sujet :

MFC

  1. #1
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut [MFC] Centrer du texte dans une RichEdit
    Slt,

    je cherche à ajouter du texte centré dans un RichEdit, mais jvois pas comment faire,

    pour ajouoter en gras, j'utilise :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    void DlListing::AppendTextToRecap(CString sTxt, BOOL bBold)
    {
    	CHARFORMAT Cfm;
     
    	m_rRecapitulatif.GetSelectionCharFormat(Cfm);
     
    	Cfm.cbSize = sizeof(CHARFORMAT);
    	Cfm.dwMask = CFM_BOLD;
    	if (bBold == TRUE)
    		Cfm.dwEffects |= CFE_BOLD; 
    	else
    		Cfm.dwEffects &= !CFE_BOLD; 
     
    	m_rRecapitulatif.SetSelectionCharFormat(Cfm); 
     
    	long int iTextLength = m_rRecapitulatif.GetTextLength();
    	m_rRecapitulatif.SetSel(iTextLength,iTextLength);
     
    	m_rRecapitulatif.ReplaceSel((LPCTSTR)(sTxt + "\r\n"));
     
    }
    Mais apparemment CHARFORMAT ne contient pas d'indication sur l'alignement, à moins que jl'ai loupé....

  2. #2
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    C'est une propriété gérée par PARAFORMAT :

    Citation Envoyé par MSDN
    In Microsoft Rich Edit 2.0, the PARAFORMAT2 structure is a Rich Edit 2.0 extension of the PARAFORMAT structure. Rich Edit 2.0 allows you to use either structure with EM_GETPARAFORMAT and EM_SETPARAFORMAT.


    Syntax

    typedef struct _paraformat {
    UINT cbSize;
    DWORD dwMask;
    WORD wNumbering;
    WORD wReserved;
    LONG dxStartIndent;
    LONG dxRightIndent;
    LONG dxOffset;
    WORD wAlignment;
    SHORT cTabCount;
    LONG rgxTabs[MAX_TAB_STOPS];
    } PARAFORMAT;
    Members

    dwMask
    Members containing valid information or attributes to set. This parameter can be none or a combination of the following values. If both PFM_STARTINDENT and PFM_OFFSETINDENT are specified, PFM_STARTINDENT takes precedence.
    PFM_ALIGNMENT
    The wAlignment member is valid.

    PFM_NUMBERING
    The wNumbering member is valid.
    PFM_OFFSET
    The dxOffset member is valid.
    PFM_OFFSETINDENT
    The dxStartIndent member is valid and specifies a relative value.
    PFM_RIGHTINDENT
    The dxRightIndent member is valid.
    PFM_RTLPARA
    Rich Edit 2.0: The wEffects member is valid
    PFM_STARTINDENT
    The dxStartIndent member is valid.
    PFM_TABSTOPS
    The cTabStobs and rgxTabStops members are valid.

    wAlignment
    Value specifying the paragraph alignment. This member can be one of the following values.
    PFA_CENTER
    Paragraphs are centered.
    PFA_LEFT
    Paragraphs are aligned with the left margin.
    PFA_RIGHT
    Paragraphs are aligned with the right margin.

  3. #3
    Membre confirmé

    Profil pro
    Inscrit en
    Décembre 2003
    Messages
    650
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Décembre 2003
    Messages : 650
    Points : 546
    Points
    546
    Par défaut
    Merci

    Mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    	PARAFORMAT pf;
    	pf.cbSize = sizeof(PARAFORMAT);
    	pf.dwMask = PFM_ALIGNMENT;
    	if (bCentered)
    		pf.wAlignment = PFA_CENTER;
    	else
    		pf.wAlignment = PFA_LEFT;		
     
    	m_rRichFiche.SetParaFormat(pf);

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Centrer un texte dans une page
    Par Samanta dans le forum Mise en forme
    Réponses: 5
    Dernier message: 20/09/2010, 22h30
  2. [ImageMagick] Centrer du texte dans une image
    Par Ministar dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 20/09/2007, 18h44
  3. Centrer le texte dans une Combobox
    Par mouloudéen dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 13/04/2007, 09h06
  4. Centrer le texte dans une TStringGrid
    Par Rodrigue dans le forum C++Builder
    Réponses: 2
    Dernier message: 10/06/2004, 11h01
  5. Réponses: 2
    Dernier message: 10/06/2002, 11h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo