VB代码转换成C#代码.

welcome316 2009-06-16 01:33:57
请会vb的朋友,帮我转换下下面这段代码, 我想用c#看看效果.
谢谢.
Imports System.ComponentModel
Imports System.Windows.Forms.Design

Public 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 Property

End 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 Property

End Class
...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
welcome316 2009-06-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 boylee83 的回复:]
用工具。这几天这个帖子这么多。

[/Quote]
朋友,可能是这种类型的帖子比较多吧,我是今天才发的啊.
呵呵.
lidss1234 2009-06-16
  • 打赏
  • 举报
回复
帮助顶一下.
  • 打赏
  • 举报
回复
用工具。这几天这个帖子这么多。
http://www.developerfusion.com/tools/convert/vb-to-csharp/
wuyq11 2009-06-16
  • 打赏
  • 举报
回复

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧