请会vb的朋友,帮我转换下下面这段代码, 我想用c#看看效果.
谢谢.
Imports System.ComponentModel
Imports System.Windows.Forms.DesignPublic Class LabelWithBar
Inherits Label Private mVal As Integer = 0 ' Current value
Private mbarColor As Color = Color.Blue ' Color of bar
Private mbarHeight As Integer = 0 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim percent As Decimal = mVal / 100
Dim brush As SolidBrush = New SolidBrush(BarColor)
Dim rect As Rectangle = e.ClipRectangle
Dim height As Integer = mbarHeight rect.Width = rect.Width * percent
If height = 0 Then height = rect.Height rect.Y = (rect.Height - height) / 2
rect.Height = height ' Draw bar
g.FillRectangle(brush, rect)
MyBase.OnPaint(e) End Sub <DefaultValue(0)> _
Public Property Value() As Integer
Get
Return mVal
End Get Set(ByVal Value As Integer) ' Make sure that the value does not stray outside the valid range.
Select Case Value
Case Is < 0
mVal = 0
Case Is > 100
mVal = 100
Case Else
mVal = Value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(GetType(Color), "Blue")> _
Public Property BarColor() As Color
Get
Return mbarColor
End Get Set(ByVal Value As Color)
mbarColor = Value ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(0)> _
Public Property BarHeight() As Integer
Get
Return mbarHeight
End Get
Set(ByVal value As Integer)
Select Case value
Case Is > Me.Size.Height, Is < 0
mbarHeight = Me.Size.Height
Case Else
mbarHeight = value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End PropertyEnd Class<System.ComponentModel.DesignerCategory("code")> _
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)> _
Public Class ToolStripStatusLabelWithBar
Inherits ToolStripStatusLabel Private mVal As Integer = 0 ' Current progress
Private mbarColor As Color = Color.Blue ' Color of progress meter
Private mbarHeight As Integer = 0 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim percent As Decimal = mVal / 100
Dim brush As SolidBrush = New SolidBrush(BarColor)
Dim rect As Rectangle = e.ClipRectangle
rect.Width = rect.Width * percent Dim height As Integer = mbarHeight
If height = 0 Then height = rect.Height rect.Y = (rect.Height - height) / 2
rect.Height = height ' Draw the progress meter.
g.FillRectangle(brush, rect) MyBase.OnPaint(e) End Sub <DefaultValue(0)> _
Public Property Value() As Integer
Get
Return mVal
End Get Set(ByVal Value As Integer) ' Make sure that the value does not stray outside the valid range.
Select Case Value
Case Is < 0
mVal = 0
Case Is > 100
mVal = 100
Case Else
mVal = Value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(GetType(Color), "Blue")> _
Public Property BarColor() As Color
Get
Return mbarColor
End Get Set(ByVal Value As Color)
mbarColor = Value ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(0)> _
Public Property BarHeight() As Integer
Get
Return mbarHeight
End Get
Set(ByVal value As Integer)
Select Case value
Case Is > Me.Size.Height, Is < 0
mbarHeight = Me.Size.Height
Case Else
mbarHeight = value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End PropertyEnd Class
谢谢.
Imports System.ComponentModel
Imports System.Windows.Forms.DesignPublic Class LabelWithBar
Inherits Label Private mVal As Integer = 0 ' Current value
Private mbarColor As Color = Color.Blue ' Color of bar
Private mbarHeight As Integer = 0 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim percent As Decimal = mVal / 100
Dim brush As SolidBrush = New SolidBrush(BarColor)
Dim rect As Rectangle = e.ClipRectangle
Dim height As Integer = mbarHeight rect.Width = rect.Width * percent
If height = 0 Then height = rect.Height rect.Y = (rect.Height - height) / 2
rect.Height = height ' Draw bar
g.FillRectangle(brush, rect)
MyBase.OnPaint(e) End Sub <DefaultValue(0)> _
Public Property Value() As Integer
Get
Return mVal
End Get Set(ByVal Value As Integer) ' Make sure that the value does not stray outside the valid range.
Select Case Value
Case Is < 0
mVal = 0
Case Is > 100
mVal = 100
Case Else
mVal = Value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(GetType(Color), "Blue")> _
Public Property BarColor() As Color
Get
Return mbarColor
End Get Set(ByVal Value As Color)
mbarColor = Value ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(0)> _
Public Property BarHeight() As Integer
Get
Return mbarHeight
End Get
Set(ByVal value As Integer)
Select Case value
Case Is > Me.Size.Height, Is < 0
mbarHeight = Me.Size.Height
Case Else
mbarHeight = value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End PropertyEnd Class<System.ComponentModel.DesignerCategory("code")> _
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)> _
Public Class ToolStripStatusLabelWithBar
Inherits ToolStripStatusLabel Private mVal As Integer = 0 ' Current progress
Private mbarColor As Color = Color.Blue ' Color of progress meter
Private mbarHeight As Integer = 0 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics Dim percent As Decimal = mVal / 100
Dim brush As SolidBrush = New SolidBrush(BarColor)
Dim rect As Rectangle = e.ClipRectangle
rect.Width = rect.Width * percent Dim height As Integer = mbarHeight
If height = 0 Then height = rect.Height rect.Y = (rect.Height - height) / 2
rect.Height = height ' Draw the progress meter.
g.FillRectangle(brush, rect) MyBase.OnPaint(e) End Sub <DefaultValue(0)> _
Public Property Value() As Integer
Get
Return mVal
End Get Set(ByVal Value As Integer) ' Make sure that the value does not stray outside the valid range.
Select Case Value
Case Is < 0
mVal = 0
Case Is > 100
mVal = 100
Case Else
mVal = Value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(GetType(Color), "Blue")> _
Public Property BarColor() As Color
Get
Return mbarColor
End Get Set(ByVal Value As Color)
mbarColor = Value ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End Property <DefaultValue(0)> _
Public Property BarHeight() As Integer
Get
Return mbarHeight
End Get
Set(ByVal value As Integer)
Select Case value
Case Is > Me.Size.Height, Is < 0
mbarHeight = Me.Size.Height
Case Else
mbarHeight = value
End Select ' Invalidate the control to get a repaint.
Me.Invalidate()
End Set
End PropertyEnd Class
http://www.developerfusion.com/tools/convert/vb-to-csharp/