0

I found a possible solution for creating a Wizard-like (next/previous) Form, in this answer: 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);
    }
}

The solution allows me to create Tabs in Designer, and hide them at Runtime. I tried to translate this to VB.NET, and worked with:

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

The only part that I didn't translate (but still works) is the m.Result = (IntPtr)1; from the C# code. As you can see, I tried with m.Result = IntPtr.Zero

For the moment I don't know what will happen if I leave it like that.

Community
  • 1
  • 1
Mr_LinDowsMac
  • 2,644
  • 9
  • 56
  • 75
  • 1
    See [Equivalent of (IntPtr)1 in VBNET?](http://stackoverflow.com/q/19283287/231316) – Chris Haas Dec 16 '15 at 22:40
  • Also worked by replacing to: `m.Result = New IntPtr(1) 'IntPtr1`. Still I don't know what it does. – Mr_LinDowsMac Dec 16 '15 at 22:45
  • Looking at [`TCM_ADJUSTRECT`](https://msdn.microsoft.com/en-us/library/windows/desktop/bb760573(v=vs.85).aspx) on MSDN, that message actually isn't expecting a return value so I think this is a little bit of a no-op. There's a much longer discussion on return values at [What does the Result property of a windows message mean and when and how to use it?](http://stackoverflow.com/q/19961694/231316). If you inspect `m.Result` before setting it, what do you get? – Chris Haas Dec 16 '15 at 23:07
  • I think you are translating in the wrong direction :O – CRice Dec 16 '15 at 23:12
  • Perhaps? To be honest, I don't know what it does that `m.Result = (IntPtr)1; ` in C# – Mr_LinDowsMac Dec 16 '15 at 23:27

1 Answers1

2

Combining your answer with @Usman's yields the following. To get 1 as an IntPtr, I used the new IntPtr(1) syntax which should work. Alternatively CType(1, IntPtr) should also work. I have not tested either, however.

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 = &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
erdomke
  • 4,980
  • 1
  • 24
  • 30