 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Simon Elliott Guest
|
Posted: Tue Jun 14, 2005 7:06 am Post subject: TCanvas RoundRect method looks odd |
|
|
I'm trying to draw a rectangular border with rounded corners on a form
by using TPaintBox. This is what's in the ONPaint event handler:
myPaintBox->Canvas->Brush->Style = bsClear;
myPaintBox->Canvas->RoundRect(0, 0, myPaintBox->Width,
myPaintBox->Height, 40, 40);
The problem is that the corners of the round rectangle look jagged and
pixelated. What can I do about this?
--
Simon Elliott http://www.ctsn.co.uk
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Jun 14, 2005 10:14 am Post subject: Re: TCanvas RoundRect method looks odd |
|
|
"Simon Elliott" <Simon at ctsn.co.uk> wrote:
| Quote: |
[...] What can I do about this?
|
I never did like the TCanvas methods. Look at the win32 API
CreateRoundRectRgn.
~ JD
|
|
| Back to top |
|
 |
Simon Elliott Guest
|
Posted: Tue Jun 14, 2005 10:53 am Post subject: Re: TCanvas RoundRect method looks odd |
|
|
On 14/06/2005, JD wrote:
| Quote: |
[...] What can I do about this?
I never did like the TCanvas methods. Look at the win32 API
CreateRoundRectRgn.
|
I did have a quick play with this but couldn't get it to display
anything. Where would I call These functions - I can't use the form's
OnPaint because the controls then get written over the top.
--
Simon Elliott http://www.ctsn.co.uk
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Jun 14, 2005 11:55 am Post subject: Re: TCanvas RoundRect method looks odd |
|
|
"Simon Elliott" <Simon at ctsn.co.uk> wrote:
| Quote: |
Where would I call These functions
|
If you're trying to create an immediate effect with the form,
put it in the constructor.
How it works is that you create the HRGN and then you set the
region to the desired control. That's it. Window's handles
everything else (except clean-up in case of error).
int FCurve = 5;
HRGN hRegion = ::CreateRoundRectRgn( 0, 0, Width, Height, FCurve, FCurve );
if( hRegion )
{
// After a successful call to SetWindowRgn, the
// operating system owns the region specified by
// the region handle hRgn.
if( !::SetWindowRgn(Handle, hRegion, true) )
{
::DeleteObject( hRegion );
}
}
That will round the corners of the form just like XP does.
~ JD
|
|
| Back to top |
|
 |
Simon Elliott Guest
|
Posted: Tue Jun 14, 2005 12:01 pm Post subject: Re: TCanvas RoundRect method looks odd |
|
|
On 14/06/2005, JD wrote:
| Quote: |
Where would I call These functions
If you're trying to create an immediate effect with the form,
put it in the constructor.
How it works is that you create the HRGN and then you set the
region to the desired control. That's it. Window's handles
everything else (except clean-up in case of error).
int FCurve = 5;
HRGN hRegion = ::CreateRoundRectRgn( 0, 0, Width, Height, FCurve,
FCurve ); if( hRegion )
{
// After a successful call to SetWindowRgn, the
// operating system owns the region specified by
// the region handle hRgn.
if( !::SetWindowRgn(Handle, hRegion, true) )
{
::DeleteObject( hRegion );
}
}
That will round the corners of the form just like XP does.
|
Yes, my form does this (except that I wasn't cleaning up with
DeleteObject) - what I want to do is to have a black border round the
form. I've tried various ways of doing this, but they seem to end up
looking pixellated. I did find some code here which used FrameRgn to
outline the form, but I can't get this to display anything. I have an
image which completely fills the form, and this may be overwriting my
form border.
--
Simon Elliott http://www.ctsn.co.uk
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Jun 15, 2005 12:54 am Post subject: Re: TCanvas RoundRect method looks odd |
|
|
"Simon Elliott" <Simon at ctsn.co.uk> wrote:
Please trim your posts.
| Quote: | [...] I did find some code here which used FrameRgn to
outline the form, but I can't get this to display anything.
|
Look at the win32 API CombineRgn and related functions. By
creating multiple regions as I first showed you (without
assigning them) and then using CombineRgn on them with the
correct flags, you can eventually end up with a region that
represents only your window frame which you would then assign
to the Handle.
Pay close attention to what regions windows will take
ownership of and what regions you will be responsible for
destroying. One mistake and you'll consume memory every
time the form's size changes.
| Quote: | I have an image which completely fills the form, and this may
be overwriting my form border.
|
Then comment out that code until you're happy with the regions.
I doubt that it's of concern though because the border is part
of the non-client area. IOW, you'd have to be doing something
intentional and quite messy to get the image over the borders.
~ JD
|
|
| Back to top |
|
 |
Simon Elliott Guest
|
Posted: Mon Jun 27, 2005 8:09 pm Post subject: Re: TCanvas RoundRect method looks odd |
|
|
On 15/06/2005, JD wrote:
| Quote: |
Please trim your posts.
|
I was trying to keep some context. Are there any guidelines for the
Borland newsgroups about how much to trim?
| Quote: | Pay close attention to what regions windows will take
ownership of and what regions you will be responsible for
destroying. One mistake and you'll consume memory every
time the form's size changes.
|
OK. Thanks for this: it's helped me avoid this pitfall.
--
Simon Elliott http://www.ctsn.co.uk
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|