Results 1 to 4 of 4

Thread: Usercontrol Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    5

    Usercontrol Question

    Hi all,

    on my usercontrol i have some Textboxes and one Button.

    1. How can I have all the events from the Controls in the main Form?
    For example the "Button_Click" Event

    2. How can I access Controls from the MainForm in my Usercontrol?


    THX

    Greetings
    Last edited by NETY; Feb 24th, 2003 at 10:37 AM.

  2. #2
    Member
    Join Date
    May 2002
    Location
    Malaysia
    Posts
    45
    You can try to declare your textbox/button in the control as public and at the main form which using this control, try to use the ADDHANDLER method to assign the control's button/textbox event to a particular Sub declare at your main form. I suppose this should work, but i haven't try before... perhaps after my office hour i will try to work out and see. by the time being hopefully this would give you some idea on how to do it...

  3. #3
    Member
    Join Date
    May 2002
    Location
    Malaysia
    Posts
    45
    Another way to do this is your declare a Public event for your control... then at the button_click event, try to fire this custom event. For example:

    Public Event MybuttonClick()


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    RaiseEvent MybuttonClick()

    End Sub


    the custom event MybuttonClick should be visible at the main form souce code editor whenver you using your usercontrol.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    5
    Hi StormJason,

    thanks a lot for your Replys.

    I have decleared the controls as public.

    Is this the professional way, because for every event i want to use in my mainform , I must add new events ?! For example. The Button-Control has a lot of such events.

    THX

    NETY

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width