none
How can I use the Button I make on a Document at run-time from VSTO Word AddIn. RRS feed

  • Question

  • Hi, here comes the beginner again.

    I confirmed that the following codes working fine with me;

    Document  DoCuMeNT = Globals.Factory.GetVstoObject( Globals.ThisAddIn.Application.ActiveDocument );
    Microsoft.Office.Tools.Word.Controls.Button  BuTToN ;                    
    DoCuMeNT.Paragraphs[1].Range.InsertParagraphBefore();
    BuTToN  =  DoCuMeNT.Controls.AddButton( DoCuMeNT.Paragraphs[1].Range, 120, 28, "BuTTon1" );
    BuTToN.Text = "Testing...";

    Thanks for the MSDN !!

    But, that is all.

    Can you tell me how to use the button?

    Now, I click it, it makes not any kind of action, it is just out there smiling at me.

    Thanks






    Friday, February 27, 2015 2:33 AM

Answers

  • God.

    All I need are followings;

    That is soo siimple.

    But, that was looong way for me.

    The first line I needed (I knew it earlier, but not clearly/properly). BuTToN.Click += new EventHandler(BuTToN_KLiCK);

    The Second (last) line I needed (I knew it earlier, but not clearly/properly).

    private void BuTToN_KLiCK(object sender, EventArgs e)

    That is it.

    Case closed.

    Thanks millions.


    Sunday, March 15, 2015 6:59 AM

All replies

  • At least you need to subscribe to the Click event of the Button control.

    You can find the Button class described in MSDN.

    Friday, February 27, 2015 9:44 AM
  • Thanks Eugene Astafiev.

    Thanks for your reply.

    .

    The information you gave to me, All of them, I checked out already,

    And had found no way to use it by myself.

    That is why I started this post.

    .

    I am sorry to say this, but, I need more specific code.

    Regards

    Friday, February 27, 2015 12:15 PM
  • OK

    Now I understand that I have to write (manually) two more things. .

    First, I need to write a Mehod.

    Following is just trying.. trying.. and trying..

    I'm a very beginner.

    I wrote it within the file name under "Ribbon1.cs". .

    private void  BuTTon1_Click(object sender, EventArgs e)     

    {         

    MessageBox.Show( "ACTiON");     

    }

    .

    Second, I need to wirte event Something.

    I wrote it within the file name under "Ribbon1.Designer.cs".

    this.BuTTon1.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler( this.BuTTon1_Click );

    .

    Yes, I clearly know that it's NOT going to work.

    But, That is all I can do for now.

    Please help.

    I have to know "Where" and "What" to write.

    I guess the general procedure of mine is not so wrong.

    .

    Regards


    Friday, March 13, 2015 1:43 PM
  • Where is the button come from? Are you talking about the Fluent UI controls?
    Friday, March 13, 2015 1:51 PM
  • Wow..

    Light speed reply !

    Thanks.

    .

    I am making a screen shot.

    Because to write the right question with right "naming" of the all and every elements is so hard to me.

    .

    Regards

    Friday, March 13, 2015 2:03 PM
  • Shot 01

    This is my VSTO Word Ribbon AddiN

    I have "button 12" (Cloud one) here.

    .

    Shot 02

    This is source code of "button 12" name under "Ribbon1.cs*".

    And above it, I have "BuTToN1_Click" method for document_level button click event.

    .

    Shot 03

    This is source code of soem event(? or something like that). "BuTToN" click event under "Ribbon1.Designer.cs*".

    I know it is stupid one. But, that is all I can do right now.

    .

    Shot 04

    Yes, It works perfectly. But, I don't know how to handle/use the click button (Hellow Button) event from now on.

     

    Regards

     

     

    Friday, March 13, 2015 2:27 PM
  • Friday, March 13, 2015 2:27 PM
  • Friday, March 13, 2015 2:28 PM
  • Friday, March 13, 2015 2:28 PM
  • This is MS Word 2010 (Not Visual studio)

    I have two(2) buttons here.

    One is on the Ribbon (cloud one). Its official name is "button12"

    The other one in on the document (and will have lots of them, IF I am lucky to have a right answer here).

    This screen shot is the next moment I clicked the former one.

    Now I am wondering how to handle the later one's click event.

    Thanks..



    Friday, March 13, 2015 2:28 PM
  • I am going to make lots of buttons within a/some document via programattically.

    (It has related with final result_list of a/many documents.)

    And

    Each of button (If I click it) has to open another document individully different one.

    That is to say;

    If I click #1 button, it opens #1 document (it is somewhere else)

    If I click #2 button, it opens #2 document(it is some other place.)

    And so on. Maybe it could be some hundreads of it.

    .

    That is all I want.

    (I am not going to ask full codes here,

    I am trying to break my small walls one by one.

    Now it is "click event".)

    .

    Regards



    Friday, March 13, 2015 2:35 PM
  • Woww,,

    Now, I have ten (10) buttons on the Document using VSTO Word Ribbon Button Click.

    So, What do I have to do from now on ?

    I want to make the each and every VuTToN click event(s).

    Plaese show me the way.

    Regards




    Saturday, March 14, 2015 3:56 PM
  • Saturday, March 14, 2015 3:56 PM
  • If making the VuTToN click events programatically is so hard,

    Just tell me how to make only one VuTToN click event.

    I have to make the way by myself anyways.

    Regards.

    Saturday, March 14, 2015 4:06 PM
  • God.

    All I need are followings;

    That is soo siimple.

    But, that was looong way for me.

    The first line I needed (I knew it earlier, but not clearly/properly). BuTToN.Click += new EventHandler(BuTToN_KLiCK);

    The Second (last) line I needed (I knew it earlier, but not clearly/properly).

    private void BuTToN_KLiCK(object sender, EventArgs e)

    That is it.

    Case closed.

    Thanks millions.


    Sunday, March 15, 2015 6:59 AM