Online Support System

Have a Question? Contact Us

Direct:
614-827-0499

Knowledge Base

Knowledge Base / Slide UI Mobile Controls / Technical Questions

How to add controls to UICanvas dynamically

04/20/2010 08:06 AM

Question

How can I add UI controls to UICanvas dynamically?

Answer

You may access controls of UICanvas in run-time using its 'childs' variable member.
For example: canvas.childs.Controls.Add(...);

But to add child controls to UICanvas properly you should use BeginAddControls(), EndAddControls(), and AddControl() methods.

BeginAddControls()
This method starts operations on controls inside of UICanvas. After you call this method UICanvas will not update until the EndAddControls() method is called. You can skip calling this method initially, becase the first call of 'AddControl()' will call this method automatically.

EndAddControls()
This method stops operations on controls inside of UICanvas and updates image buffer of UICanvas with newly added (removed) controls. You should always call this method when operations on child controls are complete.

AddControl(Control control)
Use this method to add a control to the UICanvas. You could alternatively use UICanvas.childs.Controls.Add(...) method, but it is recommended to use the AddControl() method for full compatibility with new versions of SlideUI Mobile Controls.

Download Example: http://www.devslide.com/shared/slideui/uicanvas-dynamic-controls.zip
(This example was created to show basic functionality and was tested using QVGA resolution only.)

Article Rating

The current rating for this article is Excellent (90%). The rating is based on 3 vote(s).