Click here to Skip to main content
Licence CPOL
First Posted 15 Jan 2009
Views 31,771
Downloads 186
Bookmarked 8 times

Exposing VB InputBox Dialog to C# code

By | 15 Oct 2010 | Article
This is basically a VB InputBox Dialog wrapper dll for C#.

Introduction - VS2005

This solves the issue with trying to access the Microsoft.VisualBasic.Interaction.InputBox(); code. C# is not able to use the optional variables that VB uses so we will have to expose them as overloads. This code fully exposes the VB InputBox code.

Background

C# does not contain an InputBox. Maybe Microsoft will in the 2010 code (They did add support in VS2010). Or better yet, maybe Microsoft will make it to where someone can add a .vb file to a C# project and allow it to compile.

Using the code

Add InputBoxClassLibrary.dll to your C# References.
Add Using InputBoxClassLibrary; to the C# code.

VB Code to Expose Microsoft.VisualBasic.Interaction.InputBox():

Public Class InputBox

	Public Overloads Shared Function Show(ByVal message As String) As String
		Return Microsoft.VisualBasic.Interaction.InputBox(message)

	End Function

	Public Overloads Shared Function Show(ByVal message As String, _
			ByVal title As String) As String

		Return Microsoft.VisualBasic.Interaction.InputBox(message, title)
	End Function

	Public Overloads Shared Function Show(ByVal message As String, _
			ByVal title As String, _
			ByVal defaultValue As String) As String

		Return Microsoft.VisualBasic.Interaction.InputBox(message, title, defaultValue)
	End Function

	Public Overloads Shared Function Show(ByVal message As String, _
			ByVal title As String, _
			ByVal defaultValue As String, _
			ByVal xPos As Integer) As String

		Return Microsoft.VisualBasic.Interaction.InputBox(message, title, defaultValue, xPos)
	End Function

	Public Overloads Shared Function Show(ByVal message As String, _
			ByVal title As String, _
			ByVal defaultValue As String, _
			ByVal Null As Nullable, _
			ByVal yPos As Integer) As String

		Return Microsoft.VisualBasic.Interaction.InputBox(message, title, defaultValue, , yPos)
	End Function

	Public Overloads Shared Function Show(ByVal message As String, _
			ByVal title As String, _
			ByVal defaultValue As String, _
			ByVal xPos As Integer, _
			ByVal yPos As Integer) As String

		Return Microsoft.VisualBasic.Interaction.InputBox(message, title, defaultValue, xPos, yPos)
	End Function
End Class

C# Code used to expose the InputBox Class code:

	string Returned;

	//This will show the InputBox center screen with a default title and no default val
	Returned = InputBox.Show("Message1");
	MessageBox.Show(Returned);

	//This will show the InputBox center screen with a message and title and no default val
	Returned = InputBox.Show("Message2", "title - no default val");
	MessageBox.Show(Returned);

	//This will show the InputBox center screen with a message, title, and default val
	Returned = InputBox.Show("Message3", "title - no x and y", "defaultValue");
	MessageBox.Show(Returned);

	//This will show the InputBox 50 pix away from the side of the screen.
	Returned = InputBox.Show("Message4", "title - x50", "defaultValue2", 50);
	MessageBox.Show(Returned);

	//This will show the InputBox 50 pix away from the top side of the screen.
	Returned = InputBox.Show("Message5", "title - y50", "defaultValue2", null, 50);
	MessageBox.Show(Returned);

	//this will show the InputBox 50 pix away from the top and side of the screen. 
	Returned = InputBox.Show("Message6", "title - x50 and y50", "defaultValue2", 50, 50);
	MessageBox.Show(Returned);

Points of Interest

Make sure that "Overloads Shared" is used in the VB code when exposing Optional variables in VB code.

History

01/15/09 - Document Created.
01/16/09 - Document Updated.
08/12/10 - No longer needed in VS2010.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

omzig



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 3 Pinmembersirama200419:49 31 Oct '10  
Rant[My vote of 1] Nearly fell out of my chair! PinmemberDavePaterson10:11 11 Sep '10  
GeneralMy vote of 1 Pinmemberjohannesnestler6:55 13 Aug '10  
GeneralMy vote of 1 PinmemberAxelM21:30 12 Aug '10  
GeneralMy vote of 1 Pinmemberkarabax8:56 12 Aug '10  
GeneralThis code is no longer needed in VS2010. Pinmemberomzig5:24 12 Aug '10  
Generalsimple <-> complex PinmemberFroghut23:32 23 Jun '09  
GeneralMy vote of 1 PinmemberAlex Hazanov8:47 10 Mar '09  
GeneralSimplier way PinmemberAlex Hazanov8:47 10 Mar '09  
GeneralRe: Simplier way - now simpler Pinmemberjohannesnestler6:53 13 Aug '10  
GeneralMy Vote of 1 Pinmemberrobertw0199:08 16 Jan '09  
GeneralRe: My Vote of 1 [modified] Pinmemberomzig9:55 16 Jan '09  
GeneralRe: My Vote of 1 Pinmemberrobertw0199:58 16 Jan '09  
GeneralRe: My Vote of 1 Pinmemberomzig10:03 16 Jan '09  
GeneralMy vote of 1 Pinmemberrobertw0199:06 16 Jan '09  
GeneralRe: My vote of 1 Pinmemberomzig9:55 16 Jan '09  
GeneralMy vote of 1 PinmvpDave Kreskowiak7:15 16 Jan '09  
GeneralRe: My vote of 1 Pinmemberomzig9:57 16 Jan '09  
GeneralMy vote of 1 PinmemberRob Smiley2:43 16 Jan '09  
QuestionWhat is the advantage of using VB code? PinmemberMember 46806522:09 16 Jan '09  
AnswerRe: What is the advantage of using VB code? [modified] Pinmemberomzig3:35 16 Jan '09  
GeneralMy vote of 1 PinmemberNorm .net21:09 15 Jan '09  
GeneralMy vote of 1 Pinmemberfiend19:33 15 Jan '09  
GeneralMy vote of 1 Pinmemberteleprobst-ober11:56 15 Jan '09  
GeneralMy vote of 1 PinmemberClutchplate11:47 15 Jan '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 15 Oct 2010
Article Copyright 2009 by omzig
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid