[vb.net] VB.NET Inputbox - How to identify when the Cancel Button is pressed?

1) create a Global function (best in a module so that you only need to declare once)

Imports System.Runtime.InteropServices                 ' required imports
Public intInputBoxCancel as integer                    ' public variable

Public Function StrPtr(ByVal obj As Object) As Integer
    Dim Handle As GCHandle = GCHandle.Alloc(obj, GCHandleType.Pinned)
    Dim intReturn As Integer = Handle.AddrOfPinnedObject.ToInt32
    Handle.Free()
    Return intReturn
End Function

2) in the form load event put this (to make the variable intInputBoxCancel = cancel event)

intInputBoxCancel = StrPtr(String.Empty)    

3) now, you can use anywhere in your form (or project if StrPtr is declared global in module)

dim ans as string = inputbox("prompt")         ' default data up to you
if StrPtr(ans) = intInputBoxCancel then
   ' cancel was clicked
else
   ' ok was clicked (blank input box will still be shown here)
endif