How to write a text editor in C #

Source: Internet
Author: User
Tags object serialization

Objective

Younger brother from the university began to contact programming also has 6 years, work 4 years is also dry programming of live, see a lot of procedures, they have made many, in the school programming oneself think is to do art, in fact, play some games, such as civilization, such as the Pharaoh StarCraft from some point of view is also engaged in art, looking at their own painstakingly built buildings and personnel from less to more , from simple to complex, with some sense of accomplishment in mind. Programming is the same, the program from dozens of lines written to tens of thousands of lines, functions from Hellowword to quite complex and powerful, the heart also has a lot of sense of achievement.

After graduating from work, only gradually realized that software development is essentially a tool, this tool for others or their own use. With tools, many problems can be solved by the blade. So the programmer and the Mason Blacksmith Carpenter are the same kind of people. But nothing, programmers are not superior, people in society, seriously really work on the line.

Problem

Don't say much nonsense, now talk about the question of the title, how to write a text editor in C #. I was fortunate enough to have developed a more complex text editor, so it's a bit of experience to share. The text editor you refer to here is not simply a single or multiple-line edit box like Windows, but a text editor similar to Word.

Rough Look, an editor what is difficult, in fact, because we think that the easy thing for the computer is really a big problem. For example, we often surf the Internet, you can find that in recent years many Web site login In addition to the user name and password to enter the so-called verification code, and the verification code is next to the input box crooked draw out, just like a student in a dirty paper written on the same, this is only to prevent the program to simulate login, Because the crooked text human can easily identify, and the computer is very not easy to identify.

Example: Registered Hotmail uses the authentication code, its display character is 8uv9bkyr.

A text editor mainly handles problems with

The definition of the file save format, whether the document is saved in text or binary format, and what information is stored in each unit of information in the document. Document formatting is important.

and document storage System communication, that is, the function of saving and loading documents, where the document storage system can be operating system file subsystem, database, network, in fact, the file format set, a variety of document storage system is not very different.

Document object Maintenance after it is loaded, in the face of more complex document processing, the need to use object-oriented programming ideas, careful analysis of the document structure, the loading of the document data a little bit dismembered, each of the smallest indivisible document data into an object, and then use an object tree to save the content of the document hierarchy, This constructs a Document object tree. Document editing is the task of maintaining this Document object tree.

Document object Layout, document loading requires processing the entire Document object tree, calculating the display size of each object, and then arranging the objects to be displayed in the view area, including calculations for paragraphs and document lines, and then calculating the coordinate parameters of the object in the View area.

The drawing of the document, which includes drawing the contents of the document on the computer screen and drawing on the printer. Based on the coordinates of the calculated object in the view area, the program makes some coordinate transformations, drawing objects on the graphics output object, such as drawing a text or picture. Because. NET Framework, the operating screen and printer are based on GDI +, there is no essential difference, so some of the processing of the drawing code can draw the screen, you can draw the printer. Drawing documents on the screen is also particularly needed to optimize and minimize flicker.

Environment message processing, environment message refers to some Windows messages, these messages should change the contents of the document, such as mouse keyboard messages, the system pasteboard related messages. The program processes these messages, modifies the Document object tree, inserts deletes or modifies the document element object to the object tree. After the Document object tree changes, you need to rearrange the document, handle paragraph calculations and document line calculations, recalculate the position of the object in the View area, and then refresh the screen display as needed. In addition, the user also has to process the document content when it is selected.

The document is saved, and the program generates some data based on the Document object tree and then saves it to the document storage system, which can be thought of as object serialization.

The openness of the application, providing two development capabilities, and providing functionality similar to VBA

A complete function of the text editor structure is very complex, the problem involved is very broad, no tens of thousands of lines of code is uncertain, these issues in this article is impossible to list and discuss, this has to pick some focus to say.

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.