Use of the Text Processing Control TX Text Control, txtext

Source: Internet
Author: User
Tags lenovo

Use of the Text Processing Control TX Text Control, txtext

We have been studying the use of TX Text Control over the past few days. Due to the relatively small amount of data in this area, we mainly rely on the downloaded version of the case code for research and some official blog cases for study, I have summarized some of my experiences and I will summarize them for you to share and learn. This article describes how to use TX Text Control V20.

1. Introduction to the TX Text Control

TX Text Control is a function similar to MS Word Text processing controls, including document creation, editing, printing, mail merge, format conversion, split merge, Import Export, batch generation and other functions. It is widely used in enterprise document management, website content publishing, creation of medical record templates in electronic medical records, writing of medical records, modification history, continuous printing, and archiving of medical records.

The main function of this control is to use it as the editor for Word and other documents. Although there are some controls for displaying WORD content, for example, we can use the RTF document editor in DevExpress, it also runs well, combined with Aspose. for Word background document processing, we can generate similar report data and display and edit the generated documents.

Although TX Text Control performs well in all aspects of document editing, its MailMerge Mail Merge function is often used to merge our data and document templates, then, the final document content is displayed, which can be used to process and display invoices, emails, and employee information. MailMerge mail merge can bind the data in the Master/Slave table, can meet most of the requirements.

I originally wanted to use it as a function module similar to electronic medical records. It is difficult for us to handle some drop-down lists without mentioning it in the document (there is a simple case in the official blog, but it is not easy to use). In general, if we only perform regular operations such as document presentation and data merging, it is still very good.

This control function introduction, can refer to the grape city web page introduction (http://www.gcpowertools.com.cn/products/textcontrol_winform_features.htm), this control related developers use and then share the experience of the article few, most of the information that can be found on the Internet is a simple description of the Demo code of this control by uguicheng personnel, without further in-depth introduction and application scenarios. Although grape city lists several cases of electronic medical records, it is difficult for these companies to download their electronic medical records.

In the past few days, I have learned some of the features of this control, and have re-developed the document editing examples on the official website. I have developed a completely identical Editor Version, it also provides a deeper understanding of its attributes and methods.

First, let's look at some functions of the entire software through a software interface (this is a program I followed the official case ).

After this Control is installed by default, there will be many Demo cases. for details, refer to the directory C: \ Users \ Administrator \ Documents ents \ TX Text Control templates 0.net for Windows Forms \ Samples.

 

2. Convert TX Text Control to Chinese

By default, the control interface is in English, and the menus and prompts of the control are all in English. Therefore, we need to localize the resources in Chinese to display them correctly.

The Chinese translation package is not officially provided. Only one standard English resource is provided, as shown below.

What we need to do is to translate them into Chinese, and then recompile them (compile with buildres. bat script) as the Chinese Resource dll.

We first use the VS editing tool to convert these English resource records into English (this is a tedious task. There are some old Chinese packages on the official website for your reference, and the latest V20 software (editor software ).

We perform Chinese processing one by one. We can use Baidu and Google translation as well as a reference to the software interface.

Run the VS command line as an administrator and then run the command to compile the resource.

Buildres. bat zh-CN

After compilation is successful, two resource assemblies will be added to the directory.

Txdocumentserver. resources. dll

Txtextcontrol. resources. dll

Then copy it to the running directory and place it in the directory zh-CN. With the resource assembly in these cultures, we can use it to implement the culture of the built-in menu prompts of the control.

The operation in culture is the same as other conventional practices. In the Main function, add the following code.

Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");

Run the program. Right-click the menu and you will find that all the resources in the menu are in Chinese. Other built-in menus and interfaces can be seen in Chinese.

 

3. Use of TX Text Control

With localization, it is only the first step for us to normally use the control. We need to integrate the control in the program, so we need to use it and process the properties and events of the control, in order to get the best application results.

We add the corresponding controls in the VS toolbar. You can see that the following control objects are available. In general, TextControl is used, then, you can create other RulerBar, ButtonBar, and StatusBar Based on it. If you need to merge data (frequently used), you need to add the MailMerge control object.

After adding a widget, you can directly use the widget's API to copy, paste, and cut controls.

        private void menuEdit_Undo_Click(object sender, EventArgs e)        {            _textControl.Undo();        }        private void menuEdit_Redo_Click(object sender, EventArgs e)        {            _textControl.Redo();        }        private void menuEdit_Cut_Click(object sender, EventArgs e)        {            _textControl.Cut();        }

The search and replace dialog box can also be called up through API.

        private void menuEdit_Find_Click(object sender, EventArgs e)        {            _textControl.Find();        }        private void menuEdit_Replace_Click(object sender, EventArgs e)        {            _textControl.Replace();        }

Using these basic APIS is a common operation.

By inserting related objects, slices, text boxes, and so on, simple coding is required to add objects to TextControl objects.

        private void menuInsert_Image_Click(object sender, EventArgs e)        {            TXTextControl.Image imageNew = new TXTextControl.Image();            _textControl.Images.Add(imageNew, TXTextControl.HorizontalAlignment.Left, -1, TXTextControl.ImageInsertionMode.DisplaceText);        }        private void menuInsert_TextFrame_Click(object sender, EventArgs e)        {            try            {                // Force Exception if standard version:                _textControl.TextFrames.GetItem();                Size sizeTextFrame = new Size(2268, 2268);   // 4 x 4 cm                TXTextControl.TextFrame textFrameNew = new TXTextControl.TextFrame(sizeTextFrame);                _textControl.TextFrames.Add(textFrameNew, TXTextControl.HorizontalAlignment.Left, -1, TXTextControl.TextFrameInsertionMode.DisplaceCompleteLines);            }            catch (Exception ex)            {                MessageBox.Show(ex.Message, ProductName);            }        }

The most common control is MailMerge's data merging operation, which is also used to process many templated documents.

MailMerge objects Merge data, mainly to accept collection objects or able objects, so we must convert our data into this format, otherwise the merged data will not get the expected results.

The first step of data merging is to design a template, which is very important. The template design still follows the concept of a common word file domain object, you need to add some fields for object placeholders for subsequent data replacement. The following is a template I tested.

This is mainly a template for master-slave table integration. We need to bind the regular master table record and the set record of the detail table, however, we need to convert the data object to a set (such as DataSet) before binding it to the Document Object.

In the above document, you can see the domain object without seeing the start and end bookmarks of a hidden set record. For more information about the functions and operations of bookmarks, see my previous article "using Aspose. the Word control implements operations on Word documents, and the use of Aspose. word Control and Aspose. cell Control for templated export of Word documents and Excel documents

The role of bookmarks is very important. Otherwise, the records of the collection cannot be parsed and bound to the WORD interface. In the bookmarks dialog box, we can see that there are two positions in the above document, the start and end positions of the bookmarks.

In this way, after the template is designed, the second step is to generate relevant objects through code and then merge them with the document.

For example, I construct a master table and a slave table record to generate a DataSet object for use.

Public static DataSet CreateDataSet () {DataSet ds = new DataSet (); DataTable dtMain = DataTableHelper. createTable ("Company, HandNo, Creator, CreateTime | DateTime"); dtMain. tableName = "main"; DataRow dr = dtMain. newRow (); dr ["Company"] = "Guangzhou aiqidi Software Technology Co., Ltd."; dr ["HandNo"] = "123456 "; dr ["Creator"] = "Wu huacong"; dr ["CreateTime"] = DateTime. now; dtMain. rows. add (dr); DataTable dt = DataTableHelper. createTable ("ID, ProductName, Description, Price | decimal, Quantity | int"); dt. tableName = "ProductInfo"; dr = dt. newRow (); dr ["ID"] = "1"; dr ["ProductName"] = "hybriddb shampoo"; dr ["Description"] = "hybriddb shampoo, 550 "; dr [" Price "] = 19.8 M; dr [" Quantity "] = 100; dt. rows. add (dr); dr = dt. newRow (); dr ["ID"] = "2"; dr ["ProductName"] = "Lenovo brand computer "; dr ["Description"] = "Lenovo Y700-15ISK-ISE flagship"; dr ["Price"] = 6500 M; dr ["Quantity"] = 10; dt. rows. add (dr); dr = dt. newRow (); dr ["ID"] = "3"; dr ["ProductName"] = "IPhone7 128G"; dr ["Description"] = "Apple IPhone7, 128G "; dr [" Price "] = 5800 M; dr [" Quantity "] = 10; dt. rows. add (dr); ds. tables. add (dtMain); ds. tables. add (dt); return ds ;}

Load template document first

if (setting == null){    setting = new TXTextControl.LoadSettings();    setting.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord;}_textControl.Load(Application.StartupPath + "\\Template\\template1.docx", TXTextControl.StreamType.WordprocessingML, setting);

Integrate and merge data

DataSet ds = PurchaseInfoHelper.CreateDataSet();mailMerge1.MergeBlocks(ds);mailMerge1.Merge(ds.Tables["main"], true);

Finally, we can see the results we need.

Of course, if you are familiar with Aspose. the use of the Word control, we can also use Aspose. the Word control is used for data integration in the background, Aspose. the Word control supports many variable definitions and more complex processing. For example, I extracted the original staff information in the framework module from the Word function, which was originally implemented using Aspose. word to process data merging. I Don't modify the logic, just display the merged data in TX Text Control, as shown in the following code.

Var saveFile = StaffHelper. GenerateDoc (); // Load doc_textcontrol. Load (saveFile, StreamType. MSWord );

Finally, the software interface effect we introduced was generated.

This control is currently quite good, but for some data source processing, we hope to add more interfaces and continue to observe, it is hoped that the research results will be used on specific projects.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.