|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThe Here is a list of the other features:
BackgroundHere is another example of needing (well, let's be honest, a plain button would work, so I wanted) a better looking and visually versatile button. There are a lot of great button controls already, but not with all the features I was looking for. Basically, I created the properties I was looking for, and then took over the Control PropertiesHere is a list of the primary properties:
Using the CodeOnce you get the Points of InterestThe control is just a process of layering the parts together in the right positions. There are four main areas to track. The control area, button area, text area, and image area. The button area is reduced from the control area by the control padding values. The text area is reduced from the button area by the text margin values and the image area. The image area is based on the image size. The items are placed into these areas based on their layout options. Protected Overrides Sub _
OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim MyPen As New Pen(BorderColor)
MyPen.Alignment = PenAlignment.Inset
'Shrink the Area so the Border draws correctly
'Then trim off the Padding to get the button surface area
ButtonArea = AdjustRect(New Rectangle(0.5, 0.5, _
Me.Size.Width - 1, Me.Size.Height - 1), Me.Padding)
If Me.BackgroundImage Is Nothing Then
e.Graphics.FillPath(GetBrush(AdjustRect(Me.DisplayRectangle, _
Me.Padding)), GetRoundedRectPath(ButtonArea))
End If
If BorderShow Then
If ButtonStyle = eButtonStyle.BlendEllipse Then
e.Graphics.DrawEllipse(MyPen, ButtonArea)
Else
e.Graphics.DrawPath(MyPen, GetRoundedRectPath(ButtonArea))
End If
End If
'Put the SideImage behind the Text
If SideImageBehindText AndAlso Not Me.SideImage Is Nothing Then
Dim bm As New Bitmap(Me.SideImage, Me.SideImageSize.Width, _
Me.SideImageSize.Height)
e.Graphics.DrawImage(bm, _
ImagePoint(GetStringFormat(Me.SideImageAlign), _
Me.Size, Me.SideImageSize))
End If
'Layout the Text and Image on the button surface
SetImageAndText(e.Graphics)
If Not Me.Image Is Nothing Then
Dim bm As New Bitmap(Me.Image, Me.ImageSize)
e.Graphics.DrawImage(bm, Imagept)
End If
If TextShadow Then
TextArea.Offset(1, 1)
e.Graphics.DrawString(Me.Text, Me.Font, _
New SolidBrush(ForeColorShadow), _
TextArea, GetStringFormat(Me.TextAlign))
TextArea.Offset(-1, -1)
End If
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), _
TextArea, GetStringFormat(Me.TextAlign))
'Put the SideImage in front of the Text
If Not SideImageBehindText AndAlso Not Me.SideImage Is Nothing Then
Dim bm As New Bitmap(Me.SideImage, _
Me.SideImageSize.Width, Me.SideImageSize.Height)
e.Graphics.DrawImage(bm, ImagePoint(GetStringFormat(Me.SideImageAlign), _
Me.Size, Me.SideImageSize))
End If
MyPen.Dispose()
End Sub
Because the 'Add a new Click event for only when the ButtonArea is Clicked
Public Event ClickButtonArea(ByVal Sender As Object, ByVal e As EventArgs)
Private Sub CButton_MouseDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If IsMouseOverButton(e.X, e.Y) Then
MouseDrawState = eMouseDrawState.Down
Me.Invalidate()
RaiseEvent ClickButtonArea(Me, New EventArgs)
End If
End Sub
History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||