createpatternbrush (gdi32)
Last changed: SourSW@yahoo.com-204.144.132.18

.
Summary

C# Signature:

[DllImport("gdi32.dll")]
static extern IntPtr CreatePatternBrush(IntPtr hbmp);

User-Defined Types:

None.

Notes:

hbmp simply is a handle to a bitmap image.

Tips & Tricks:

Using the System.Drawing.Bitmap class, you can create whatever pattern you desire.

Sample Code (in VB):

<System.Runtime.InteropServices.DllImport("gdi32.dll")> _
Public Function CreatePatternBrush(ByVal hbmp As IntPtr) As IntPtr
End Function

Dim gBrush As IntPtr
Dim bB As New Bitmap(Width, Height)
Dim drawingArea As Graphics = Graphics.FromImage(bB)
Dim lGB As New Drawing2D.LinearGradientBrush(drawingArea.VisibleClipBounds, Color.Yellow, _
        Color.Orange, Drawing2D.LinearGradientMode.Vertical)

drawingArea.FillRectangle(lGB, drawingArea.VisibleClipBounds)
gBrush = CreatePatternBrush(bB.GetHbitmap)

Alternative Managed API:

Do you know one? Please contribute it!

Documentation