School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,421 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,526 people online right now. Registration is fast and FREE... Join Now!




Custom Inputbox

 
Reply to this topicStart new topic

> Custom Inputbox, Create your own inputbox.

AdamSpeight2008
Group Icon



post 6 May, 2009 - 11:45 PM
Post #1


Your Own InputBox

In VB6 you could use the InputBox for inputting text, like so.
CODE

  Dim temp7 As String = InputBox("Enter the album name.")

But it has its limitations;-
Cancel returns "", which maybe a valid input, so making it nigh on impossible to detect the cancel.

Now we are using vb.net let start on step away from using the old vb6 functionality.
It is really simple to create your own.

All you need is
  • A Textbox for the input text. (Txt_TextEntry)
  • A Label for the prompt text. (Lbl_Prompt)
  • A Button for Cancel (But_Cancel)
  • A Button for OK (But_Ok)
Here mine
Attached Image

A little bit of code.
CODE

Imports System.Windows.Forms

Public Class InputBox

Protected m_BlankValid As Boolean = True
Protected m_ReturnText As String = ""

Public Overloads Function ShowDialog( _
   ByVal TitleText As String, _
   ByVal PromptText As String, _
   ByVal DefaultText As String, _
   ByRef EnteredText As String, _
   ByVal BlankValid As Boolean) As System.Windows.Forms.DialogResult
  m_BlankValid = BlankValid
  Me.Lbl_Prompt.Text = PromptText
  Me.Text = TitleText
  Me.Txt_TextEntry.Text = DefaultText
  Me.ShowDialog()
  EnteredText = m_ReturnText
  Return Me.DialogResult
End Function

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txt_TextEntry.TextChanged
  If Me.Txt_TextEntry.Text = "" Then
   Me.But_Ok.Enabled = m_BlankValid
  Else
   Me.But_Ok.Enabled = True
  End If
End Sub

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles But_Ok.Click
  Me.DialogResult = System.Windows.Forms.DialogResult.OK
  m_ReturnText = Me.Txt_TextEntry.Text
  Me.Close()
End Sub

Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles But_Cancel.Click
  Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  m_ReturnText = ""
  Me.Close()
End Sub
End Class


Usage is not a simple as vb6 but hey we got a lot more capabilities.

CODE

Dim TextReturned As String=""
Dim a As New InputBox
If a.ShowDialog("The Title", "The Prompt", "Default", TextReturned , False) = Windows.Forms.DialogResult.Cancel Then
' Cancel Pressed
Beep()
Else
'
Endif


You can create different types of inputbox, for example;- password, numbers only, masked etc.

Simples

So now you're a custom InputBox building coding pirate. pirate.gif
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/8/09 12:10AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month