How to dynamically change the text of CMFCRibbonLabel

My CMDIFrameWndEx

displayed window is the main frame uses CMFCRibbonStatusBar

, to which I add CMFCRibbonLabel

.

I would like to change the text of this shortcut at runtime:

m_pLabel->SetText(description);
m_pLabel->Redraw();

      

It only updates the text, not the rectangle in which it can be drawn. Therefore, if the original text was too short, the entire new line will not be visible.

How do I get it to resize correctly?

+1


a source to share


3 answers


Answering my question again ...

I worked around the problem by adding and removing a shortcut instead of trying to change the text.

Code for adding a label:

CMFCRibbonLabel* pLabel = new CMFCRibbonLabel(description);
pLabel->SetID(ID_MYLABEL); // ID is 0 by default

m_wndStatusBar.AddDynamicElement(pLabel);
m_wndStatusBar.RecalcLayout();
m_wndStatusBar.RedrawWindow();

      



Please note that I am setting an ID so I can call CMFCRibbonStatusBar::RemoveElement()

with that ID later . In order for the changes to be visible, calls RecalcLayout()

and are required RedrawWindow()

.

Code to remove the label:

if(m_wndStatusBar.RemoveElement(ID_MYLABEL))
{
    m_wndStatusBar.RecalcLayout();
    m_wndStatusBar.RedrawWindow();
}

      

0


a source


You don't need to delete and re-add. Just call it:



m_wndStatusBar.ForceRecalcLayout();

      

+4


a source


use CMFCRibbonStatusBarPane :: SetAlmostLargeText function

+1


a source







All Articles