Hide Table of Contents

Set Focus on PropertyManager Page Control Example (C#)

This example shows how to set focus on a Propertymanager page control.

//---------------------------------------------------------------------------

// Preconditions:

//  1. Open a model document.

//  2. Copy Module - Main to your project.

//  3. Copy Class Modules - clsPropMgr to a class module in your project.

//  4. Add a reference to the SolidWorks.Interop.swpublished primary interop

//     assembly (in the IDE, right-click the name of the project,

//     select Add Reference, and select SolidWorks.Interop.swpublished).

//  5. Open the Immediate window.

//  6. Run the macro.

//

// Postconditions:

//  1. PropertyManager page is created and displayed.

//  2. Select the checkbox to set focus on Text box.

//     Verification printed to Immediate window.

//  3. Deselect the checkbox to remove focus from Text box.

//     Verification printed to Immediate window.

//---------------------------------------------------------------------------

// Module - Main

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace CreatePropertyManagerPageExample_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        public ModelDoc2 Part;

        public clsPropMgr pm;

        public void Main()

        {

            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swStopDebuggingVstaOnExit, false);

            Part = (ModelDoc2)swApp.ActiveDoc;

 

            //Create a new instance of the PropertyManager class

            pm = new clsPropMgr(swApp);

            pm.Show();

        }

        public SldWorks swApp;

    }

}

Back to top

// Class Modules - clsPropMgr

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using SolidWorks.Interop.swpublished;

using System;

using System.Runtime.InteropServices;

using System.Diagnostics;

 

namespace CreatePropertyManagerPageExample_CSharp.csproj

{

    [ComVisibleAttribute(true)]

    public class clsPropMgr : PropertyManagerPage2Handler7

    {

        //General objects required for the PropertyManager page

        PropertyManagerPage2 pm_Page;

        PropertyManagerPageGroup pm_Groupbox;

        PropertyManagerPageCheckbox pm_Checkbox;

        PropertyManagerPageTextbox pm_Textbox;

 

        //Each object in the page needs a unique ID

        const int groupboxID = 1;

        const int checkboxID = 2;

        const int textboxID = 3;

        public void Show()

        {

            pm_Page.Show2(0);

        }

        //The following runs when a new instance

        //of the class is created

        public clsPropMgr(SldWorks swApp)

        {

            string pageTitle = null;

            string caption = null;

            long options = 0;

            int errors = 0;

            int control = 0;

            int alignment = 0;

            //Set the variables for the page

            pageTitle = "Test focus methods";

            options = (int)swPropertyManagerButtonTypes_e.swPropertyManager_OkayButton + (int)swPropertyManagerButtonTypes_e.swPropertyManager_CancelButton + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage + (int)swPropertyManagerPageOptions_e.swPropertyManagerOptions_PushpinButton;

            

            //Create the PropertyManager page

            pm_Page = (PropertyManagerPage2)swApp.CreatePropertyManagerPage(pageTitle, (int)options, this, ref errors);

            //Make sure that the page was created properly

            if (errors == (int)swPropertyManagerPageStatus_e.swPropertyManagerPage_Okay)

            {

                //Begin adding the controls to the page

 

                //Create the group box

                caption = "Group box";

                options = (int)swAddGroupBoxOptions_e.swGroupBoxOptions_Visible + (int)swAddGroupBoxOptions_e.swGroupBoxOptions_Expanded;

                pm_Groupbox = (PropertyManagerPageGroup)pm_Page.AddGroupBox(groupboxID, caption, (int)options);

 

                // Create a checkbox

                control = (int)swPropertyManagerPageControlType_e.swControlType_Checkbox;

                caption = "Focus on text box";

                alignment = (int)swPropertyManagerPageControlLeftAlign_e.swControlAlign_LeftEdge;

                options = (int)swAddControlOptions_e.swControlOptions_Visible + (int)swAddControlOptions_e.swControlOptions_Enabled;

                pm_Checkbox = (PropertyManagerPageCheckbox)pm_Groupbox.AddControl(checkboxID, (short)control, caption, (short)alignment, (int)options, "");

                pm_Checkbox.Checked = false;

 

                // Create a text box

                control = (int)swPropertyManagerPageControlType_e.swControlType_Textbox;

                caption = "Text box";

                pm_Textbox = (PropertyManagerPageTextbox)pm_Groupbox.AddControl(textboxID, (short)control, caption, (short)alignment, (int)options, "");

                }

            else

            {

                //If the page is not created

                System.Windows.Forms.MessageBox.Show("An error occurred while attempting to create the " + "PropertyManager page");

            }

        }

 

        #region IPropertyManagerPage2Handler7 Members

        void IPropertyManagerPage2Handler7.AfterActivation()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.AfterClose()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        int IPropertyManagerPage2Handler7.OnActiveXControlCreated(int Id, bool Status)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnButtonPress(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnCheckboxCheck(int Id, bool Checked)

        {

            // Set focus on the text box when checkbox is selected

            if (Checked)

            {

                pm_Page.SetFocus(textboxID);

                Debug.Print ("Focus on Text box.");

            }

            else

            {

                Debug.Print ("Focus off Text box.");

            }

        }

        void IPropertyManagerPage2Handler7.OnClose(int Reason)

        {

            if (Reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Cancel)

            {

                //Do something when the cancel button is clicked

            }

            else if (Reason == (int)swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)

            {

                //Do something else when the OK button is clicked

            }

        }

        void IPropertyManagerPage2Handler7.OnComboboxEditChanged(int Id, string Text)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnComboboxSelectionChanged(int Id, int Item)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnGainedFocus(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnGroupCheck(int Id, bool Checked)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnGroupExpand(int Id, bool Expanded)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnHelp()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnKeystroke(int Wparam, int Message, int Lparam, int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnListboxSelectionChanged(int Id, int Item)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnLostFocus(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnNextPage()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnNumberboxChanged(int Id, double Value)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnOptionCheck(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnPopupMenuItem(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnPopupMenuItemUpdate(int Id, ref int retval)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnPreview()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnPreviousPage()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnRedo()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnSelectionboxCalloutCreated(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnSelectionboxCalloutDestroyed(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnSelectionboxFocusChanged(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnSelectionboxListChanged(int Id, int Count)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnSliderPositionChanged(int Id, double Value)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnSliderTrackingCompleted(int Id, double Value)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnSubmitSelection(int Id, object Selection, int SelType, ref string ItemText)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        bool IPropertyManagerPage2Handler7.OnTabClicked(int Id)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnTextboxChanged(int Id, string Text)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnUndo()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        void IPropertyManagerPage2Handler7.OnWhatsNew()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        #endregion

    }

}

Back to top

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Set Focus on PropertyManager Page Control Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2010 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.