简体   繁体   English

我们可以在C ++ MFC应用程序的对话框中的控件的所有边上都有边框吗?

[英]Can we have border on all sides for a control in a dialog in a C++ MFC application?

Generally if u add any control Eg: a rich text, the left and the top portion of the control will have thick borders.But the bottom and the right side of the control do not have borders. 通常,如果您添加任何控件,例如富文本,则控件的左侧和顶部将具有粗边框,但是控件的底部和右侧则没有边框。 Is there any way to add borders to all sides. 有没有办法向所有边添加边框。 The border property has only true or false option, i don't want to take off the borders but have the borders unique on all sides. border属性只有true或false选项,我不想脱下边框,但边框在所有面上都是唯一的。 Please let me know if there are any ways. 有什么办法请告诉我。

Sorry i was unable add images earlier as i didn't have enough reputations. 抱歉,我没有足够的声誉,因此无法较早添加图像。 Please note the below image where the left and top borders of the rich text box are thick but the right and the bottom part and plain. 请注意下图,其中富文本框的左侧和顶部边框较粗,而右侧和底部则较粗。 I want all sides with borders even. 我甚至希望所有边界都有边界。

在此处输入图片说明

Anyways?. 无论如何?。

I've answered a very similar (may be duplicate) question recently. 我最近回答了一个非常相似(可能重复)的问题。 You can check “Want to show colored box around Richedit control in MFC at runtime” . 您可以选中“在运行时希望在MFC中的Richedit控件周围显示彩色框” That question asked for a yellow colored border. 这个问题要求使用黄色边框。 To answer your question, it requires you to derive your own class from CRichEditCtrl, override OnNcPaint , and a simple modification of the sample ( OnNcPaint ) code I presented in that post: 要回答您的问题,它要求您从CRichEditCtrl派生您自己的类,重写OnNcPaint ,并对我在该帖子中介绍的示例代码( OnNcPaint )进行简单的修改:

CPen pen;
COLORREF color = ::GetSysColor(COLOR_3DDKSHADOW);
pen.CreatePen(PS_SOLID, 5, color);
dc.SelectObject(pen);
dc.Rectangle(&rect);

The above would result in... 以上将导致...

在此处输入图片说明

Note: You can adjust the border color by changing the parameter of ::GetSyscolor 注意:您可以通过更改:: GetSyscolor的参数来调整边框颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM