Autor Beitrag
CSharp_Anfänger
Hält's aus hier
Beiträge: 6



BeitragVerfasst: So 18.01.09 13:36 
Hi,

ich habe zwei Fragen:

Ich erstelle mit unten stehendem Code einen Button,
wie schaffe ich es dass der Button nur erscheint wenn der User eine neue Besprechung aufmachen möchte?

Im Anhang habe ich ein Bild eingefügt, wo ich ihn gerne hätte.

Button erstellen:
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
    public class Connect : Object, Extensibility.IDTExtensibility2
    {
        private CommandBarButton MyButton;
        /// <summary>
        ///    Implements the constructor for the Add-in object.
        ///    Place your initialization code within this method.
        /// </summary>
        public Connect()
        {
        }
        public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            applicationObject = application;
            addInInstance = addInInst;

            if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
            {
                OnStartupComplete(ref custom);
            }

        }

        public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
        {
            if (disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
            {
                OnBeginShutdown(ref custom);
            }
            applicationObject = null;
        }


        public void OnAddInsUpdate(ref System.Array custom)
        {
        }

        public void OnStartupComplete(ref System.Array custom)
        {
            CommandBars oCommandBars;
            CommandBar oStandardBar;

            try
            {
                oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, applicationObject, null);
            }
            catch (Exception)
            {
                // Outlook has the CommandBars collection on the Explorer object.
                object oActiveExplorer;
                oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);
                oCommandBars = (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
            }

            // Set up a custom button on the "Standard" commandbar.
            try
            {
                oStandardBar = oCommandBars["Standard"];
            }
            catch (Exception)
            {
                // Access names its main toolbar Database.
                oStandardBar = oCommandBars["Database"];
            }

            // In case the button was not deleted, use the exiting one.
            try
            {
                MyButton = (CommandBarButton)oStandardBar.Controls["Open Meetings"];
            }
            catch (Exception)
            {
                object omissing = System.Reflection.Missing.Value;
                MyButton = (CommandBarButton)oStandardBar.Controls.Add(1, omissing, omissing, omissing, omissing);
                MyButton.Caption = "Open Meetings";
                MyButton.Style = MsoButtonStyle.msoButtonCaption;
            }

            // The following items are optional, but recommended. 
            //The Tag property lets you quickly find the control 
            //and helps MSO keep track of it when more than
            //one application window is visible. The property is required
            //by some Office applications and should be provided.
            MyButton.Tag = "Open Meetings";

            // The OnAction property is optional but recommended. 
            //It should be set to the ProgID of the add-in, so that if
            //the add-in is not loaded when a user presses the button,
            //MSO loads the add-in automatically and then raises
            //the Click event for the add-in to handle. 
            MyButton.OnAction = "!<MyCOMAddin.Connect>";

            MyButton.Visible = true;
            MyButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.MyButton_Click);


            object oName = applicationObject.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, applicationObject, null);

            oStandardBar = null;
            oCommandBars = null;
        }

        public void OnBeginShutdown(ref System.Array custom)
        {

        }

        private void MyButton_Click(CommandBarButton cmdBarbutton, ref bool cancel)
        {
            Form MainPage = new MainPage();
            MainPage.Show();
        }


        private object applicationObject;
        private object addInInstance;
    }
}


Moderiert von user profile iconKha: Code- durch C#-Tags ersetzt
Einloggen, um Attachments anzusehen!