日期:2014-05-19  浏览次数:20876 次

如何将下面的C#代码转换成VB.NET代码?急
namespace   Morell.GroupPanel
{
public   delegate   void   PropChangeHandler(TabPage   tabPage,   Property   prop,   object   oldValue);
public   enum   Property
{
Text,
ImageIndex
}
}

namespace   Morell.GroupPanel
{
public   class   GroupPanel   :   System.Windows.Forms.UserControl
{
private   void   StartEdit(object   sender,   EventArgs   e)
{
this.Capture   =   true;
}
}
}

namespace   Morell.GroupPanel
{
[ToolboxItem(false)]public   class   TabPage   :   Panel
{
public   event   PropChangeHandler   PropertyChanged;
public   event   EventHandler   StartEdit;

public   void   OnPropertyChanged(Property   prop,   object   oldValue)
{
//   Is   the   event   registered
if   (PropertyChanged   !=   null)
//   Raise   the   event
PropertyChanged(this,   prop,   oldValue);
}

Public   Sub   BeginEdit()
                        If   Not   (StartEdit   Is   Nothing)   Then
                                StartEdit(Me,   New   EventArgs())
                        End   If
                End   Sub
}
}

------解决方案--------------------
If Not (StartEdit Is Nothing) Then
StartEdit(Me, New EventArgs())
End If

if(StartEdit != null)
{
StartEdit(this, New EventArgs());
}
------解决方案--------------------
If Not object.Equals (StartEdit ,Nothing) Then
StartEdit(Me, New EventArgs())
End If

您看看msdn
Remarks
The Is operator determines if two object references refer to the same object. However, it does not perform value comparisons. If object1 and object2 both refer to the exact same object instance, result is True; if they do not, result is False.
就是说is只是比较引用对象
不是sqlsever那种比较是否是null


Object.Equals (Object, Object) Determines whether the specified Object instances are considered equal.
Supported by the .NET Compact Framework.
这个才是比较!
------解决方案--------------------
Namespace Morell.GroupPanel
Public delegate void PropChangeHandler(TabPage tabPage, Property prop, Object oldValue)
Public Enum Property
Text
ImageIndex
End Enum
End Namespace

Namespace Morell.GroupPanel
Public Class GroupPanel
Inherits System.Windows.Forms.UserControl
Private Sub StartEdit(ByVal sender As Object, ByVal e As EventArgs)
Me.Capture = True
End Sub
End Class
End Namespace

Namespace Morell.GroupPanel
(ToolboxItem(False))Public Class TabPage
Inherits Panel
Public event PropChangeHandler PropertyChanged
Public event EventHandler StartEdit

Public Sub OnPropertyChanged(ByVal prop As Property, ByVal oldValue As Object)
' Is the event registered
If Not PropertyChanged Is Nothing Then
' Raise the event