Firing new event in existing control?

Hi,

I'm new to Visual Basic 2005 (Express Edition) and I' decided to build my own PrintPreviewDialog using the PrintPreviewControl. One of the properties of the PrintPreviewControl is the Zoom Propertie. Unfortunately, the control doesn't provide a ZoomChanged event and I need to know when this propertie is modified (by the user, by the program or by resizing the control).

Is there a way to trigger a ZoomChanged event everytime the value of the Zoom propertie change

I created a new UserControl that inherit from the PrintPreviewControl but I'm not sure where to go from there.



Answer this question

Firing new event in existing control?

  • LeoXue

    Gack! I meant to use Overrides, not Overloads. This is not the first time I wanted to override a property but couldn't, it should have given me pause. Shadows is the band-aid.


  • m.schlestein

    Hmm, that would change the Zoom property value without raising an event. Using Overloads instead of Shadows ensures that the event is always raised, even when code references the base class...


  • Jweige

    Thanks, I tought about that but, in this case, the zoom property already exist and is build in the PrintPreviewControl. I dont have acces to the code of the property Get or property Set and therefore can not raise a event from there.

    I'm thinking about adding a new property like this one

    Public Property MyZoom() As Double
    Get
    MyZoom = Me.Zoom
    End Get
    Set(ByVal value As Double)
    Me.Zoom = value
    If Not Me.DesignMode Then RaiseEvent ZoomChanged(Me, New EventArgs)
    End Set
    End Property

    This way the old Zoom property still exist but by using the new MyZoom property I'm raising the zoomChanged event. Unfortunately this doesn't triger the event when the zoom property is changed when the control is resize.

    What I would like is a way to "monitor" the zoom property value end raise a event when the value change. Is it possible


  • awperli

    If you are using a property you can raise an event when you set a new value. Here is an example.




  • TonyTech06

    Try this:

    Public Class MyPreviewControl
    Inherits PrintPreviewControl
    Public Event ZoomChanged(ByVal Sender As Object, ByVal e As EventArgs)
    Public Overloads Property Zoom() As Double
    Get
    Return MyBase.Zoom
    End Get
    Set(ByVal value As Double)
    If Math.Abs(MyBase.Zoom - value) < 1.0E-17 Then Exit Property
    MyBase.Zoom = value
    RaiseEvent ZoomChanged(Me, New EventArgs)
    End Set
    End Property
    End Class



  • CHEN YU-TIEN

    Actually you would want to use the Shadows keyword instead of the Overloads keyword. For consumers explicitly using your derived type, this would effectively hide the "zoom" property in the base class. Do note that the consumer could still cast the control into a previewcontrol and call the original "zoom" property.

    Hope this helps,



  • Tampa Magnus

    That is incorrect. What you are referring to is the "overrides" keyword, not the "overloads" keyword. However, for that to work the property in the base class needs to be marked as "overridable", which I assume is not the case for this control.

     



  • Firing new event in existing control?