簡體   English   中英

我的代碼是否已從C#正確轉換為Vb.Net?

[英]Is my code properly translated from C# to Vb.Net?

我在此答案中找到了創建類似向導(下一個/上一個)的窗體的可能解決方案: 在C#中為Windows窗體創建向導

class WizardPages : TabControl
{
    protected override void WndProc(ref Message m)
    {
        // Hide tabs by trapping the TCM_ADJUSTRECT message
        if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
        else base.WndProc(ref m);
    }        

    protected override void OnKeyDown(KeyEventArgs ke)
    {
        // Block Ctrl+Tab and Ctrl+Shift+Tab hotkeys
        if (ke.Control && ke.KeyCode == Keys.Tab) 
            return;
        base.OnKeyDown(ke);
    }
}

該解決方案使我可以在Designer中創建選項卡,並在運行時將其隱藏。 我試圖將其翻譯為VB.NET,並使用:

Imports System
Imports System.Windows.Forms

Public Class WizardPages
    Inherits TabControl

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If (m.Msg = 4904 And Not DesignMode) Then '4904 is Dec of 0x1328 Hex
            m.Result = IntPtr.Zero 'IntPtr1
        Else
            MyBase.WndProc(m)
        End If

    End Sub

End Class

我沒有翻譯的唯一部分(但仍然可以使用)是m.Result = (IntPtr)1; 從C#代碼 如您所見,我嘗試使用m.Result = IntPtr.Zero

目前,我不知道如果那樣離開會發生什么。

將您的答案與@Usman的結果相結合,得出以下結果。 為了獲得1作為IntPtr,我使用了應該起作用的new IntPtr(1)語法。 另外, CType(1, IntPtr)也應該起作用。 我也沒有測試。

導入系統導入System.Windows.Forms

Public Class WizardPages
  Inherits TabControl

  Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    If m.Msg = &H1328 AndAlso Not DesignMode Then
      m.Result = new IntPtr(1)
    Else
      MyBase.WndProc(m)
    End If

  End Sub

  Protected Overrides Sub OnKeyDown(ke As KeyEventArgs)
    ' Block Ctrl+Tab and Ctrl+Shift+Tab hotkeys
    If ke.Control AndAlso ke.KeyCode = Keys.Tab Then Return
    MyBase.OnKeyDown(ke)
  End Sub
End Class

使用Telerik的轉換器

這是將C#轉換為VB之后的結果

Class WizardPages Inherits TabControl
    Protected Overrides Sub WndProc(ByRef m As Message)

        If m.Msg = &H1328 AndAlso Not DesignMode Then
            m.Result = DirectCast(1, IntPtr)
        Else
            MyBase.WndProc(m)
        End If

    End Sub

    Protected Overrides Sub OnKeyDown(ke As KeyEventArgs)

        If ke.Control AndAlso ke.KeyCode = Keys.Tab Then
            Return
        End If
        MyBase.OnKeyDown(ke)
    End Sub
End Class

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM