I'm making a class to handle custom forms. To make things easier and consistent I use a brush to draw to the form. Everything works great until I try to draw a picture to the form that is smaller than the form if I try to clip to center it. If it is bigger than the form it clips to center correctly. The picture I'm working with right now is taller than the forms height, but shorter than its width. If I try to clip to center horizontally it comes up with the error. If I set the x axis to 0 I get no error and it clips to center vertically fine with the rest of the form the default background color. Here is the code for the picture draw:
To paint to the screen I use:
where _Shape is the preconfigured region of the form (for rounded corners/odd shaped forms).
x asxis 0:
I clone the image as that is the easiest way to clip the image to use in a brush. I use .FillPath rather than .DrawImage so I can consistently use a brush to draw to the screen as the other options for the form are various gradients and such.
-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
Code:
Dim orgCenter As New Point(_Image.Picture.Width / 2, _Image.Picture.Height / 2)
Dim myCenter As New Point(Me.Width / 2, Me.Height / 2)
Dim x As Integer
Dim y As Integer
Dim width As Integer
Dim height As Integer
If Me.Width > _Image.Picture.Width Then
x = myCenter.X - orgCenter.X
width = _Image.Picture.Width
Else
x = orgCenter.X - myCenter.X
width = Me.Width
End If
If Me.Height > _Image.Picture.Height Then
y = myCenter.Y - orgCenter.Y
height = _Image.Picture.Height
Else
y = orgCenter.Y - myCenter.Y
height = Me.Height
End If
nImageWrap = WrapMode.Clamp
bmp = _Image.Picture
nImage = bmp.Clone(New Rectangle(x, y, width, height), bmp.PixelFormat)
CurrentBrush = New System.Drawing.TextureBrush(nImage, nImageWrap)
To paint to the screen I use:
Code:
e.Graphics.FillPath(CurrentBrush, _Shape)
x asxis 0:
I clone the image as that is the easiest way to clip the image to use in a brush. I use .FillPath rather than .DrawImage so I can consistently use a brush to draw to the screen as the other options for the form are various gradients and such.
-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!