/* Filename: Round_Corner_Button.cc Date: 2023-03-21 Author: Mervyn Bick Description: Round_Corner_Button is a pushbutton based on an idea (and code) "borrowed" from Marc van den Berghen's article "The Form Factory" in issue 21 of the dBulletin. https://www.jpmartel.com/bulletin.htm The custom control should be used on a form where the metric property is set to pixels. In the designer the pushbutton will present as a square. Resize as appropriate keeping the height and width about the same. When the form opens the pushbutton will set its width to match the height. This ensures any text remains centered. If it is necessary to assign an event handler to the onOpen event the onOpen event in the custom class must be executed before any other code. function ROUNDBUTTON1_onOpen() roundbutton::onOpen() // Other code return In theory, CreateRoundRectRgn() from the Windows32 API should create the required shape. This function allows the rounding of the corners to be set as required. Unfortunately I have not managed to implement this (yet) so I've used CreateEllipticRgn() combined with a dBASE shape object. The dBASE shape object does not allow the rounding of the corners to be adjusted. */ class Round_Corner_Button( parentObj ) of PushButton( parentObj ) custom with (this) onOpen = class::ONOPEN metric = 6 // Pixels height = 65.0 width = 65.0 fontsize = 15 text = 'PB' systemtheme := false endwith function onopen local hrgn1 if this.width <> this.height this.width = this.height endif if type("SetWindowRgn") # "FP" extern CINT SetWindowRgn(CHANDLE, CHANDLE, CLOGICAL) user32 endif if type("CreateRoundRectRgn") # "FP" extern chandle CreateRoundRectRgn(cint,cint,cint,cint,cint,cint) gdi32 endif if type("CreateEllipticRgn") # "FP" extern chandle CreateEllipticRgn(cint,cint,cint,cint) gdi32 endif x1 = this.left y1 = this.top x2 = this.left+this.width y2 = this.top+this.height // hrgn1=CreateRoundRectRgn(x1,y1,x2,y2,1,1) hrgn1=CreateEllipticRgn(this.width-5,5,5,this.width-5) setwindowrgn(this.hwnd,hrgn1,true) class::addring() return function addRing this.outline = new shape(this.parent) this.outline.shapestyle := 4 this.outline.colorNormal := this.colorNormal this.outline.top = this.top this.outline.left = this.left this.outline.width = this.width this.outline.height = this.height this.outline.penwidth := 1 return endclass