Today, a friend asked me that when he used fillrectangle to draw an image to a form, he always misaligned and did not know what was going on. Take me Code Let's take a look at the Code as follows:
Private Void Drawtitle_right (Graphics g)
{
Image img = Files. getimage ( " /Images/top_right.gif " );
Brush = New Texturebrush (IMG );
G. fillrectangle (brush, This . Clientsize. Width - IMG. Width, 0 , IMG. Width, IMG. Height );
}
But why is it misplaced? After debugging for half a day, the result is the same as that of his experiment. The use of drawimage will not be a problem. After looking at the dislocation pattern for half a day, we found that:
"Fillrectangle is to fill in a graphics and then display the part specified by rectangle ."
Assume that the image size is the size of graphics. Fillrectangle fills the graphics in mosaic mode, and then draws the rectangle specified by rectangle. (Of course, the actual implementation may not be like this, but the effect is like this. Let me remember that when I was a child, I used my mom and I used my photo in the dark room to wash my 1-inch photos with 5-inch extension paper through a small window ^ & ^ ).
When the rect specified by fillrectangle exactly matches the image in getimage, the display is normal. If they do not match, the system will be misplaced. I have always understood this as follows:
"Fillrectangle is a rectangle with a specified image filled with coordinates at (x, y), width, width, and height ."
There are still discrepancies (this is the sequent Effect of Delphi! -_-!).
summary
after reading replies from friends, I looked back at my own articles.
I do not think it is so clear. Use the code to prove everything: Download the Code