mfc ribbon动态修改字符_如何動態更改CMFCRibbonLabel的文本

My CMDIFrameWndEx derived main frame window uses a CMFCRibbonStatusBar to which I add a CMFCRibbonLabel. I'd like to change the text of this label at runtime:

我的CMDIFrameWndEx派生主框架窗口使用CMFCRibbonStatusBar,我添加了一個CMFCRibbonLabel。我想在運行時更改此標簽的文本:

m_pLabel->SetText(description);

m_pLabel->Redraw();

It only updates the text but not the rectangle in which to draw it. So if the original text was too short, the new string won't be visible completely.

它只更新文本,但不更新繪制它的矩形。因此,如果原始文本太短,則新字符串將不會完全可見。

How do I get it to resize correctly?

如何讓它正確調整大小?

3 个解决方案

#1

You don't need to remove and re-add. Just call this:

您無需刪除和重新添加。請致電:

m_wndStatusBar.ForceRecalcLayout();

#2

use the CMFCRibbonStatusBarPane::SetAlmostLargeText function

使用CMFCRibbonStatusBarPane :: SetAlmostLargeText函數

#3

Answering my own question again...

再次回答我自己的問題......

I worked around the issue by adding and removing the label instead of trying to change the text.

我通過添加和刪除標簽而不是嘗試更改文本來解決此問題。

Code for adding the 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();

Note that I'm setting an ID so I can later call CMFCRibbonStatusBar::RemoveElement() with that ID. The calls to RecalcLayout() and RedrawWindow() are needed to make the changes visible.

請注意,我正在設置ID,以便稍后可以使用該ID調用CMFCRibbonStatusBar :: RemoveElement()。需要調用RecalcLayout()和RedrawWindow()才能使更改可見。

Code for removing the label:

if(m_wndStatusBar.RemoveElement(ID_MYLABEL))

{

m_wndStatusBar.RecalcLayout();

m_wndStatusBar.RedrawWindow();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值