【问题标题】:How to set the top/bottom margins of a Win32 richedit如何设置 Win32 Richedit 的顶部/底部边距
【发布时间】:2017-01-04 23:43:27
【问题描述】:

我们可以使用EM_SETMARGINS 消息来设置RichEdit 控件的左右边距。但我不知道如何设置顶部/底部边距。有人知道吗?谢谢。

【问题讨论】:

    标签: c++ windows winapi controls


    【解决方案1】:

    使用EM_GETRECT/EM_SETRECT消息组合修改所有边距:

            RECT rc;
            // Get the current control rectangle
            SendMessage(hWndRichEdit, EM_GETRECT, 0, (LPARAM)&rc);
            rc.left += 20; // increase the left margin 
            rc.top += 20; // increase the top margin
            rc.right -= 20; // decrease the right margin
            rc.bottom -= 20; // decrease the bottom margin (rectangle)
            // Set the rectangle
            SendMessage(hWndRichEdit, EM_SETRECT, 0, (LPARAM)&rc);
    

    生成的控件具有所有四个边距:

    更新:根据下面的Barmak ShemiraniIInspectable cmets,您可以使用GetClientRect 函数来获取当前矩形和InflateRect 函数来操作矩形/边距尺寸。

    【讨论】:

    • 您可能希望使用GetClientRect 而不是EM_GETRECT。因为EM_GETRECT 返回当前边距。例如,左/上边距可以返回为 1 和 1。而 GetClientRect 始终返回 0 和 0。
    • 鲜为人知的是,Windows API 提供了许多rectangle functions。可以更改此答案中的代码以利用 InflateRect,例如:InflateRect(rc, -20, -20);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    相关资源
    最近更新 更多