954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

access events of form in UserControl

access events of form in UserControl
i have
1)User control with one MSFlexGrid on it
2)Form to place user control
3)Some form's own control
i dont know how many controls are there under form
i have to place them in grid columns (eg. combobox in grid to provide its service)
now problem is if i place any control in grid after i LostFocus from that control i need to palce the value present in control in grid.
i cannot ask to write LostFocus function to my UserControl user or any programmer so i must have provision to catch events of controls available on form.
let's make question more simple
i need to access events of controls present on form in userControl without any code in form

vtelebyteM
Newbie Poster
4 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Hi, U can use Usercontrol.Parent Property get the Parent object and use WithEvents keyword to capture the Parent events

'In UserControl
Option Explicit

Dim WithEvents mParent As Form

Private Sub mParent_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   MsgBox "Down"
End Sub

Public Sub SetParent(mParentForm As Form)
   Set mParent = mParentForm
End Sub

Private Sub UserControl_Show()
   If TypeOf UserControl.Parent Is Form Then
      Set mParent = UserControl.Parent
   End If
End Sub


Now your usercontrol receive the messages if its parent is form.

selvaganapathy
Posting Pro
547 posts since Feb 2008
Reputation Points: 44
Solved Threads: 100
 

thanks for code.....
i tried same thing & it works......

vtelebyteM
Newbie Poster
4 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You