VB .NET Calling a Form

6010
11
Jump to solution
03-05-2012 06:01 AM
Gregde_Bruin
New Contributor III
Hi,

I'm in the process of converting code from VBA to VB. NET, and I'm having trouble calling a form I created from a button.
Here's what I've tried so far:

Protected Overrides Sub OnClick()

Dim FormLogin As New System.Windows.Forms.Form
FormLogin.Show()

End Sub

This brings up the form, but it's a completely blank form, which the form I'm attempting to call is not.
Any help is appreciated.

Thank you,
cdebruin
0 Kudos
11 Replies
JimIsbell
New Contributor II
Thanks for that reply, @KenBuja. That's pretty much the same code I have, and it works beautifully.

Incidentally, I discovered that this technique can also be used with a System.Windows.Forms.MessageBox object. As you know (or will eventually find out), the default location for the MessageBox is at the CENTER OF YOUR DISPLAY SCREEN. This behavior is not what I prefer, so I use the Win32 Window Wrapper technique, as follows:


Imports System.Windows.Forms


' Example 1: This will open a MessageBox at the center of YOUR FORM:
MessageBox.Show(New Win32HWNDWrapper(MyFormInstanceName.Handle), "This is the message", "This is the caption")


' Example 2: This will open a MessageBox at the center of the ARCMAP APPLICATION WINDOW:
MessageBox.Show(New Win32HWNDWrapper(My.ArcMap.Application.Hwnd), "This is the message", "This is the caption")

I hope someone finds this as useful as I have.
0 Kudos
JimIsbell
New Contributor II
Here's a follow-up to the Form Owner issue.

I saw this demonstrated at the 2012 User Conference in San Diego using only ONE LINE OF CODE! As it turns out, .NET has a built-in static method that can do the same thing as the wrapper class mentioned earlier. It works as follows:

MyFormInstanceName.Show(System.Windows.Forms.Control.FromHandle(My.ArcMap.Application.hWnd))

No wrapper class is needed after all!
0 Kudos