从状态栏右侧对齐文本 [英] Allign text from right side on status bar

查看:128
本文介绍了从状态栏右侧对齐文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将左侧的一些文本和右侧的一些文本与vc ++中的状态栏对齐



我尝试了什么:



i在我添加了另一个文本的空格之后添加了左侧的空格但是当大文本空间不能一直显示时

can we allign some text from left side and some text from right side to the statusbar in vc++

What I have tried:

i have added the spaces from left side after spaces i have added another text but when big text coming space is not showing equal for all the time

推荐答案

您必须获取状态栏窗口的实际宽度,然后调整文本以适应。请参阅 CWnd :: GetWindowRect [ ^ ]和 CDC :: GetTextExtent(MFC) [ ^ ]。
You have to get the actual width of the status bar window and then adjust your text to fit. See CWnd::GetWindowRect[^] and CDC::GetTextExtent (MFC)[^].


您有两个选项,其中两个都需要从 CStatusBar类中派生一个类[ ^ ]或CMFCStatusBar类 [ ^ ]。



更改的类型m_wndStatusBar 在主框架窗口类头文件中派生类并包含派生类的头文件。如有必要,在主框架类的 OnCreate 中创建并初始化 m_wndStatusBar



第一种方法是覆盖 CStatusBar :: DrawItem resp。 CMFCStatusBar :: OnDrawPane 根据需要进行绘图。这要求传递的字符串包含一个用于将其拆分为左右部分的分隔符。



第二种方法是为右对齐添加一个窗格文本。此解决方案的缺点是,最左侧窗格不能再使用附加窗格的固定空间(假设使用样式 SBPS_STRETCH ,这使得此窗格占用剩余的窗格可用空间)。此解决方案的优点是您可以单独设置左右文本。但要显示右对齐文本,您还必须使用ownerdraw为该窗格。
You have two options where both requires deriving a class from the CStatusBar Class[^] or the CMFCStatusBar Class[^].

Change the type of m_wndStatusBar in your main frame window class header file to the derived class and include the header file of the derived class. If necessary create and initialise m_wndStatusBar in OnCreate of the main frame class.

The first method is overriding CStatusBar::DrawItem resp. CMFCStatusBar::OnDrawPane to do the drawing as required. This requires that the passed string contains a delimeter that is used to split it into the left and right parts.

The second method would be adding a pane for the right aligned text. The disadvantage of this solution is that the fixed space of the additional pane can't be used by the leftmost pane anymore (assuming using the style SBPS_STRETCH which lets this pane occupy the remaining available space). The advantage of this solution is that you can set the left and right text independently. But to show right aligned text you have to use ownerdraw for that pane too.


这篇关于从状态栏右侧对齐文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆