C # program diary
------ This is an article, it is written to our school's BBS. At that time, I just entered the big three, and the tone is a bit fun? :) Now the third is to end, I really miss the time ... But I wish you a happy learning, should you still have no problem?
Learn to suffer, there is also a happy. Simple, share with you; and, as usual, eager for your participation - don't let me call too long? I am eager, because I like to be full of life, I like a group of people for ideals and enthusiastic, while burning days, I like my seniors to go, leave their encouragement to me - I will think when I walk I told me all the happiness, pain, joy, and depressed, I am happy to watch them on my foundation, go faster, better! Oh, come, let's work together, we have a cup for our cause! !
Everyone see the C # program, if it is .NET, better look. Such a comment is an XML style that makes the program itself is a good document: ///
This procedure, although it is simple, it is worth talking about it. Oh, if you like, you may wish to follow your post. But first, I ask you a few weak :).
1, the document application of the VC is a typical view structure. Start the frame, so many categories, beginners tend to be confused, huh, can you tell me how it is packaged? 2, everyone writes the drawing function in the vc's onDraw function, but you will find that when the form minimizes or such events, the open graph is resembled, recursively draw, and occupy certain graphics. This is more clear to discover this. why? 3, I have done such an attempt, do the background diagram, then edit the text on the background chart. For example, I started to make a letter paper, typing in the letter paper, I feel very comfortable. I think the lines of the letter paper should be painted, in .. viEW with CDC pointer; perhaps, I have no experience, I do it. However, the input of the text will change the position of the graphic; then use the Ontime non-stop, it is good, very happy. However, when the font difference is too large, or when scrolling occurs in the editing area, it will be a mess. What should you think?
Now I try to learn to do that view structure --- From only one form, don't add the richedit control, now just start, but I feel very interesting. It can make people think about the problem.
First, edit this function: ///
} #endregion, where the sentence is simple to say:
This.BackColor = system.drawing.color.white; makes the form color to White, as editable zone, and
this.autoscrollminsize = new system.drawing.size (550, 450); telling how many forms of formal documents
The following code draws graphical graphics in the document - Preparation: ///
The drawing: Rectangle rectangleArea = new Rectangle (rectangleTopLeft, rectangleSize); Rectangle ellipseArea = new Rectangle (ellipseTopLeft, ellipseSize); dc.DrawRectangle (bluePen, rectangleArea); dc.DrawEllipse (redPen, ellipseArea);
Where do you think the above code should be added? In the constructor of Form1? Yes, before adding this two sentences: graphics dc = this.creategraphics (); this.show ();
However, you will find that after the form is minimized, or after being covered by other forms, the graphic disappears. Oh, the phenomenon of VC reproduces. In fact, Windows will use the Paint event to notify the application to complete some re-draw requirements. So, you should overload this function as follows: ///
Base.onpaint (e);} The added IF judgment is a small optimization. For this program, if the drawn graphics are not masked, it is not necessary to re-draw, thereby increasing efficiency. However, I will say below with the following code, you understand (1) just:
Size scrolloffset = new size (this.autoscrollposition);
What is the role of this sentence? If you first remove it, then, then the judgment of the IF will be changed, or simply not optimize, the execution will find that when you use the vertical scroll bar, it will find that the graphic is like that elliptical flower, and I used the letter paper as the same :). well, why? Look at the picture below, you will understand:
----------------------------------------- | ... B | ----------------------.--------- | || ........ | ...... ..................................... | || ........ | ------------------------------ .. | || ........ | a ..... ..................................... | || ........ | ... ........................................ | || ....... | ....................................... | || .. ... | -------------------------------- | || ------- -------------------------------- | |
If B is the Document area, A is ClientArea, where the coordinate processing is done by the above program. (1) Handling the scrolling data, have you found it?
The current view is still very incomplete, I try again to solve the problem of text input related processing. Oh, after the results, I will talk about it again. Here is a complete program. There is no part that is huge, practical text processing procedures. Everyone skip is yes :). Using system.drawing; using system.componentmodel; using system.windows.form; using system.data ;. using system.data ;. USING SYSTEM.DATA;
A summary description of Namespace View {////
Public Form1 () {/// Windows Form Designer Support for // InitializeComponent ();
/// / TODO: Add any constructor code // if (! Yn) DrawString = "sample text" after the initializeComponent call.
///
// Create Point for Upper-Left Corner of Drawing.// SET FORMAT OF STRING.STRINGFORMAT DRAWFORMAT = New StringFormat (); DrawFormat.Formatflags = StringFormatFlags.directionRightToleft;
// Draw string to screen.e.graphics.drawstring (DrawString, DrawFont, Drawbrush, X, Y, DrawFormat); Base.onpaint (E);}
///
#Region Windows Form Designer Generated Code ///
///
Private Void Form1_Load (Object Sender, System.EventArgs E) {}
PRIVATE VOID FORM1_KEYDOWN (Object sender, system.windows.Forms.keyeventargs e) {// yn = true; // DrawString = E.KeyCode.toString ();}
private void Form1_KeyPress (object sender, System.Windows.Forms.KeyPressEventArgs e) {yn = true; drawString = e.KeyChar.ToString (); x = 1; // Form1.ActiveForm.BackColor = Color.Blue;}}}
Ok, I am tired, I originally, my family is coming back, I have been 7 o'clock, I am falling asleep on the car. However, I am still willing to talk, huh, if you are useful to you, how happy I should be. If I am gone, I graduated, I don't have the opportunity to do this. What about you?