Monday, March 9, 2009

How To Create A Banner for Windows Form

Its Nice to See banners on the top of winforms, its simple just add one picture box to your form, then inside load of the form

write the code.

PictureBox1.Image = GetBanner(pbBanner.Width, pbBanner.Height, " Welcome")


Public Function GetBanner(ByVal Width As Integer, ByVal Height As Integer, ByVal bannerText As String) As Image

Dim bmp As New Bitmap(Width, Height)
Dim gImage As Graphics
gImage = Graphics.FromImage(bmp)

Dim rect As New Rectangle(0, 0, Width, Height)

Dim mybrush As New LinearGradientBrush(rect, Color.DodgerBlue, Color.White, LinearGradientMode.Vertical)

'mybrush.SetSigmaBellShape(0.5, 1)

Dim drawString As String = bannerText
Dim drawFont As New Font("Microsoft Sans Serif", 11, FontStyle.Bold)
Dim drawBrush As New SolidBrush(Color.DarkBlue)
Dim drawPoint As New PointF(Width / 2.8, Height / 3)

gImage.FillRectangle(mybrush, 0, 0, Width, Height)

gImage.DrawString(drawString, drawFont, drawBrush, drawPoint)

Return bmp

End Function