I want to skin my own buttons and control backgrounds in the Paint Event. To do that, a picture needs to be divided into a 3 x 3 grid, like a tic-tac-toe grid. This allows the picture to be resized with no weirdness at the corners and edges. To maximize flexibility for the skin artist, the edges and middle should be allowed to stretch or tile when the background is resized. The corners stay as they are.
The test app is downloadable at www.Omnibrowser.com/SkinningApplication.zip
. Check it out...click the button in the center of the form to toggle between stretching and tiling the edges. If we can get this working it's kind of cool. The code that stretches the edges and middle works just fine. But the code that TILES the edges and middle doesn't work. It should work, but it doesn't.
Here's an example...PaintImage is the source bitmap, sknButton is the destination. The variable iRightMargin, iTopMargin, etc., are concerned with how much of a margin exists around the skinned image.
Dim MiddleRightSource As New RectangleF(PaintImage.Widt
h - iRightMargin, iTopMargin, iRightMargin, PaintImage.Height - iBottomMargin - iTopMargin)
Dim MiddleRightDestination As New RectangleF(sknButton.Width
- iRightMargin, iTopMargin, iRightMargin, sknButton.Height - iBottomMargin - iTopMargin)
If bRightTile = True Then
G.FillRegion(New TextureBrush(PaintImage, MiddleRightSource), New Region(MiddleRightDestinat
G.DrawImage(PaintImage, MiddleRightDestination, MiddleRightSource, GraphicsUnit.Pixel) 'Stretch
It's like the Fill Region command decides to start the fill from the edge of sknButton, rather than from the edge of the region described. FillRectangle has the same problem. Creating an ImageAttributes and setting the Wrapmode to Tile doesn't tile.
Would love to get this working and it's driving me nuts and holding up my project. I'll put a page up on my site with a sample app on how to do this credit those who contribute. Thanks for any help.