Change the shape of CEdit custom draw?
-
Hi, I've created CCustomEdit inherited from CEdit and managed to change its background color and text color. I'm trying to change the shape of it ( eg : on each end i plan to make it like curve a bit rather than 90 degrees ) Is there any ways to change the shape of the CEdit ? Any tutorials/sample would be highly appreciated. Can GDI able to change the style of it? My project is MFC based. With thanks, KarHong
good
-
Hi, I've created CCustomEdit inherited from CEdit and managed to change its background color and text color. I'm trying to change the shape of it ( eg : on each end i plan to make it like curve a bit rather than 90 degrees ) Is there any ways to change the shape of the CEdit ? Any tutorials/sample would be highly appreciated. Can GDI able to change the style of it? My project is MFC based. With thanks, KarHong
good
karhong wrote:
Is there any ways to change the shape of the CEdit ?
Not only edit control, but the shape of any window can be changed by setting appropriate region. In your case, create a round rect region using the
CreateRoundRectRgn()
function and set that region to the edit control using theSetWindowRgn()
function. -
Hi, I've created CCustomEdit inherited from CEdit and managed to change its background color and text color. I'm trying to change the shape of it ( eg : on each end i plan to make it like curve a bit rather than 90 degrees ) Is there any ways to change the shape of the CEdit ? Any tutorials/sample would be highly appreciated. Can GDI able to change the style of it? My project is MFC based. With thanks, KarHong
good
This may help you http://www.codeproject.com/KB/edit/EditStyle.aspx
-
karhong wrote:
Is there any ways to change the shape of the CEdit ?
Not only edit control, but the shape of any window can be changed by setting appropriate region. In your case, create a round rect region using the
CreateRoundRectRgn()
function and set that region to the edit control using theSetWindowRgn()
function. -
This may help you http://www.codeproject.com/KB/edit/EditStyle.aspx
-
karhong wrote:
Is there any ways to change the shape of the CEdit ?
Not only edit control, but the shape of any window can be changed by setting appropriate region. In your case, create a round rect region using the
CreateRoundRectRgn()
function and set that region to the edit control using theSetWindowRgn()
function.what place should i place the CreateRoundRectRgn() and SetWindowRgn() ? I've try below code but it seems like the EditBox keep on blinking CRect rcItem; CDC* pDC=this->GetDC(); this->GetClientRect(&rcItem); CRgn rgn; rgn.CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom, 50, 50); SetWindowRgn( (HRGN)rgn.Detach(), TRUE ); Thanks, KarHong
good
-
what place should i place the CreateRoundRectRgn() and SetWindowRgn() ? I've try below code but it seems like the EditBox keep on blinking CRect rcItem; CDC* pDC=this->GetDC(); this->GetClientRect(&rcItem); CRgn rgn; rgn.CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom, 50, 50); SetWindowRgn( (HRGN)rgn.Detach(), TRUE ); Thanks, KarHong
good
-
karhong wrote:
what place should i place the CreateRoundRectRgn() and SetWindowRgn() ?
The
PreSubclassWindow()
function is a good place.karhong wrote:
CDC* pDC=this->GetDC();
Why are you calling this function?
oh i'm using the pDC to draw the rectangle. That one I'm just testing out with the link given by Chandrasekharanp I'm taking pDC out now and try your method. But after i put below code, and execute it then the button went dissapear void CCustomEdit::PreSubclassWindow() { CRect rcItem; this->GetClientRect(&rcItem); CRgn rgn; rgn.CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom, 50, 50); SetWindowRgn( (HRGN)rgn.Detach(), TRUE ); CEdit::PreSubclassWindow(); }
good