'VB.net de butonları XP yapmak icin
'(form1 in ustundeki button1 icin)
'oncelikle vb.net in drawing clasını import etmeliyiz,
'bunun icin formun en ustune;
Imports System.Drawing.Drawing2
'bundan sonra windows form designer generated code ifadesinin
'hemen altına grekli tanımlamaları yapalım;
Enum BtnState
Disabled
Normal
Hot
Pushed
End Enum
Const cornerR As Integer = 4
Const cornerD As Integer = (cornerR * 2)
'simdi butonun seklini degistiren paint Sub ını olusturalım;
Private Sub PaintXPButton(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles Button1.Paint
'eger butonun ismi degisik ise yukarda button1 yerine kendi butonunuzun ismini yazmalısınız isterseniz virgul koyup istediginiz diger butonları yazarak aynı efekti verebilirsiniz.
Dim btn As Button = CType(sender, Button)
Dim backgroundBrush As New SolidBrush(Me.BackColor)
Dim bMouseDown As Boolean = (btn.MouseButtons And MouseButtons.Left) <> 0
Dim ptMouse As Point = Me.PointToClient(btn.MousePosition)
Dim bMouseInButton As Boolean = btn.Bounds.Contains(ptMouse)
'butonun davranısını belirliyelim
Dim state As BtnState
If (btn.Enabled = False) Then
state = BtnState.Disabled
ElseIf (bMouseDown = False) Then
If (bMouseInButton = True) Then
state = BtnState.Hot
Else 'bMouseInButton = False
state = BtnState.Normal
End If
Else 'bMouseDown = True
If (bMouseInButton = True) Then
state = BtnState.Pushed
Else 'bMouseInButton = False
state = BtnState.Hot
End If
End If
Dim rect As New Rectangle(1, 1, e.ClipRectangle.Width - (cornerR + 1), e.ClipRectangle.Height - (cornerR + 1))
Dim layoutRect As New RectangleF(rect.X, rect.Y, rect.Width, rect.Height)
Dim gradNormal As New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(0, 0, 10, e.ClipRectangle.Height), _
SystemColors.ControlLightLight, SystemColors.ActiveCaption, LinearGradientMode.Vertical)
Dim gradPushed As New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(0, 0, 10, e.ClipRectangle.Height), _
SystemColors.ActiveCaption, SystemColors.ControlLightLight, LinearGradientMode.Vertical)
Dim strFormat As New StringFormat()
strFormat.Alignment = StringAlignment.Center
strFormat.LineAlignment = StringAlignment.Center
Dim pp As GraphicsPath = RoundRectPath(rect, cornerR)
If (state <> BtnState.Disabled) Then
Dim shadowRect As New Rectangle(0, 0, e.ClipRectangle.Width - 2, e.ClipRectangle.Height - 2)
Select Case state
Case BtnState.Disabled
e.Graphics.FillPath(SystemBrushes.ControlLight, pp)
e.Graphics.DrawPath(SystemPens.ControlDarkDark, pp)
e.Graphics.DrawString(btn.Text, btn.Font, SystemBrushes.ControlDarkDark, layoutRect, strFormat)
Case BtnState.Pushed
e.Graphics.FillPath(gradPushed, pp)
Dim hiRect As Rectangle = rect
hiRect.Inflate(-1, -1)
e.Graphics.DrawRectangle(SystemPens.ControlLightLi ght, hiRect)
e.Graphics.DrawPath(SystemPens.ControlDarkDark, pp)
e.Graphics.DrawString(btn.Text, btn.Font, SystemBrushes.ActiveCaptionText, layoutRect, strFormat)
End Select