【问题标题】:Write formatted text(printf style) to a MFC CEdit control, which would display the formatted text in a EditControl?将格式化文本(printf 样式)写入 MFC CEdit 控件,这将在 EditControl 中显示格式化文本?
【发布时间】:2010-03-22 12:40:40
【问题描述】:

我需要在 CEdit 控制的编辑控制框中显示文本以及变量值。我该怎么做 ?目前我正在使用 SetWindowText(),但这只需要一个字符串...如何获取格式化字符串以显示在编辑控件中?

示例:printf("The answer is %d\n",ans) -> 如何在编辑控件中打印相同的消息?

【问题讨论】:

    标签: mfc formatting cedit editcontrol


    【解决方案1】:

    使用 CString 的 Format 成员。

    CString text;
    text.Format(_T("The answer is %d\n"), ans);
    edit.SetWindowText(text);
    

    【讨论】:

    • 和/或您可以从 CEdit 派生您自己的类,并在一次调用中添加一个方法来执行此操作。 M.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多