【发布时间】:2015-12-16 22:33:15
【问题描述】:
我找到了一个可能的解决方案来创建类似向导的(下一个/上一个)表单,在这个答案中:Creating Wizards for Windows Forms in C#
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
我没有翻译(但仍然有效)的唯一部分是 C# 代码中的 m.Result = (IntPtr)1;。如您所见,我尝试使用m.Result = IntPtr.Zero
目前我不知道如果我就这样离开会发生什么。
【问题讨论】:
-
也可以通过替换为:
m.Result = New IntPtr(1) 'IntPtr1。我仍然不知道它的作用。 -
查看 MSDN 上的
TCM_ADJUSTRECT,该消息实际上并不期望返回值,所以我认为这有点无操作。在What does the Result property of a windows message mean and when and how to use it? 有更长的关于返回值的讨论。如果你在设置之前检查m.Result,你会得到什么? -
我认为您的翻译方向错误:O
-
也许吧?老实说,我不知道 C# 中
m.Result = (IntPtr)1;的作用