Resizing Static Text control
-
Hi all, I just wanted to know can we increase the size of static text(label we are using in dialog box) at runtime.... like i put text in my static text at run time using SetDlgItemText(), but sometimes when text is big it is not displayed i.e text is displayed according to the size of static text control....so what i want is that my control size should increase or decrease according to the text given... Thanks in advance...
-
Hi all, I just wanted to know can we increase the size of static text(label we are using in dialog box) at runtime.... like i put text in my static text at run time using SetDlgItemText(), but sometimes when text is big it is not displayed i.e text is displayed according to the size of static text control....so what i want is that my control size should increase or decrease according to the text given... Thanks in advance...
BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); CString str; CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowText(str); int iLen = str.GetLength(); int iWidth = 8*iLen;//assume 8 pixel per character GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); rect.right = iWidth; GetDlgItem(IDC_STATIC1)->MoveWindow(rect); return TRUE; }
Nigah M Manzoor
modified on Tuesday, July 1, 2008 7:58 AM
-
BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); CString str; CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowText(str); int iLen = str.GetLength(); int iWidth = 8*iLen;//assume 8 pixel per character GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); rect.right = iWidth; GetDlgItem(IDC_STATIC1)->MoveWindow(rect); return TRUE; }
Nigah M Manzoor
modified on Tuesday, July 1, 2008 7:58 AM
Hey thanks its increasing the size but one more problem is there, where ever i put label when i run my program its showing the text at upper left corner only.....
-
Hey thanks its increasing the size but one more problem is there, where ever i put label when i run my program its showing the text at upper left corner only.....
-
use GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); ScreenToClient(&rect); instead of GetDlgItem(IDC_STATIC1)->GetClientRect(rect);
Nigah M Manzoor
hey thanks it worked correctly
-
hey thanks it worked correctly
i also used the same code to resize my static text control it is working fine but one problem the text box width is not exactly according to the text it is little bit large. i want do like autofit to content. any idea?
-
i also used the same code to resize my static text control it is working fine but one problem the text box width is not exactly according to the text it is little bit large. i want do like autofit to content. any idea?
Use this method. CClientDC dc( pWnd ); CFont * pOldFont = dc.SelectObject( pWnd->GetFont()); CSize txtSize = dc.GetTextExtent(m_szText); dc.SelectObject( pOldFont);