Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

from way back . . . (man Ive learned alot snce then)

 

add this class to your app (code follows, post back if I messed something up in the VB translation from C#).

 

usage:

______________________________________________

 

Public Shared Function ObjTec.InputForm.PromptString(ByVal args As ObjTec.PromptFormArgs) As String

 

 

 

 

 

 

 

parameters:

args
- instance of ObjTec.PromptFormArgs (see below)

 

 

 

 

 

 

 

return:

 

 

 

 

 

 

 

on 'OK' - the User Specified Text,
on 'Cancel' - nothing

 

 

 

 

 

 

[font=Microsoft Sans Serif]dim s as string [/font][font=Microsoft Sans Serif]= ObjTec.InputForm.PromptString(new ObjTec.PromptFormArgs("This is The Title", "This is the Prompt", "This is Initial Value") [/font]

 

 

 

______________________________________________

 

Public Shared Function ObjTec.InputForm.PromptQuery(ByVal args As ObjTec.PromptFormArgs, ByRef result As String) As Boolean

 

 

 

 

 

 

 

parameters:

args
- instance of ObjTec.PromptFormArgs (see below)
result [out] -
null on user cancel else the input value

 

 

 

 

 

 

return:

on 'OK'- true
on 'Cancel' - false

 

 

 

 

 

 

______________________________________________

 

 

 

 

class ObjTec.PromptFormArgs

 

constructor

 

 

[/font][font=Microsoft Sans Serif]Public Sub New(ByVal title As String, ByVal prompt As String, ByVal defaultValue As String)[/font][font=Microsoft Sans Serif]

property

[/font][font=Microsoft Sans Serif]shared readonly ObjTec.PromptFormArgs.Empty [/font][font=Microsoft Sans Serif][font=Microsoft Sans Serif]

 

 

 

 

 

 

 

 

 

 

 

 

 

defaults the form to:[/font]

Title = Application.ProductName

 

 

 

 

 

 

prompt = "Value Required"

Default = "[not set]'"
[/font][font=Microsoft Sans Serif][font=Microsoft Sans Serif]dim s as string [/font][font=Microsoft Sans Serif]= ObjTec.InputForm.PromptString(ObjTec.PromptFormArgs.Empty) [/font][font=Microsoft Sans Serif]

[/font]

 

 

 

_____________________________________________

 

 

 

 

example:









Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
[indent]Dim s1 As String = ObjTec.InputForm.PromptString(New ObjTec.PromptFormArgs("A Value Needed", "Enter any Value", "Default"))




Dim s2 As String









If ObjTec.InputForm.PromptQuery(ObjTec.PromptFormArgs.Empty, s2) Then[indent]MessageBox.Show(s2)







[/indent]
ElseIf Not (s1 Is Nothing) Then








[indent]MessageBox.Show(s1)







[/indent]
Else








[indent]MessageBox.Show("User Cancelled")







[/indent]
End If







[/indent]End Sub

The Class Code -

[indent]Imports System Imports System.Drawing



Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms

Namespace ObjTec 









Public Class InputForm[indent]



Inherits System.Windows.Forms.Form

Private WithEvents okButton As System.Windows.Forms.Button


[/indent]

[indent]Private WithEvents cancelBtn As System.Windows.Forms.Button


Friend WithEvents label1 As System.Windows.Forms.Label
Friend WithEvents textBox1 As System.Windows.Forms.TextBox
Private components As System.ComponentModel.Container = Nothing









Private Sub New()[indent]InitializeComponent()







[/indent]
End Sub 










Protected Overloads Sub Dispose(ByVal disposing As Boolean)
[indent]If disposing Then[indent]If Not (components Is Nothing) Then[indent]components.Dispose()






[/indent]
End If






[/indent]End If




MyBase.Dispose(disposing)




[/indent]End Sub










Private Sub InitializeComponent()
[indent]Me.okButton = New System.Windows.Forms.Button



Me.cancelBtn = New System.Windows.Forms.Button
Me.label1 = New System.Windows.Forms.Label
Me.textBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
Me.okButton.DialogResult = System.Windows.Forms.DialogResult.OK
Me.okButton.Enabled = False
Me.okButton.Location = New System.Drawing.Point(96, 56)
Me.okButton.Name = "okButton"
Me.okButton.TabIndex = 0
Me.okButton.Text = "&OK"
Me.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.cancelBtn.Location = New System.Drawing.Point(200, 56)
Me.cancelBtn.Name = "cancelBtn"
Me.cancelBtn.TabIndex = 1
Me.cancelBtn.Text = "&Cancel"
Me.label1.Location = New System.Drawing.Point(32, 8)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(288, 16)
Me.label1.TabIndex = 2
Me.label1.Text = "label1"
Me.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.textBox1.Location = New System.Drawing.Point(32, 32)
Me.textBox1.Name = "textBox1"
Me.textBox1.Size = New System.Drawing.Size(296, 20)
Me.textBox1.TabIndex = 3
Me.textBox1.Text = "textBox1"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(352, 93)
Me.Controls.Add(Me.textBox1)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.cancelBtn)
Me.Controls.Add(Me.okButton)
Me.Name = "InputForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "InputForm"
Me.ResumeLayout(False)



[/indent]
End Sub










Private Sub SetFromArgs(ByVal args As PromptFormArgs)
[indent]Me.Text = args._title



Me.label1.Text = args._prompt
Me.textBox1.Text = args._default



[/indent]
End Sub










Public Shared Function PromptQuery(ByVal args As PromptFormArgs, ByRef result As String) As Boolean
[indent]Dim frm As New InputForm 










Try[indent]result = Nothing 










If args Is Nothing Then[indent]frm.SetFromArgs(New PromptFormArgs)






[/indent]
Else
[indent]frm.SetFromArgs(args)






[/indent]
End If 











If frm.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
[indent]result = frm.textBox1.Text




Return True



[/indent]
Else
[indent]Return False 






[/indent]
End If







[/indent]Finally
[indent]frm.Dispose() 






[/indent]
End Try 






[/indent]End Function












Public Shared Function PromptString(ByVal args As PromptFormArgs) As String
[indent]Dim frm As New InputForm












Try[indent]If args Is Nothing Then[indent]frm.SetFromArgs(New PromptFormArgs)






[/indent]
Else
[indent]frm.SetFromArgs(args)






[/indent]
End If












If frm.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
[indent]Return frm.textBox1.Text 






[/indent]
Else
[indent]Return Nothing[/indent]
End If








[/indent]Finally
[indent]frm.Dispose()[/indent]
End Try






[/indent]End Function












Private Sub textBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged
[indent]okButton.Enabled = textBox1.Text <> ""[/indent]
End Sub 






[/indent]End Class












Public Class PromptFormArgs
[indent]Friend _title As String = System.Windows.Forms.Application.ProductName




Friend _prompt As String = "Value Required"
Friend _default As String = "[Not Set]"

Friend Sub New()
End Sub









Public Sub New(ByVal title As String, ByVal prompt As String, ByVal defaultValue As String)[indent]_title = title _prompt = prompt



_default = defaultValue



[/indent]
End Sub 












Public Shared ReadOnly Property Empty() As PromptFormArgs
[indent]Get[indent]Return Nothing 






[/indent]
End Get






[/indent]End Property






[/indent]End Class 





End Namespace

 

 

 

[/indent]

TestDialog.zip

Edited by Joe Mamma

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • Administrators
Posted
In most cases you are probably better off building your own dialog to handle the specific input request and take full advantage of other controls (comboboxes, error providers etc.) rather than mimic the InputBox - which I always felt looked ugly and was severely limited in terms of how you could offer help to the user.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Thanks, Joe. I'll definitely have to give that a try at some point when I have a bit more time to dig into it.

 

 

 

 

In most cases you are probably better off building your own dialog to handle the specific input request and take full advantage of other controls (comboboxes' date=' error providers etc.) rather than mimic the InputBox - which I always felt looked ugly and was severely limited in terms of how you could offer help to the user.[/quote']

 

 

I definitely agree. I only use it for in-house apps (or ones at home) that are "quick and dirty." I'd never use in in the final version of a production app for external users.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...