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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,937评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,503评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,712评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,668评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,677评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,601评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,975评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,637评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,881评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,621评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,710评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,387评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,971评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,947评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,189评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,805评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,449评论 2 342

推荐阅读更多精彩内容