Hi Dmitry
First of all THANKS for your reply.
Hi this is the code i am using.
Here when i click My_Bu any no. of times, it works. But if i go and
click other buttons after clicking My_Bu, other buttons didnt work.
If i start a fresh instance of outlook and if i go and click other
buttons it works fine even for multiple times.. If i click that My_Bu,
My_Bu works, then after other buttons didnt work.
Note: MyAn_Click displays frmView1 only for a single time.. Even if i
click next time it didnt work. frmView1 is an ordinary form without any
code or properties changed. Just had some controls.
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
string strTemp;
strTemp =
CreateToolBar((Microsoft.Office.Interop.Outlook.Ap plication)application)
;
}
//declare forms(developed in c#.net)
//frmInbox1 is displayed in MyBu_Click
//frmView1 is displayed in MyAn_Click
public View frmView1 = new View();
public frmInbox frmInbox1 = new frmInbox();
public string CreateToolBar(Microsoft.Office.Interop.Outlook.App lication
Application)
{
Microsoft.Office.Core.CommandBars oCommandBars;
Microsoft.Office.Core.CommandBar oStandardBar;
Microsoft.Office.Core.CommandBarButton MyBu;
Microsoft.Office.Core.CommandBarButton MyCo;
Microsoft.Office.Core.CommandBarButton MyAn;
Microsoft.Office.Core.CommandBarButton MyRe;
Microsoft.Office.Core.CommandBarButton MyOr;
try
{
oCommandBars =
(Microsoft.Office.Core.CommandBars)applicationObje ct.GetType().InvokeMem
ber("CommandBars", System.Reflection.BindingFlags.GetProperty , null,
applicationObject ,null);
}
catch(Exception)
{
// Outlook has the CommandBars collection on the Explorer object.
object oActiveExplorer;
oActiveExplorer=
applicationObject.GetType().InvokeMember("ActiveEx plorer",System.Reflect
ion.BindingFlags.GetProperty,null,applicationObjec t,null);
oCommandBars=
(Microsoft.Office.Core.CommandBars)oActiveExplorer .GetType().InvokeMembe
r("CommandBars",System.Reflection.BindingFlags.Get Property,null,oActiveE
xplorer,null);
}
try
{
oStandardBar =
oCommandBars.Add("Bar",Microsoft.Office.Core.MsoBa rPosition.msoBarTop
,null,false);
}
catch(Exception)
{
oStandardBar = oCommandBars["Database"];
}
// In case the button was not deleted, use the existing one.
try
{
MyBu =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["but1"];
MyCo =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyCo"];
MyAn =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyAn"];
MyRe =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyRe"];
MyOr =
(Microsoft.Office.Core.CommandBarButton)oStandardB ar.Controls["MyOr"];
}
catch(Exception)
{
object omissing = System.Reflection.Missing.Value ;
MyBu = (Microsoft.Office.Core.CommandBarButton)
oStandardBar.Controls.Add(1, omissing , omissing , omissing , omissing);
MyBu.Caption = "Button1";
MyBu.Style =
Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon AndCaption;
PrepareImage (strLookPath + @"res\1.ico");
MyBu.PasteFace ();
//similarly for all the buttons
}
try
{
MyBu.Tag = "Button1";
//similarly for all the buttons
MyBu.OnAction = "!<MyCOMAddin.Connect>";
//similarly for all the buttons
MyBu.Visible = true;
MyBu.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(this.MyB
u_Click);
//similarly for all the buttons
object oName =
applicationObject.GetType().InvokeMember("Name",Sy stem.Reflection.Bindin
gFlags.GetProperty,null,applicationObject,null);
oStandardBar = null;
oCommandBars = null;
return "success";
}
catch(System.Exception e)
{
return e.Message ;
}
}
private void MyBu_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
//showing a form - In this form am getting some inputs from client
frmSelection1.application = PubapplicationObject;
frmeSelection1.Top = 250;
frmeSelection1.Left = 250;
frmeSelection1.InitialStart();
frmSelection1.strSelectedName = "";
frmSelection1.ShowDialog ();
strName = frmSelection1.strSelectedName.ToString();
if (strName.Trim().ToString().Length > 0)
{
string strTmp = GetSelectedItem(PubapplicationObject);
}
try
{
if (SetUserWindowPosition() > 0)
{
//show another form - frmInbox, this form replaces the outlook
//listvew(where mails are listed in outlook)
frmInbox1.InitialStart();
frmInbox1.BringToFront();
frmInbox1.Show();
}
}
catch (System.Exception e)
{
System.Windows.Forms.MessageBox.Show ("Error: " + e.Message.ToString
());
}
}
private void MyAn_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
frmView1.ShowDialog();
}
private void MyCo_Click(Microsoft.Office.Core.CommandBarButton
cmdBarbutton,ref bool cancel)
{
System.Windows.Forms.MessageBox.Show("Co Clicked");
}
Anushya
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!