ASP. NET interactive bitmap Form Design (8)

Source: Internet
Author: User

Click the event handler button
Next, click the event handler for each button. Most of the operations are simply to add a new printable object to the drawing list, and then call the Invalidate on PictureBox to redraw with the updated drawing list. The typical code of the button event handler is as follows:


C #
Private void AddPoint_Click (object sender, System. EventArgs e ){
DrawingList. Add (new DPoint (GetRandomPoint (), Color. Blue ));
Drawing. Invalidate ();
}

Visual Basic

. NET Private Sub AddPoint_Click (ByVal sender As System. Object ,_
ByVal e As System. EventArgs) Handles AddPoint. Click
DrawingList. Add (New DPoint (GetRandomPoint (), Color. Blue ))
Drawing. Invalidate ()
End Sub


The Change fills to hot pink button (Change fill color to pink) has some differences-it gets an array of all the objects that can be filled in the list, then change their paint brush color to pink. This part of code is displayed at the end of the previous section "back to the filled list. (You must also disable PictureBox .)

Finally, the Erase All (delete All) button creates a new drawing list and points our drawingList field to this list. In this way, the old drawing list is released to recycle the last memory. Disable PictureBox and delete yourself.

PictureBox plotting event processing program
The last thing we should note is to draw an image in PictureBox. To do this, you need to process the painting event generated by PictureBox, and then draw on it using the Graphics object passed through this event. To plot, you only need to call the DrawList method of the drawing list-A for each loop and polymorphism will be responsible for the rest of the work!


C #
Private void Drawing_Paint (object sender,
System. Windows. Forms. PaintEventArgs e ){
DrawingList. DrawList (e. Graphics );
}


Visual Basic

. NET Private Sub Drawing_Paint (ByVal sender As Object ,_
ByVal e As System. Windows. Forms. PaintEventArgs )_
Handles Drawing. Paint
DrawingList. DrawList (e. Graphics)
End Sub


This is the end of our Windows Forms Application journey-consider the code and modify it so that you can learn more!

Use plotting objects in ASP. NET Applications
Although there are some differences between ASP. NET Web applications and Windows Forms applications, the similarity between the two still surprised Dr. GUI!

Main Parts of Web forms applications
The main parts of ASP. NET Web forms applications correspond to each part of Windows Forms applications.

Page
This option corresponds to the main window in the Windows Forms Application. The page is the container for all buttons and other controls.

Button
Likewise, there is a set of buttons that can be used to perform various operations on the form. Note that, unlike previous applications, we set the pageLayout attribute of the page document to GridLayout instead of FlowLayout. This means that each button (and other controls) can be located by pixel position ).

Note that there are some text boxes.

Note that you cannot copy or paste Windows Forms controls to the Web-you must recreate the entire page.

Image Control
The image control corresponds to PictureBox in the Windows Forms Application. However, there are some important differences between the two: The image control does not generate a Paint message, but contains the URL for loading the image.

We set this URL to the second Web page, ImageGen. aspx. In other words, we have a Web page, and all of its work is to generate a bit in the image from our drawing list, and then send the image to the client's Web browser.

We will discuss the code below.

Main routine of Web forms applications
There are some important differences between the codes of Windows Forms applications and Web forms applications-but there are also some interesting similarities. Note that all the code in the object file that can be drawn can be used in any of the three applications.

Our Page is derived from System. Web. UI. Page. In addition to the following content, it also contains a set of declarations for all controls:

Identical content: Data declaration and GetRandomPoint
This code is almost identical to the Code in the Visual Basic. NET Windows Forms Application. If you want to, you can take a look at the above Code. There is only one difference between them, that is, fields are declared without being initialized. They will be initialized in the Page_Load method (as shown later ).

The GetRandomPoint method is identical to that of other applications. Code reuse is really good, isn't it?

Very similar: Click the event handler
The event handler for Button clicking is the same as the Windows form application, with only one exception: In a Web form, because the image is re-drawn every time you click the button, you do not need to (and cannot) invalid image control. In addition, it will automatically redraw-so the only thing to call is the Add method of the drawing list.

The following is a typical button event handler-used to draw a vertex.

Private Sub AddPoint_Click (ByVal sender As System. object, _ ByVal e As System. eventArgs) Handles AddPoint. click drawingList. add (New DPoint (GetRandomPoint (), Color. blue) End Sub

Other button event handlers are similar to Windows Forms. Except for one exception, do not call any method to invalidate the image.

Very different content: page loading and uninstalling handlers
The method for loading and uninstalling the page handler is completely different.

Remember that our page objects are re-created using every HTTP request. Since each request will create a new page, we cannot store data as a member variable as in Windows forms. In Windows Forms, the main window will exist with the application.

Therefore, we must store the information required between the request and the page in a certain state variable. There are several options-this will be discussed below.

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.