Tuesday, October 19, 2010

vb6 how to dynamically add controls


vb6 can dynamically add a control without control array:
object.add (progid, name, container)

Parameters:
object: necessary. An object expression, its value is "used" in the list of an object.

progid: necessary. A string that identifies the control. Most of the control progid can see objects through the browser to decide. Progid control by the control of the library and class composition. For example, commandbutton control progid is vb.commandbutton. Progid with the object in the browser not the same as shown in the case, visual basic will display a error message including the correct progid.

name: necessary. A string used to identify the members of the collection.

container: Optional. An object reference that specifies the control container. If not specified or null, the default value of controls set their containers. By specifying the parameters, a control can be placed in any existing container control (such as frame control). Users can control or activex document as a container.

For example: (add in picture1 above a commandbutton)
private sub form_load ()
form1.controls.add "vb.commandbutton", "cmdok", picture1
with form1! cmdok
. Visible = true
. Width = 500
. Caption = "confirm (& y)"
end with
end sub

Focus: When you add a reference to the need not permit the control to an existing (already deployed good) application, before using the add method to add the controls you have to have the license keyword.


Add no reference in the run-time control
You can also add methods to dynamically add a reference in the project was not the control. ("Not cited" control is not present in the control toolbox). To do this, you must also add keywords to control the license to the licenses collection. The following example be added before adding the control itself, the control of the permit keyword:
option explicit
private withevents extctl as vbcontrolextender

private sub form_load ()
licenses.add "prjweeks.weeksctl", "xydsfasfjewfe"
set extctl = form1.controls.add ("prjweeks.weeksctl", "ctl1")
extctl.visible = true 'the control is invisible by default.
end sub
However, no reference to such a control program of events, you must use withevents keyword to declare a variable as vbcontrolextender target object (as above), and set the object variable to add a reference to the method returns. Then, vbcontrolextender object objectevent events programming the control of the event. Here is a simple example:
option explicit
dim withevents objext as vbcontrolextender 'statement extender variable

private sub loadcontrol ()
licenses.add "project1.control1", "xydsfasfjewfe"
set objext = controls.add ("project1.control1", "myctl")
objext.visible = true
end sub

private sub extobj_objectevent (info as eventinfo)
'Using the select case programming control events.
select case info.name
case "click"
'Click here to deal with the incident.
'Now show the other case
case else 'unknown event
'Here to deal with unknown events.
end select
end sub

Note: not to an inherent control variables assigned to the vbcontrolextender; any such attempt will cause a type mismatch error.

However, you can also use an object variable declared withevents keyword, and set the method returns a reference to the variable, add the control to a dynamic program of events, as shown below.
option explicit
'Declare an object variable commandbutton.
private withevents cmdobject as commandbutton

private sub form_load ()
set cmdobject = form1.controls.add ("vb.commandbutton", "cmdone")
cmdobject.visible = true
cmdobject.caption = "dynamic commandbutton"
end sub

private sub cmdobject_click ()
print "this is a dynamically added control"
end sub

If you want to add a user control or any activex control to your form, or to the control must be added to the "tool box", or to control the license tags to the licenses collection. For more information, please refer to the "increasing method (licenses set)."

Note: If you add an activex or user control to your project, but did not use it in the form, you must not select "Project Properties" dialog box "build" tab on the "delete the unused The activex control "option. If your application tries to add the control, then the add method will fail because the necessary information has been discarded.


Remove the control

To remove dynamically add controls, use the "remove" method. Please note that you can only remove those who use the "Add" method to add the control (and use the "load" statement to add the control to compare) the following example to delete a dynamic added controls:
form1.controls.remove "ctl1" 'The name of the control ctl1







Recommended links:



Teach you in a foreign country for international domain name registration



Quality integrators corporation is canadian



MP4 TO 3GP



Approach new and successful



E-mail Scrubbing Brush



Store goods without manually



Intel Strikes started



Evaluate Java And JavaScript



Ningbo CHIC - Yum CRC show "weapon"



Easy-speed Run 47 Hours To Restore The Secret



3GPP converter



My Favorite Text Or Document Editors



Evaluate Screen Capture



VBScript Length Property



MP4 To Flash



No comments:

Post a Comment