现在的位置: 首页 > 综合 > 正文

VB.NET 与 C# 定义事件,方法,属性,字段,构造函数的不同之处

2013年10月12日 ⁄ 综合 ⁄ 共 1527字 ⁄ 字号 评论关闭

一样的功能,两种语言不同的定义方式:

第一组:
VB.Net

Public Property setProgressBar() As Integer
        
Get
            
Return _progressBar
        
End Get
        
Set(ByVal Value As Integer)
            _progressBar 
= Value
            
Me.Panels(_progressBar).Style = StatusBarPanelStyle.OwnerDraw
        
End Set
    
End Property

C#:

 public int setProgressBar
        {
            
get
            {
                
return _progressBar;
            }
            
set
            {
                _progressBar 
= value;
                
this.Panels[_progressBar].Style = StatusBarPanelStyle.OwnerDraw ;
            }
        }

第二组:
VB.Net

    Private Sub Reposition(ByVal sender As ObjectByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles MyBase.DrawItem
        progressBar.Location 
= New Point(sbdevent.Bounds.X, sbdevent.Bounds.Y)
        progressBar.Size 
= New Size(sbdevent.Bounds.Width, sbdevent.Bounds.Height)
        progressBar.Show()
    
End Sub

C#

this.DrawItem += new StatusBarDrawItemEventHandler(Reposition);

 private void Reposition(object sender, StatusBarDrawItemEventArgs e)
        {
            progressBar.Location
=new Point(e.Bounds.X,e.Bounds.Y);
            progressBar.Size 
= new Size(e.Bounds.Width, e.Bounds.Height);
            progressBar.Show();
        }

第三组:构造函数
VB.NET

Public Class ProgressStatus 
{   
Sub New()
        progressBar.Hide()
        
Me.Controls.Add(progressBar)
    
End Sub
}

C#

public  class ProgressStatus
{
public ProgressStatus()
        {
            progressBar.Hide();
            
this.Controls.Add(progressBar);
      }
}

 

抱歉!评论已关闭.