![]() |
CXTPControlComboBox width |
Post Reply
|
| Author | |
Bala
Newbie
Joined: 31 January 2008 Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Topic: CXTPControlComboBox widthPosted: 09 July 2008 at 11:09am |
|
Hi,
We are using CXTPControlComboBox object and setting up a standard width based on the string size that we are adding.
But on multi byte langauges ( japanese/chinese) our math of setting width doesnot hold up....a few chars are trucated in the display.
Here is how our display looks like...
![]() Is there an auto width property on the CXTPControlComboBox? or should we be getting the font width and number of chars do the math and come up with the width??
Regards,
Bala |
|
![]() |
|
jimmy
Senior Member
Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
Post Options
Thanks(0)
Quote Reply
Posted: 09 July 2008 at 11:11am |
|
Hi,
int CExResizeDialog::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) { if (lpCreateControl->bToolBar) { CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar); if (!pToolBar) return FALSE; if (lpCreateControl->nID == ID_GUI_ONLINECURRENT && pToolBar->GetBarID() == IDR_GUI_ONLINESETTINGS) { CXTPControlComboBox* pComboState = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject(); pComboState->SetCaption(_T("Online")); pComboState->SetWidth(180); pComboState->SetDropDownWidth(220); pComboState->SetDropDownItemCount(30); lpCreateControl->pControl = pComboState; return TRUE; } } return FALSE; } Jimmy |
|
![]() |
|
Bala
Newbie
Joined: 31 January 2008 Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 09 July 2008 at 12:35pm |
|
Thanks for your response.looks like you have hard coded value of 180.
we are also calling SetWidth
But I would like to know what value to set..
for ex:- we have a string called "Samrt priority" in english ...and it may be different in chinese.....so how do we come up with the width.
One way is to get the string length and multiply by average font width.
I am trying to see - if codejock has a special flag called "autowidth" on the combo box. ---ie'; combo box width adjusts based on the string added and font. - instead of users having to specify it...
Regards,
Bala
|
|
![]() |
|
Smucker
Senior Member
Joined: 02 February 2008 Status: Offline Points: 156 |
Post Options
Thanks(0)
Quote Reply
Posted: 09 July 2008 at 2:16pm |
|
Here's the basic code I use:
int cwidth = 0; pcombo->ResetContent(); CDC *pdc = pcombo->GetEditCtrl()->GetDC(); for (each CString strval you add) { pcombo->AddString(strval); int w = pdc->GetTextExtent(strval).cx; if (w > cwidth) cwidth = w; } pcombo->GetEditCtrl()->ReleaseDC(pdc); pcombo->SetDropDownWidth(max(pcombo->GetWidth(), cwidth)); // ** ** - you may want to constrain cwidth to a reasonable range. |
|
|
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)
Platform: Windows 200x/XP/Vista/Win7 (32/64 bit) Language: Visual C++ 9.0 (Studio 2008) |
|
![]() |
|
Bala
Newbie
Joined: 31 January 2008 Status: Offline Points: 12 |
Post Options
Thanks(0)
Quote Reply
Posted: 09 July 2008 at 3:01pm |
|
Thanks Smucker! I plugged in the logic and works great in german,french,chinese,english...etc
I had to substitute GetEditCtrl with GetListBoxCtrl - since our ctrl is of type list box
May be for next release - codejock could support this property - 'autowidth' and do this math - instead of every customer setting the width.
Regards,
Bala
|
|
![]() |
|
Smucker
Senior Member
Joined: 02 February 2008 Status: Offline Points: 156 |
Post Options
Thanks(0)
Quote Reply
Posted: 09 July 2008 at 3:41pm |
|
Here's a more accurate version that handles the font size and borders/scroll width correctly. New code/changed code in green:
int cwidth = 0; CFont cfont; CDC *pdc = pcombo->GetListBoxCtrl()->GetDC(); CFont *pfont = pcombo->GetListBoxCtrl()->GetFont(); if (!pfont) { cfont.CreateStockObject(DEFAULT_GUI_FONT); pfont = &cfont; } pdc->SaveDC(); pdc->SelectObject(pfont); pcombo->ResetContent(); for (each CString strval you add) { pcombo->AddString(strval); int w = pdc->GetTextExtent(strval).cx; if (w > cwidth) cwidth = w; } CXTNonClientMetrics ncm; cwidth += ncm.iBorderWidth * 2 + ncm.iScrollWidth; pdc->RestoreDC(-1); pcombo->GetListBoxCtrl()->ReleaseDC(pdc); pcombo->SetDropDownWidth(max(pcombo->GetRect().Width(), cwidth)); |
|
|
Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)
Platform: Windows 200x/XP/Vista/Win7 (32/64 bit) Language: Visual C++ 9.0 (Studio 2008) |
|
![]() |
|
jimmy
Senior Member
Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
Post Options
Thanks(0)
Quote Reply
Posted: 10 July 2008 at 6:45am |
|
Will be nice to support Markup into ListBox
Jimmy |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |