Вставка элемента управления содержимым поля со списком в C# и .NET


     Содержит выпадающий список элементов списка, которые пользователи могут выбирать. В отличие от выпадающего списка, поле со списком позволяет пользователям вводить пользовательские входные данные.

Полный код

using System;
using System.Text;
using SautinSoft.Document;
using SautinSoft.Document.CustomMarkups;
using SautinSoft.Document.Drawing;
using System.IO;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            InsertCombobox();
        }
        /// <summary>
        /// Inserting a Combo Box content control.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/content-controls-insert-combobox-net-csharp-vb.php
        /// </remarks>

        static void InsertCombobox()
        {
            // Let's create a simple document.
            DocumentCore dc = new DocumentCore();

            // Create a Combo Box content control.
            InlineContentControl combobox = new InlineContentControl(dc, ContentControlType.ComboBox);
            dc.Sections.Add(new Section(dc, new Paragraph(dc, new Run(dc, "Combo Box "), combobox)));

            // Set common the content control properties.
            combobox.Properties.Title = "Combo Box";
            combobox.Properties.LockDeleting = true;
            combobox.Properties.CharacterFormat.FontColor = Color.Blue;

            // Add combox's list items.
            combobox.Properties.ListItems.Add(new ContentControlListItem("One", "1"));
            combobox.Properties.ListItems.Add(new ContentControlListItem("Two", "2"));
            combobox.Properties.ListItems.Add(new ContentControlListItem("Three", "3"));
            combobox.Properties.ListItems.Add(new ContentControlListItem("Four", "4"));

            // Set a default selected item.
            combobox.Properties.SelectedListItem = combobox.Properties.ListItems[2]; 

            // Save our document into DOCX format.
            string resultPath = @"result.docx";
            dc.Save(resultPath, new DocxSaveOptions());
			
            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultPath) { UseShellExecute = true });
        }
    }
}

Download

Imports System
Imports System.Text
Imports SautinSoft.Document
Imports SautinSoft.Document.CustomMarkups
Imports SautinSoft.Document.Drawing
Imports System.IO

Namespace Example
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			InsertCombobox()
		End Sub
                ''' Get your free 30-day key here:   
                ''' https://sautinsoft.com/start-for-free/
		''' <summary>
		''' Inserting a Combo Box content control.
		''' </summary>
		''' <remarks>
		''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/content-controls-insert-combobox-net-csharp-vb.php
		''' </remarks>

		Private Shared Sub InsertCombobox()
			' Let's create a simple document.
			Dim dc As New DocumentCore()

			' Create a Combo Box content control.
			Dim combobox As New InlineContentControl(dc, ContentControlType.ComboBox)
			dc.Sections.Add(New Section(dc, New Paragraph(dc, New Run(dc, "Combo Box "), combobox)))

			' Set common the content control properties.
			combobox.Properties.Title = "Combo Box"
			combobox.Properties.LockDeleting = True
			combobox.Properties.CharacterFormat.FontColor = Color.Blue

			' Add combox's list items.
			combobox.Properties.ListItems.Add(New ContentControlListItem("One", "1"))
			combobox.Properties.ListItems.Add(New ContentControlListItem("Two", "2"))
			combobox.Properties.ListItems.Add(New ContentControlListItem("Three", "3"))
			combobox.Properties.ListItems.Add(New ContentControlListItem("Four", "4"))

			' Set a default selected item.
			combobox.Properties.SelectedListItem = combobox.Properties.ListItems(2)

			' Save our document into DOCX format.
			Dim resultPath As String = "result.docx"
			dc.Save(resultPath, New DocxSaveOptions())

			' Open the result for demonstration purposes.
			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultPath) With {.UseShellExecute = True})
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.