solidworks二次开发VB.NET--属性页控件 事件触发函数

1.属性页控件

在我们写了属性页控件后,我们需要检测属性页控件的事件,来对属性页事件作出响应,以满足后续动作。

2 捕捉到响应事件的api

solidworks提供了IPropertyManagerPage2Handler9 Interface 接口来监听控件事件。
http://help.solidworks.com/2017/english/api/swpublishedapi/SolidWorks.Interop.swpublished~SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9_members.html
接口成员如下:

Name    Description
 Method AfterActivation Called after the PropertyManager page has been activated.  
 Method AfterClose  Called after the PropertyManager page is closed.  
 Method OnActiveXControlCreated Called when an attempt to create an ActiveX control on the PropertyManager page occurs.  
 Method OnButtonPress   Called when a user clicks this button on this PropertyManager page.  
 Method OnCheckboxCheck Called when a user selects this check box on this Pro pertyManager page.  
 Method OnClose Called when this PropertyManager page is closing.  
 Method OnComboboxEditChanged   Called when a user changes the text string in the text box of a combo box on this PropertyManager page.  
 Method OnComboboxSelectionChanged  Called when a user changes the selected item in a combo box on this PropertyManager page.  
 Method OnGainedFocus   Called when a control (edit box, combo box, list box, or number box) gains focus on this PropertyManager page.  
 Method OnGroupCheck    Called when a user selects the check box in the title of a group box on a PropertyManager page.  
 Method OnGroupExpand   Called when a user clicks an arrow to open a group box on the PropertyManager page.  
 Method OnHelp  Called when a user clicks the Help button on this PropertyManager page.  
 Method OnKeystroke Processes a keystroke that occurred on this PropertyManager page.  
 Method OnListboxRMBUp  Called when the right-mouse button is released in a list box on this PropertyManager page.  
 Method OnListboxSelectionChanged   Called when a user changes the selected item in a list box or selection list box on this PropertyManager page.  
 Method OnLostFocus Called when a control (edit box, combo box, list box, or number box) loses focus on this PropertyManager page.  
 Method OnNextPage  Called when a user clicks the Next button on the PropertyManager page.  
 Method OnNumberboxChanged  Called when a user changes the value in the number box on a PropertyManager page.  
 Method OnNumberBoxTrackingCompleted    Called when a user finishes changing the value in the number box on a PropertyManager page.  
 Method OnOptionCheck   Called when a user selects an option (radio button) on this PropertyManager page.  
 Method OnPopupMenuItem Determines which item was selected when the user selects a pop-up menu item.  
 Method OnPopupMenuItemUpdate   When Windows attempts to select or deselect and enable or disable the pop-up menu item, SOLIDWORKS calls this method to get the state of the menu item from the add-in.  
 Method OnPreview   Called when a user clicks the Preview button on a PropertyManager page.  
 Method OnPreviousPage  Called when a user clicks the Back button on this PropertyManager page.  
 Method OnRedo  Called when a user clicks the Redo button on this PropertyManager page.  
 Method OnSelectionboxCalloutCreated    Performs some processing while the callout for this selection box is created.  
 Method OnSelectionboxCalloutDestroyed  Performs some processing after the callout for this selection box is destroyed.  
 Method OnSelectionboxFocusChanged  Indicates that the active selection list box has changed.  
 Method OnSelectionboxListChanged   Called when a user changes the selection list in a selection box on this PropertyManager page.  
 Method OnSliderPositionChanged Called whenever the user changes the position of a slider control on this PropertyManager page.  
 Method OnSliderTrackingCompleted   Called when a user finishes dragging a slider control on this PropertyManager page.  
 Method OnSubmitSelection   Called when a selection is made, which allows the add-in to accept or reject the selection.  
 Method OnTabClicked    Called when a user clicks a tab on a multi-tab PropertyManager page.  
 Method OnTextboxChanged    Called when a user changes the string in a text box on this PropertyManager page.  
 Method OnUndo  Called when a user clicks the Undo button on this PropertyManager page.  
 Method OnWhatsNew  Called when a user clicks the What's New button on this PropertyManager page.  
 Method OnWindowFromHandleControlCreated    Called when an attempt is made to create a .NET control on the PropertyManager page.

其中三种主要的接口用在属性页的确定与关闭上
和按钮按下

 [OnClose]       Called when this PropertyManager page is closing.  //在属性页点击确定关闭时响应
[AfterClose]    IPropertyManagerPage2Handler9~AfterClose.html) | Called after the PropertyManager page is closed.  //在属性页点击关闭时响应
[OnButtonPress]    Called when a user clicks this button on this PropertyManager page.  //点击按钮时响应

3 solidworks add-in的属性页响应事件类 PMPHandler

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports SolidWorks.Interop.swpublished



Public Class PMPageHandler
    Implements PropertyManagerPage2Handler9
------------------------------------------------------------------------------------------
    '定义变量
    Dim Length As Double = 0.05
    Dim Width As Double = 0.05
    Dim High As Double = 0.01
------------------------------------------------------------------------------------------
    Dim iSwApp As SldWorks
    Dim userAddin As SwAddin

    Public Sub New()

    End Sub

    Function Init(ByVal sw As SldWorks, ByVal addin As SwAddin) As Integer
        iSwApp = sw
        userAddin = addin
    End Function

    'Implement these methods from the interface
    Sub AfterClose() Implements PropertyManagerPage2Handler9.AfterClose
        ''This function must contain code, even if it does nothing, to prevent the
        ''.NET runtime environment from doing garbage collection at the wrong time.
        Dim IndentSize As Integer
        IndentSize = System.Diagnostics.Debug.IndentSize
        System.Diagnostics.Debug.WriteLine(IndentSize)

    End Sub

    Sub OnCheckboxCheck(ByVal id As Integer, ByVal status As Boolean) Implements PropertyManagerPage2Handler9.OnCheckboxCheck

    End Sub

    Sub OnClose(ByVal reason As Integer) Implements PropertyManagerPage2Handler9.OnClose
        ''This function must contain code, even if it does nothing, to prevent the
        ''.NET runtime environment from doing garbage collection at the wrong time.
        Dim IndentSize As Integer
        IndentSize = System.Diagnostics.Debug.IndentSize
        System.Diagnostics.Debug.WriteLine(IndentSize)
----------------------------------------------------------------------------------------------------------
'可以在这里写事件触发代码
        Dim swapp As SldWorks
        Dim part As ModelDoc2
        Dim boolstatus As Boolean
        Dim swsketchmanager As SketchManager
        Dim swfeaturemanager As FeatureManager

        swapp = CreateObject("SldWorks.Application")
        part = CType(swapp.ActiveDoc, ModelDoc2)
        swsketchmanager = part.SketchManager
        swfeaturemanager = part.FeatureManager

        '创建草图
        boolstatus = part.Extension.SelectByID2("前世基准面", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
        part.InsertSketch2(True)
        part.ClearSelection2(True)

        swsketchmanager.CreateCenterRectangle(0, 0, 0, Length, Width, 0)

        swfeaturemanager.FeatureExtrusion2(True, False, False, 0, 0, High, 0, False, False, False, False, 0.0174532925199433, 0.0174532925199433, False, False, False, False, True, True, True, 0, 0, False)
----------------------------------------------------------------------------------------------------------------
    End Sub

    Sub OnComboboxEditChanged(ByVal id As Integer, ByVal text As String) Implements PropertyManagerPage2Handler9.OnComboboxEditChanged

    End Sub

    Function OnActiveXControlCreated(ByVal id As Integer, ByVal status As Boolean) As Integer Implements PropertyManagerPage2Handler9.OnActiveXControlCreated
        OnActiveXControlCreated = -1
    End Function

    Sub OnButtonPress(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnButtonPress

    End Sub

    Sub OnComboboxSelectionChanged(ByVal id As Integer, ByVal item As Integer) Implements PropertyManagerPage2Handler9.OnComboboxSelectionChanged

    End Sub

    Sub OnGroupCheck(ByVal id As Integer, ByVal status As Boolean) Implements PropertyManagerPage2Handler9.OnGroupCheck

    End Sub

    Sub OnGroupExpand(ByVal id As Integer, ByVal status As Boolean) Implements PropertyManagerPage2Handler9.OnGroupExpand

    End Sub

    Function OnHelp() As Boolean Implements PropertyManagerPage2Handler9.OnHelp
        OnHelp = True
    End Function

    Sub OnListboxSelectionChanged(ByVal id As Integer, ByVal item As Integer) Implements PropertyManagerPage2Handler9.OnListboxSelectionChanged

    End Sub

    Function OnNextPage() As Boolean Implements PropertyManagerPage2Handler9.OnNextPage
        OnNextPage = True
    End Function

    Sub OnNumberboxChanged(ByVal id As Integer, ByVal val As Double) Implements PropertyManagerPage2Handler9.OnNumberboxChanged
--------------------------------------------------------------------------------------------------------
捕捉数字输入框的变化 ,id为在PMPage里定义的控件id
      If (id.Equals(3)) Then
            Length = val
        End If
        If (id.Equals(4)) Then
            Width = val
        End If
        If (id.Equals(5)) Then
            High = val
        End If
--------------------------------------------------------------------------------------------------------------
    End Sub

    Sub OnOptionCheck(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnOptionCheck

    End Sub

    Function OnPreviousPage() As Boolean Implements PropertyManagerPage2Handler9.OnPreviousPage
        OnPreviousPage = True
    End Function

    Sub OnSelectionboxCalloutCreated(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnSelectionboxCalloutCreated

    End Sub

    Sub OnSelectionboxCalloutDestroyed(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnSelectionboxCalloutDestroyed

    End Sub

    Sub OnSelectionboxFocusChanged(ByVal Id As Integer) Implements PropertyManagerPage2Handler9.OnSelectionboxFocusChanged

    End Sub

    Sub OnSelectionboxListChanged(ByVal id As Integer, ByVal item As Integer) Implements PropertyManagerPage2Handler9.OnSelectionboxListChanged

    End Sub

    Sub OnTextboxChanged(ByVal id As Integer, ByVal text As String) Implements PropertyManagerPage2Handler9.OnTextboxChanged

    End Sub

    Public Sub AfterActivation() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.AfterActivation

    End Sub

    Public Function OnKeystroke(ByVal Wparam As Integer, ByVal Message As Integer, ByVal Lparam As Integer, ByVal Id As Integer) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnKeystroke

    End Function

    Public Sub OnPopupMenuItem(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPopupMenuItem

    End Sub

    Public Sub OnPopupMenuItemUpdate(ByVal Id As Integer, ByRef retval As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPopupMenuItemUpdate

    End Sub

    Public Function OnPreview() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPreview
        OnPreview = True
    End Function

    Public Sub OnSliderPositionChanged(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSliderPositionChanged

    End Sub

    Public Sub OnSliderTrackingCompleted(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSliderTrackingCompleted

    End Sub

    Public Function OnSubmitSelection(ByVal Id As Integer, ByVal Selection As Object, ByVal SelType As Integer, ByRef ItemText As String) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSubmitSelection
        OnSubmitSelection = True
    End Function

    Public Function OnTabClicked(ByVal Id As Integer) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnTabClicked
        OnTabClicked = True
    End Function

    Public Sub OnUndo() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnUndo

    End Sub

    Public Sub OnWhatsNew() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnWhatsNew

    End Sub

    Function OnWindowFromHandleControlCreated(ByVal Id As Integer, ByVal Status As Boolean) As Integer Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnWindowFromHandleControlCreated

    End Function

    Sub OnGainedFocus(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGainedFocus

    End Sub

    Sub OnListboxRMBUp(ByVal Id As Integer, ByVal PosX As Integer, ByVal PosY As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnListboxRMBUp

    End Sub

    Sub OnLostFocus(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnLostFocus

    End Sub

    Sub OnRedo() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnRedo

    End Sub


    Sub OnNumberBoxTrackingCompleted(ByVal id As Integer, ByVal val As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNumberBoxTrackingCompleted

    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class

你可能感兴趣的:(solidworks二次开发VB.NET--属性页控件 事件触发函数)