DuiVision development tutorial (9)-dynamically create controls and duivision controls

Source: Internet
Author: User

DuiVision development tutorial (9)-dynamically create controls and duivision controls

In most cases, DuiVision-based interface programs define the interface through xml in advance, but sometimes you need to dynamically create controls through code. You can refer to the following example of dynamically creating controls:

CDuiButton * pToolBtn = static_cast <CDuiButton *> (DuiSystem: CreateControlByName (L "button", m_pDlg-> GetSafeHwnd (), m_pDuiObject); if (pToolBtn) {(CControlBase *) m_pDuiObject)-> AddControl (pToolBtn); pToolBtn-> SetName (L "btnName"); pToolBtn-> SetTitle (L "Dynamic Button "); pToolBtn-> SetPosStr (L "10, 10, 110,35"); pToolBtn-> OnAttributeSkin (L "skin: IDB_BT_ICON", FALSE); pToolBtn-> trim (L "skin: trim ", FALSE); pToolBtn-> SetMaxIndex (4); pToolBtn-> SetAction (L "dlg: dlg_login"); pToolBtn-> OnPositionChange ();}

This code first uses the CreateControlByName function provided by DuiSystem to dynamically create a control (the control type name must be specified during creation, for example, a button control is a button, a handle to the window, and a pointer to the parent control ).
After the widget is created, call its function to set some properties of the widget. You must pay special attention to the settings of the widget's location information, you must set the position string (corresponding to the pos attribute of the control), because the position string can calculate the actual position of the control based on the location information of the parent control, if you do not use this method to directly specify the position of the control, the actual position may not be calculated because there is no relevant information during Automatic Location calculation.
You need to call the SetPosStr function to set the position string. Note that the OnPositionChange function must be called at the end. This function will actually perform a location calculation so that the control can be displayed in the correct position.

The following code is an example of dynamically creating controls in the demo program:

// Demonstrate how to dynamically Add a child control to the div (to the edit box page of the basic control) CControlBase * pDiv = (CControlBase *) GetControl (_ T ("tab. control.4 "); if (pDiv) {CDuiEdit * pControlEdit = static_cast <CDuiEdit *> (DuiSystem: CreateControlByName (L" edit ", m_pDlg-> GetSafeHwnd (), pDiv); if (pControlEdit) {pDiv-> AddControl (pControlEdit); pControlEdit-> SetName (L "btnName "); pControlEdit-> SetTitle (L "dynamically added edit box control"); pControlEdit-> SetPosStr (L "50,220,250,250"); pControlEdit-> OnAttributeSkin (L "skin: IDB_EDIT ", FALSE); pControlEdit-> OnAttributeLeftImage (L "skin: IDB_COMPUTER", FALSE); pControlEdit-> OnPositionChange ();}}

DuiVision open source code (github): https://github.com/blueantst/DuiVision
Ant financial studio home page: http://www.blueantstudio.net
DuiVision QQ group: 325880743
Public Account: blueantstudio or search for blue ant Studio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.