private void AddBuildingBlockControlAtRange() { this.Paragraphs[1].Range.InsertParagraphBefore(); buildingBlockControl2 = this.Controls.AddBuildingBlockGalleryContentControl( this.Paragraphs[1].Range, "buildingBlockControl2"); buildingBlockControl2.PlaceholderText = "Choose an equation"; buildingBlockControl2.BuildingBlockCategory = "Built-In"; buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeEquations; }
private void CreateBuildingBlockControlsFromNativeControls() { if (this.ContentControls.Count <= 0) { return; } buildingBlockControls = new System.Collections.Generic.List <Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl>(); int count = 0; foreach (Word.ContentControl nativeControl in this.ContentControls) { if (nativeControl.Type == Word.WdContentControlType.wdContentControlBuildingBlockGallery) { count++; Microsoft.Office.Tools.Word.BuildingBlockGalleryContentControl tempControl = this.Controls.AddBuildingBlockGalleryContentControl(nativeControl, "VSTOBuildingBlockContentControl" + count.ToString()); buildingBlockControls.Add(tempControl); } } }
//</Snippet1> private void ThisDocument_Startup(object sender, System.EventArgs e) { try { //<Snippet2> comboBoxContentControl1.PlaceholderText = "Choose a title, or enter your own"; comboBoxContentControl1.DropDownListEntries.Add("Engineer", "Engineer", 0); comboBoxContentControl1.DropDownListEntries.Add("Designer", "Designer", 1); comboBoxContentControl1.DropDownListEntries.Add("Manager", "Manager", 2); dropDownListContentControl1.PlaceholderText = "Choose a rating (1 lowest, 3 highest)"; dropDownListContentControl1.DropDownListEntries.Add("1", "1", 0); dropDownListContentControl1.DropDownListEntries.Add("2", "2", 1); dropDownListContentControl1.DropDownListEntries.Add("3", "3", 2); //</Snippet2> //<Snippet3> this.Tables[1].Range.Select(); groupControl1 = this.Controls.AddGroupContentControl("groupControl1"); //</Snippet3> //<Snippet4> Word.Template template1 = this.AttachedTemplate as Word.Template; if (template1 != null) { object description = null; template1.BuildingBlockEntries.Add("Employee Table", Word.WdBuildingBlockTypes.wdTypeCustom1, "Employee and Customer Information", this.Tables[1].Range, ref description, Word.WdDocPartInsertOptions.wdInsertContent); template1.BuildingBlockEntries.Add("Customer Table", Word.WdBuildingBlockTypes.wdTypeCustom1, "Employee and Customer Information", this.Tables[2].Range, ref description, Word.WdDocPartInsertOptions.wdInsertContent); } //</Snippet4> //<Snippet5> if (!this.FormsDesign) { this.ToggleFormsDesign(); } this.Tables[2].Delete(); this.Tables[1].Delete(); this.ToggleFormsDesign(); //</Snippet5> //<Snippet6> buildingBlockControl1 = this.Controls.AddBuildingBlockGalleryContentControl( this.Paragraphs[1].Range, "buildingBlockControl1"); buildingBlockControl1.BuildingBlockCategory = "Employee and Customer Information"; buildingBlockControl1.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeCustom1; buildingBlockControl1.PlaceholderText = "Choose your first building block"; buildingBlockControl2 = this.Controls.AddBuildingBlockGalleryContentControl( this.Paragraphs[2].Range, "buildingBlockControl2"); buildingBlockControl2.BuildingBlockCategory = "Employee and Customer Information"; buildingBlockControl2.BuildingBlockType = Word.WdBuildingBlockTypes.wdTypeCustom1; buildingBlockControl2.PlaceholderText = "Choose your second building block"; //</Snippet6> } catch (Exception ex) { MessageBox.Show(ex.Message); } }