| | |
Rounded corners - one more time
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 20
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Feb 2008
Posts: 11
Reputation:
Solved Threads: 1
Try the function 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."
Pascal and Delphi Syntax (Toggle Plain Text)
RoundRect(DC: HDC; X1, Y1, X2, Y2, X3, Y3: Integer) : Bool;
•
•
Join Date: Oct 2007
Posts: 20
Reputation:
Solved Threads: 0
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);
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);
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...
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...
![]() |
Similar Threads
- Rounded corners are back (DaniWeb Community Feedback)
- Recent changes (DaniWeb Community Feedback)
- Tic Tac Toe help (Java)
- Spell checker gone? (DaniWeb Community Feedback)
- Resolution for Rounded Corners (DaniWeb Community Feedback)
- Creating a blob (HTML and CSS)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: FTP transfer fails without errors
- Next Thread: how to connect SQL database through delphi?
| Thread Tools | Search this Thread |






