943,677 Members | Top Members by Rank

Ad:
Jan 21st, 2008
0

Rounded corners - one more time

Expand Post »
I've created a playing card descendent of TCustomControl and I want it to have rounded corners. The card is displayed in a Paint procedure where I determine the bitmap and then use a Canvas.Draw(0, 0, FCardBMP); This approach works well except - no rounded corners. Setting FCardBMP.Transparent := true; doesn't work when the card is dragged onto the table which has a different color background. It seems that "Transparent" just sets the corner, transparent pixels to the color of the initial background, but doesn't change pixels colors when the card is dragged.

With no success I've tried to use

Cnt := GenRegion(Par, FCardBMP,
(FCardBMP.Width - FCardBMP.Width+1) div 2,
(FCardBMP.Height - FCardBMP.Height+1) div 2);
hRegion := CreatePolygonRgn(Par, Cnt, ALTERNATE);
SetWindowRgn(FCardBMP.handle, hRegion, true);

I believe the secret is to useSetWindowRgn but I'm stymied. Any help would be appreciated. Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bob on whidbey is offline Offline
32 posts
since Oct 2007
Feb 9th, 2008
0

Re: Rounded corners - one more time

Try the function
Pascal and Delphi Syntax (Toggle Plain Text)
  1. RoundRect(DC: HDC; X1, Y1, X2, Y2, X3, Y3: Integer) : Bool;
I've never got around to using it, but it says in the book "Draws a rectangle with rounded corners using the selected pen and filled using the selected brush."
Reputation Points: 10
Solved Threads: 1
Newbie Poster
glindhot is offline Offline
14 posts
since Feb 2008
Feb 10th, 2008
0

Re: Rounded corners - one more time

Regions are for windows. Not for painting.

You should be able to set the transparent and transparentColor properties of the bitmap before drawing it in your paint procedure.

Hope this helps.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Feb 11th, 2008
0

Re: Rounded corners - one more time

As the card is dragged from the gray side to the green "table" the background will change. Depending on where the card is, some of the time 1 or 2 corners will have a green background and 3 or 2 will have gray corners. Sometimes even half and half as the corner is about 3 x 2 pixels.

When I set the transparent color (to the unique color of the corners) it seems that the color in each corner is static....at the gray color of the initial backgroubnd of the card. Dragging the card to the table doesn't change the corner colors to green. I thought that's what was suppose to happen.

This seems to work fairly well, although not perfectly, to set the corners transparent for each bitmap card. Notice that it seems to work better to have width and height PLUS ONE. This coding is executed whenever the dimension of a card changes...generallhy only once per card...when it is instantiated.

GetWindowRgn(Handle, FRoundedReg);
DeleteObject(FRoundedReg);
D := width div 15; // "15" determined by trial and error
FRoundedReg := CreateRoundRectRgn(0, 0, Width+1, Height+1, D, D);
SetWindowRgn(Handle, FRoundedReg, TRUE);
Reputation Points: 10
Solved Threads: 0
Light Poster
bob on whidbey is offline Offline
32 posts
since Oct 2007
Feb 11th, 2008
0

Re: Rounded corners - one more time

So your card is actually a separate window?

If it is just the problem of dragging the card across different components on a single form, you can use a TPaintBox (found in the System tab of the components palette) to draw on the form directly. Then you could avoid using a separate window and window regions...
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: FTP transfer fails without errors
Next Thread in Pascal and Delphi Forum Timeline: how to connect SQL database through delphi?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC