官术网_书友最值得收藏!

Creating our first example

In our first example, we will make you more comfortable, by explaining the Hello World example using Visual Studio 2008 and Microsoft Office InfoPath 2007.

Let's write a Hello World program as our first program, using VSTO 3.0 for Microsoft InfoPath 2007.

  1. Open Visual Studio 2008, and create a new InfoPath 2007 Form template project.
  2. Select New project. Under Office, select 2007 and then select InfoPath 2007 Form template, and name the project as per your requirements.
  3. Next, the Design Template dialog box appears. This is where you choose the template for your design requirement. In our example, we will select Blank and click on OK.
  4. The solution will be created with all of supporting files for our development of InfoPath solution. Let's write a Hello World message on a button click event for an InfoPath form. In the design task pane of the Visual Studio window, you can find the Controls button hyper linked. The following screenshot shows the InfoPath Design Task Pane inside Visual Studio.
    Creating our first example
  5. Next drag-and-drop a textbox to display the Hello World message and a button to write the Click event for, from InfoPath toolbox. The next image represents the InfoPath Toolbox Task Pane showing the InfoPath-supported controls.
    Creating our first example
  6. Right-click on the button and select Button Properties from the shortcut menu. In the Button Properties window, click on the Edit Form Code button under the General tab. This will generate the Click event for the button.
  7. Add the following code into the control's Click event:
    public void Click_Clicked(object sender, ClickedEventArgs e)
    {
    // Read the Textbox and write the "Hello World"
    XPathNavigator xNode = MainDataSource.CreateNavigator(). SelectSingleNode("/my:myFields/my:field1", NamespaceManager);
    // Set value to Textbox
    xNode.SetValue("Hello World");
    }
    

Once you have added and executed the above code, you will get the following screenshot as the output.

Creating our first example
主站蜘蛛池模板: 大荔县| 贺兰县| 浦城县| 淮南市| 宁都县| 藁城市| 定州市| 林口县| 朔州市| 收藏| 家居| 黔南| 嘉鱼县| 连江县| 彭泽县| 兴隆县| 青神县| 伊金霍洛旗| 保靖县| 彰武县| 宜川县| 汽车| 万安县| 嘉荫县| 油尖旺区| 永州市| 富源县| 温州市| 康保县| 墨竹工卡县| 芷江| 太和县| 泸州市| 万盛区| 石楼县| 湘潭县| 南丰县| 尼玛县| 东宁县| 利川市| 凤冈县|