[Question]Handle Events in a User-Defined Control

Discussion in 'Archives' started by Markizano, May 29, 2007.

[Question]Handle Events in a User-Defined Control
  1. Unread #1 - May 29, 2007 at 3:43 PM
  2. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    [Question]Handle Events in a User-Defined Control

    When making a User-Defined control in VB6, how do I tell VB what to do when an event is called. I am currently trying to make a number box to take the place of a TextBox. The only problem with that is I can't figure out how to tell VB to handle the Click event and others. A user-defined control comes with GotFocus, LostFocus and Validate; but I want to add Click, MouseUp, MouseDown, DblClick, KeyPress, KeyUp, KeyDown, and Change (Maybe a few others). I could use some general help to make the code handle the event when it is called and have it be called at the right time.

    Any help is appreciated.

    Markizano
     
  3. Unread #2 - May 29, 2007 at 10:02 PM
  4. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [Question]Handle Events in a User-Defined Control

    Code:
    private sub UserControl_Click()
       'blah
    end sub
     
  5. Unread #3 - Jun 4, 2007 at 3:47 PM
  6. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    [Question]Handle Events in a User-Defined Control

    Actually, that's what I'm trying to create. I've learned recently that the Sub UserControl is the SubProgram for the usercontrol, then there's an underscore, then the event name. A basic UserControl that can receive focus in the properties editor comes with the events: "GotFocus", "LostFocus", and "Validate". Yet, these events are nowhere to be found in the module. Now, what if I wanted to add an event that would occur when the mouse is clicked? I put in this code in the General Declarations:
    Code:
    Event Click()
    
    and now when I make the .OCX and add the component to my toolbox and add that to my form, I can now add this to my code (I'm making a NumberBox to start simple):
    Code:
    Private Sub NumberBox1_Click()
       'Whatever I want the control to do when clicked goes here.
    End Sub
    
    The only problem with that is that Just putting the code "Event Click()" Doesn't mean that when the mouse is pressed and released over the control that it will automatically handle it in that fasion. What I want to do is handle the code for the event.
    Something like:
    Code:
    'Declarations
    Event Click()
    
    Private Sub HandleEvent_Click()
        If MouseDown Then
            If MouseUp Then
                Call Click
            End If
        End If
    End Sub
    
    Something like that. Hope that cleared things up for you, Covey.

    EDIT: Didn't you make your own UserControl for EliteSwitch? I saw one when that kid tried to decompile it.
     
  7. Unread #4 - Jun 4, 2007 at 11:28 PM
  8. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [Question]Handle Events in a User-Defined Control

    Add this to your usercontrol code:
    Code:
    Public Event Click()
    
    Private Sub UserControl_Click()
        RaiseEvent Click
    End Sub
     
  9. Unread #5 - Jun 5, 2007 at 3:05 PM
  10. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    [Question]Handle Events in a User-Defined Control

    Ok, kew...Thanks for the method on how to handle events for the regular/basic/given events when a control is created at design-time; now, what if I wanted to create a new event that is not included in the given events, such as...
    Code:
    Event Random(Number As Integer) ' Randomizes the numbers in the NumberBox if a number is entered.
    
    Private Sub UserControl_Random(Number As Integer)
    If UserControl.Number = Number Then RaiseEvent Random
    End Sub
    
    Is this the manner that I would proceed to do so?

    In the case that I use this for other User-Defined controls, I want to be able to use this for events not included in the default set of events given when the control is created at design-time. I really appreciate what has been given so far. This really helps,
    THANK YOU MUCH! :D.
     
  11. Unread #6 - Jun 6, 2007 at 3:19 AM
  12. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [Question]Handle Events in a User-Defined Control

    I'm not 100% sure, but it would make sense doing it that way.
     
  13. Unread #7 - Jun 6, 2007 at 2:44 PM
  14. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    [Question]Handle Events in a User-Defined Control

    Ok Covey, Thank you very much for everything! :D If I have any more questions, of course, I'll post.
     
< Guide Compilation | selling lvl 68 with fire cape !!!!!!!omfg!!!!! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site