C # reference coordinate system functions similar to modeling in drawing

Source: Internet
Author: User

In entity modeling software, various reference coordinate systems are often set and saved to facilitate model creation. C # similar functions are also available in plotting. But not as powerful as modeling software. In entity modeling software, various coordinate systems can be set and stored independently and called at any time. However, it can only be called in the form of nesting. When it is returned to the upper-level status, the skipped status will not be saved.

1 Normal Mode

Main Command: State = graphics. begincontainer (); Create a New Drawing status

E. Graphics. endcontainer (state1); ends the drawing state.

 

Code
Rectangle rect =   New Rectangle ( 0 , 0 , 100 , 100 ); // Sample Image

Graphicscontainer state1 = E. Graphics. begincontainer (); // Create a new drawing coordinate state1

E. Graphics. translatetransform ( 100 , 100 ); // Move the coordinate system to 100,100 and draw a blue rectangle mark
E. Graphics. drawrectangle (pens. Blue, rect );
Graphicscontainer state2 = E. Graphics. begincontainer (); // On this basis, create a plot coordinate state2

E. Graphics. rotatetransform ( 45 ); // Rotate 45 degrees, draw a red rectangle mark
E. Graphics. drawrectangle (pens. Red, rect );

E. Graphics. translatetransform (100,100);
E. Graphics. drawrectangle (pens. Black, rect );

E. Graphics. endcontainer (state2 );//Exit Coordinate System 2 and draw a blue elliptic
E. Graphics. drawellipse (pens. Blue, rect );

E. Graphics. endcontainer (state1 );//Exit state1 and draw a red elliptic
E. Graphics. drawrectangle (pens. Red, rect );

 

Status 1

Move to 100,100 and draw a blue rectangle

Nested state 2

Move to, 0, and draw a red rectangle

Exit status 2, draw a blue oval

Exit status 1, draw a red rectangle

Status 2 is nested. If you exit status 1 and draw a red rectangle, status 2 is no longer saved.

Graphics. begincontainer () and endgontainer are used to save and return the current canvas status. Of course, moving is only a way to change the canvas status.

 

2 With scaling

Main Command: graphicscontainer containerstate = E. Graphics. begincontainer (
Destrect, srcrect,
Graphicsunit. pixel );

Add two more parameters. destrect and scrrect specify the scaling size.

Pixel unit

I don't know how the two rectangles define scaling.

Code
Rectangle srcrect =   New Rectangle ( 0 , 0 , 200 , 200 );
Rectangle destrect =   New Rectangle ( 200 , 200 , 100 , 100 );

// Create a scaled drawing board.
graphicscontainer containerstate = E. graphics. begincontainer (
destrect, srcrect,
graphicsunit. pixel);

// scale a green rectangle in a drawing.
E. graphics. fillrectangle ( New solidbrush (color. red), 0 , 0 , 100 , 100 );

// exit the drawing board.
E. graphics. endcontainer (containerstate);

// draws the original red rectangle.
E. graphics. fillrectangle ( New solidbrush (color. green), 0 , 0 , 100 , 100 );

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.