Raise event problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QW5kcmV3?=

    Raise event problem


    I have a vb.net 2005 app I am creating, I also have a separate user control
    that I have created separate from the app.

    On the control I have:

    Namespace HLMultiSelect.F orms.Controls
    Public Class HLMultiSelect

    Inherits System.Windows. Forms.Control

    Public Event ReportMouseStat us(ByVal bStatus As Boolean)

    Private Sub HLSelectButton_ MouseEnter(ByVa l sender As Object, ByVal
    e As System.EventArg s) Handles Me.MouseEnter
    mMouseHover = True
    Invalidate()

    RaiseEvent ReportMouseStat us(True)

    End Sub

    Private Sub HLSelectButton_ MouseLeave(ByVa l sender As Object, ByVal
    e As System.EventArg s) Handles Me.MouseLeave

    mMouseHover = False
    Invalidate()

    RaiseEvent ReportMouseStat us(False)
    End Sub

    End Class

    End Namespace

    On the app that I am creating I have:

    Imports HLMultiSelect.F orms.Controls
    Public Class Form1

    Public WithEvents sMouse As New HLMultiSelect
    Private Sub sMouse_ReportMo useStatus(ByVal bStatus As Boolean) Handles
    sMouse.ReportMo useStatus

    MsgBox("hello")

    End Sub

    Id does not fire, am I missing something?

    The only thing that calls the event is when the user puts the mouse over the
    control.




  • Steve Gerrard

    #2
    Re: Raise event problem

    Andrew wrote:
    >
    The only thing that calls the event is when the user puts the mouse
    over the control.
    Which never happens, because the control is not on a form, where the user to put
    their mouse over it.

    You could either put an instance of the control on Form1, and then handle that
    instance's ReportMouseStat us event, or you can do as you have done, and then add
    sMouse to the form's controls, using Me.Controls.Add . You will probably need to
    give it a position and size, and make sure it is visible, if you go that way.


    Comment

    • =?Utf-8?B?QW5kcmV3?=

      #3
      Re: Raise event problem

      It is a control on a form, but I was able to solve the problem, I did not
      make the Public Event ReportMouseStat us(ByVal bStatus As Boolean)
      A shared event.

      Thanks for the help..






      "Steve Gerrard" wrote:
      Andrew wrote:

      The only thing that calls the event is when the user puts the mouse
      over the control.
      >
      Which never happens, because the control is not on a form, where the user to put
      their mouse over it.
      >
      You could either put an instance of the control on Form1, and then handle that
      instance's ReportMouseStat us event, or you can do as you have done, and then add
      sMouse to the form's controls, using Me.Controls.Add . You will probably need to
      give it a position and size, and make sure it is visible, if you go that way.
      >
      >
      >

      Comment

      • Steve Gerrard

        #4
        Re: Raise event problem

        Andrew wrote:
        It is a control on a form, but I was able to solve the problem, I did
        not make the Public Event ReportMouseStat us(ByVal bStatus As Boolean)
        A shared event.
        >
        That suggests to me that the control you are getting the event from (sMouse, the
        one you created with New), is not the same as the one that actually picked up
        the mouse (the one you have on the form).

        If that is okay with you, it is fine, but if there is already a control on the
        form, there is no need to create another one with New; just capture the event
        from the one on the control.


        Comment

        Working...