Hi
Somebody have a example how can to create a class and extend properties and events of control (It is not Microsoft), ?
Is possible to do it for any control , same no microsoft ?
Tia
Printable View
Hi
Somebody have a example how can to create a class and extend properties and events of control (It is not Microsoft), ?
Is possible to do it for any control , same no microsoft ?
Tia
The most common way of extending a control is to use a UserControl. Place the control you want to extend inside the usercontrol, add methods/properties that the control normally uses (which would call the actual methods), then add your own custom methods/properties. Generally, all you need to do at that point is to ensure the that contained control resizes properly to your usercontrol size, i.e., UserControl_Resize event
Sort of, without major hacking of VTables. You can create a class with all the methods you want, including all of the ones on the actual control. You would have one additional method where you pass the class the instance of the control, and that reference is cached in the class. When each method of the class is called, call the actual method on the control that applies and call your own custom methods for those that apply.
The downside with this approach is that you have to establish this class & control-relationship during runtime, this means you can't easily cache custom properties during design-time. The advantage with the usercontrol is that your custom properties can be assigned and cached during design-time.
Now there is a legitimate way of extending any control if you can gain access to the TLB of the control. The idea is to create a new interface that implements the actual control's interface. Theoretically, this new TLB can be used during runtime in a statement similar to the following after declaring the interface:Code:' simple example of maybe trying to extend VB's Picturebox
Private m_Control As VB.PictureBox
' your custom properties must be declared so they can be cached/retrieved
Private m_FileName As String
' Start your standard & custom properties and functions/subs
Public Property Set AttachControl(theControl As VB.PictureBox) ' called to assign class to control
Set m_Control = theControl
End Property
' sample of existing property
Public Property Let AutoRedraw(newValue As Boolean)
m_Control.AutoRedraw = newValue
End Property
Public Property Get AutoRedraw() As Boolean
AutoRedraw = m_Control.AutoRedraw
End PRoperty
' sample of custom property
Public Property Let PictureFileName(newValue As String)
m_FileName = newValue
' take action after property changed
End Property
Public Property Get PictureFileName() As String
PictureFileName = m_FileName
End Property
Private Sub Class_Terminate
Set m_Control = Nothing
End Sub
Set newInterface = [theControl]
Now the newInterface can be used to call the control's built-in methods and also your custom methods that are on that new TLB. This falls in the area of TLB design, which I am in no way an expert.
How to use I tried as
Code:Dim frmobjdesenho As objdesenho
Private Sub Form_Activate()
Set frmobjdesenho.AttachControl Me.pctfrm
End Sub
You forgot the equal signCode:Set frmobjdesenho.AttachControl = Me.pctfrm
If creating class properties or creating usercontrols is new to you. You have a lot of experimenting and playing in your near future.