|
-
Jul 15th, 2015, 09:23 AM
#1
Thread Starter
Fanatic Member
Creating class and Extend control Properties
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
-
Jul 15th, 2015, 09:40 AM
#2
Re: Creating class and Extend control Properties
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
-
Jul 15th, 2015, 09:45 AM
#3
Thread Starter
Fanatic Member
Re: Creating class and Extend control Properties
 Originally Posted by LaVolpe
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
Thank you, But is possible to build without to use UserControl ? Declaring Object and to use a Class ?
Tia
-
Jul 15th, 2015, 09:48 AM
#4
Re: Creating class and Extend control Properties
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.
-
Jul 15th, 2015, 09:52 AM
#5
Thread Starter
Fanatic Member
Re: Creating class and Extend control Properties
 Originally Posted by LaVolpe
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.
Thank you again
Do you have a little example ? :-(
-
Jul 15th, 2015, 10:10 AM
#6
Re: Creating class and Extend control Properties
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
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:
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.
Last edited by LaVolpe; Jul 15th, 2015 at 10:19 AM.
-
Jul 15th, 2015, 10:25 AM
#7
Thread Starter
Fanatic Member
Re: Creating class and Extend control Properties
How to use I tried as
Code:
Dim frmobjdesenho As objdesenho
Private Sub Form_Activate()
Set frmobjdesenho.AttachControl Me.pctfrm
End Sub
-
Jul 15th, 2015, 10:36 AM
#8
Re: Creating class and Extend control Properties
Code:
Set frmobjdesenho.AttachControl = Me.pctfrm
You forgot the equal sign
If creating class properties or creating usercontrols is new to you. You have a lot of experimenting and playing in your near future.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|