[英]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
这是将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.