Join LiveSide!
Sign In using: Name/Password OpenID
or Live ID: Sign In Live ID
0 out of 8,444 members
are online, & 54 guest(s).

Recent Comments

–Kaol
re: Writing Plugins For Windows Live Writer - Working With Forms

–ScottIsAFool
re: Writing Plugins For Windows Live Writer - Working With Forms

–Kaol
re: Writing Plugins For Windows Live Writer - Working With Forms

Log in or Join to leave a comment!

LiveSide on Mobile

Our latest posts and our favorite links,
all on your phone or mobile device
Visit m.LiveSide.net
Or go to www.LiveSide.net
on your mobile device and we'll redirect you!

Tweets We Like

Loading...

LiveSide Time

Redmond

Dallas (server)

London

Shanghai

Windows Live Calendar

Follow us on Facebook

    LiveSide.net
   
    Promote Your Page Too

  • LiveSide on the Windows Live Network
  • LiveSide on Facebook
  • LiveSide on Twitter
  • LiveSide RSS  
  • Windows Live Alerts
  •  
  • feedburner
  •  
LiveSide - Developer Blog

Writing Plugins For Windows Live Writer - Working With Forms

Most plugins for Live Writer will have a form appear when you click on the Insert link within Live Writer, this form will perform the functionality of the plugin and return the code or text that will be put in the blog entry. Within this form, you can do whatever you want the plugin to do, but for this example I will be keeping it simple and showing the basics, letting you code the rest of the plugin and change whatever settings for your form that you want.

Open up your project (I will be continuing with the "MyNewPlugin" example from the previous posts), and create a new form in your project (for this example I will be calling the form frmMyForm). For this example, my form will have only a text box, an insert button and a cancel button, and all it will do is allow the user to enter some text and have it appear in the blog entry when you press insert. In your form, add a textbox and two buttons (I have also added a label to describe what the textbox does), you should have something like this:

Any other properties of this form can be changed as you wish. Except for the textbox which I have called txbxText, I have kept all the original names that get given when the form items are created.

Now we need to tell the buttons what they are going to be done. We'll start with the cancel button; in the properties of the form, there is a property called CancelButton, just set that to be the cancel button (in this case Button2). For the Insert button, double click it and Visual Studio will create the method for you, we can then add our code into that method. Before we do this though, at the top of the Class (before the initializing method), we need to declare a string variable, so just put in string text;.

In this plugin, all we need to do for the Insert button is assign the DialogResult value, set the text and close the form. So the code we need to put in is:

            DialogResult = DialogResult.OK;
            text = txbxText.Text;
            this.Close();

Note how we are assigning the text string to equal the text from the textbox. The last thing we need to do for this plugin is just create a string method that returns the text string, this will be called later from the main plugin class.

        public string getText
        {
            get { return text; }
        }

Now, in the main class where we overrode the CreateContent method, we need to add in a new section, so before we had just newContent = "Some text"; we now need to tell the plugin that we want to use our new form:

using (frmMyForm form = new frmMyForm())
            {

Now, you might remember in the last post that I mentioned about the DialogResult section (and I also touch upon it above), this is where it actually comes in to play. Once we have told the plugin to use the form, we need to create a new DialogResult that opens up our newly called form, so we insert the next line:

                DialogResult result = form.ShowDialog();

In the form when we click on the Insert button, we set the DialogResult to equal DialogResult.OK, this signifies that an OK was pressed in a dialog, so we can check for this by using an if statement. Within that if statement, we are going to set the newContent value to equal the getText string from the form:

                if (result == DialogResult.OK)
                {
                    newContent = "You entered: " + form.getText + ".";
                }

We now need to close off all open sections (using a } ) . Hopefully you can see where everything falls into place, form.getText is the public string that we set to return the text string in the form, and the text string gets the value of the textbox, which is what finally gets inserted into the blog entry.

Any questions about this post please feel free to leave a comment, as this one is a little more involved that the previous two steps.

Download Source Code: here.

SL

<< Previous - Adding An Icon

Comments

Writing Plugins For Windows Live Writer - Working With Forms » Dee’s-Planet! Blog wrote Writing Plugins For Windows Live Writer - Working With Forms &raquo; Dee&#8217;s-Planet! Blog
on Fri, Oct 20 2006 12:20 AM
Kaol wrote re: Writing Plugins For Windows Live Writer - Working With Forms
on Fri, Oct 20 2006 8:17 AM

ScottIsAFool, when I builded it, Visual Studio tell me that it can't find type or namespace. Why?

ScottIsAFool wrote re: Writing Plugins For Windows Live Writer - Working With Forms
on Fri, Oct 20 2006 8:48 AM

Does it give any more information? What type or namespace can it not find?

Kaol wrote re: Writing Plugins For Windows Live Writer - Working With Forms
on Sun, Oct 22 2006 2:59 AM

I have resolved this problem. Thanks. Your tutorial is very good. I'm looking forward to the next one.

Developer wrote Writing Plugins For Windows Live Writer - Adding An Icon
on Sun, Oct 29 2006 5:37 PM

Ok, so now that we have the basis for our Live Writer plugin, we need to start adding things to it to make it look and feel better. The best way is to add an image to the plugin that will appear in the Insert section of Writer.

LiveSide - Developer Blog wrote Writing Plugins For Windows Live Writer - Using Settings In Your Plugin
on Sun, Apr 22 2007 9:44 PM

So far I've shown you how to create basic plugins for Windows Live Writer , in this next guide I'm going to show you how you can use settings in your plugin to make things easier for your end user, you can create default options (that they can customise

LiveSide - Developer Blog wrote Writing Windows Live Writer Plugins - A Recap
on Tue, Oct 23 2007 8:33 PM

There was a comment left on my most recent plugin guide: &quot;I would love to see a guide on how to

?????? Windows Live Writer ?????? - ?????? - LiveSino - LiveSide ????????? wrote ?????? Windows Live Writer ?????? - ?????? - LiveSino - LiveSide ?????????
on Wed, Oct 24 2007 12:08 PM

Pingback from  ?????? Windows Live Writer ?????? - ??????  -  LiveSino - LiveSide ?????????

Sign In Live ID using Live ID, Name/Password, or OpenID
or Join LiveSide to leave a comment!