943,636 Members | Top Members by Rank

Ad:
Feb 24th, 2009
0

access events of form in UserControl

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vtelebyteM is offline Offline
4 posts
since Feb 2009
Feb 24th, 2009
0

Re: access events of form in UserControl

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

VB Syntax (Toggle Plain Text)
  1. 'In UserControl
  2. Option Explicit
  3.  
  4. Dim WithEvents mParent As Form
  5.  
  6. Private Sub mParent_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  7. MsgBox "Down"
  8. End Sub
  9.  
  10. Public Sub SetParent(mParentForm As Form)
  11. Set mParent = mParentForm
  12. End Sub
  13.  
  14. Private Sub UserControl_Show()
  15. If TypeOf UserControl.Parent Is Form Then
  16. Set mParent = UserControl.Parent
  17. End If
  18. End Sub

Now your usercontrol receive the messages if its parent is form.
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Feb 25th, 2009
0

Re: access events of form in UserControl

thanks for code.....
i tried same thing & it works......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vtelebyteM is offline Offline
4 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: STOP a process in between .....
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How to : save an auto generated power point Slide to a folder and rename it





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC