在C ++ Builder XE中带有圆角的窗体周围的边框 [英] Border around a form with rounded corner in c++ builder XE

查看:215
本文介绍了在C ++ Builder XE中带有圆角的窗体周围的边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助以下代码,我制作了一个带有圆角的C ++ Builder XE表单

I have made a C++ Builder XE form with rounded corner with the help of the following code

BorderStyle = bsNone; 

void __fastcall TForm1::FormCreate(TObject *Sender)
{
     HRGN frmrgn;  

     frmrgn = CreateRoundRectRgn (0, 0, ClientWidth, ClientHeight,12,12);
     SetWindowRgn(Handle,frmrgn,true);
}

它看起来很酷,但是缺少边框,我尝试了很多事情,但没有得到很好的结果 所以请帮助我绘制RGB(96,96,96)颜色的边框

It looks cool but the border is missing, I tried many thing but not get good result so please help me to draw border of color RGB(96,96,96)

我想使整个表格可拖动.

And I want to make whole form dragable.

推荐答案

1.绘制深灰色边框

这很容易,具体取决于您希望边框看起来多么复杂.如果您只想要深灰色的轮廓,则可以使用线条和圆弧的组合来绘制轮廓,或者使用

1. Painting a dark grey border

This one's easy, depending on how complex you want the border to look. If you just want an outline in dark grey, either draw it using a combination of lines and arcs, or use the FrameRgn function to draw an outline around your region with a specific brush. Doing this is the best solution since you already have a region you've used to define the shape of the window.

但是,用于 说,在成功调用SetWindowRgn之后,系统拥有由区域句柄hRgn指定的区域.系统不会复制该区域.因此,您不应使用该区域句柄进行任何其他函数调用."您需要再次为paint方法创建区域.

However, the MSDN documentation for SetWindowRgn says, "After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy of the region. Thus, you should not make any further function calls with this region handle." You'll need to create your region again for the paint method.

您的绘画方法的一些代码:

Some code for your paint method:

HRGN hRegion = ::CreateRoundRectRgn (0, 0, ClientWidth, ClientHeight,12,12);
Canvas->Brush->Style = bsSolid;
Canvas->Brush->Color = RGB(96, 96, 96);
::FrameRgn(Canvas->Handle, hRegion, Canvas->Brush->Handle, 2, 2);
::DeleteObject(hRegion); // Don't leak a GDI object

2.使窗口可拖动而没有标题栏

简短的摘要是,您需要处理

2. Making the window draggable without its title bar

The short summary is that you need to handle the WM_NCHITTEST message. Windows sends this to see if the mouse is over the title bar ('NC' stands for 'non-client'; it's actually testing to see if it's anywhere in the non-client area, which can be any window border, not just the top one.) You can make your window draggable by saying 'yes, the mouse is in the caption right now' even when it isn't. Some code:

// In the 'protected' section of your form's class declaration
virtual void __fastcall WndProc(Messages::TMessage &Message);

// The implementation of that method:
void __fastcall TForm1::WndProc(Messages::TMessage& Message) {
  TForm::WndProc(Message); // inherited implementation
  if (Message.Msg == WM_NCHITTEST && Msg.Result == htClient) {
    Msg.Result = htCaption;
  }
}

您可以执行一些命中测试,以限制窗口的哪些部分显示为标题栏,以便创建自己的标题栏.

You can perform some hit testing of your own to restrict what parts of your window appear to be the title bar, in order to create a title bar of your own.

示例Delphi代码.

关于使用此消息的很好的文章注意/陷阱不要掉进去.

这篇关于在C ++ Builder XE中带有圆角的窗体周围的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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