Results 1 to 3 of 3

Thread: Extended InputBox Function

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Post Extended InputBox Function

    I made the following function because Kleinma was asking about why the inputbox function wouldn't allow dialog results and wouldn't allow the prompt message to get bigger like it did in VB6...one of those things that M$ seemed to forget. so i wrote my own version on the InputBox function and made it much like the MessageBox.Show function...in fact i named it InputMessageBox.Show... if you download the source do whatever you'd like...i'm going to try and add more functionality to it in the future...like adding icons...being about to validation...etc...but for now here's the basic with a TestBed project to see how it works...one thing i would suggest is not to change anything in the ComputerLabelHeight routine...feel free to...just a suggestion. well here it is hope you like it
    Attached Files Attached Files

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2
    New Member
    Join Date
    Jul 2009
    Posts
    1

    Thumbs up Re: Extended InputBox Function

    Just wanted to let you know that I love your add-on!

    Also, I have updated it a little bit, and yes, I did do a major revision to your ComputeLabelHeight function.

    In my program, I format my message with vbNewLine's quite a bit, and your InputBox worked great, except it wouldn't show anything past 5 lines.

    After a bit of playing around with the numbers, I came up with the following:

    Code:
        Private Sub ComputeLabelHeight(ByVal sz As String)
            Dim fnt As New Font(Me.lblPrompt.Font.Name, Me.lblPrompt.Font.Size)
            ' Compute the string dimensions in the given font
            Dim bmp As Bitmap = New Bitmap(1, 1, Drawing.Imaging.PixelFormat.Format32bppArgb)
            Dim gph As Graphics = Graphics.FromImage(bmp)
    
            Dim lineHeight As Integer = CInt(Me.lblPrompt.Font.Height * 1.25)
            Dim stringSize As SizeF = gph.MeasureString(sz, fnt)
            Dim lines As Integer = CInt((Math.Floor(stringSize.Width) + ((Split(sz, vbNewLine).Length) * Me.lblPrompt.Width)) / Me.lblPrompt.Width)
    
            Me.lblPrompt.Height = (lines * lineHeight)
            Me.Height = Me.lblPrompt.Top + (lines * lineHeight) + 72
    
            gph.Dispose()
            bmp.Dispose()
        End Sub
    This will allow any number of lines to be shown in your InputBox. I've also set the form's minimum height to 30 (just below the Cancel button).

    In addition, I've also appended to the end of your .vb file two "flavors" of the traditional InputBox. They are both detailed below:

    Code:
    Module InputMessageBoxFunctions
        Private Const CANCEL As String = Chr(24)
    
        'Function: myInputBox
        'Purpose: Provides the user with a VB.NET InputBox with one exception:
        '         it can tell the user whether or not the Cancel button has been
        '         pressed.
        '         The difference between this function and the VB.NET InputBox
        '         is that the VB.NET InputBox only returns "" (aka String.Empty or
        '         Nothing) when the Cancel button is pushed whether or not anything
        '         has been entered into the InputBox. It wasn't made clear enough
        '         to me when the Cancel button was pressed, hence this function.
        'Parameters: Takes same parameters as a VB.NET InputBox
        'Returns: If OK was pressed, will return the text typed in.
        '         If Cancel was pressed, it will return the "Cancel" ASCII character
        Public Function myInputBox(ByVal Prompt As String, Optional ByVal Title As String = "", Optional ByVal DefaultResponse As String = "") As String
            Dim result As InputDialogResults.InputMsgResults = InputMessageBox.Show(Prompt, Title, DefaultResponse)
    
            If result.DialogResult = InputDialogResults.InputMsgResults.InputDialogResult.OK Then
                myInputBox = result.Response
            Else
                myInputBox = CANCEL
            End If
        End Function
    
        'Function: InputBox
        'Purpose: Extremely similar to the VB.NET InputBox, except that upon the
        '         user clicking the Cancel button, rather than returning "" (aka
        '         String.Empty or Nothing), this will return the Default Response.
        'Parameters: Takes same parameters as a VB.NET InputBox
        'Returns: If OK was pressed, will return the text typed in.
        '         If Cancel was pressed, it will return the Default Response.
        Public Function InputBox(ByVal Prompt As String, Optional ByVal Title As String = "", Optional ByVal DefaultResponse As String = "") As String
            InputBox = myInputBox(Prompt, Title, DefaultResponse)
    
            If InputBox = CANCEL Then
                InputBox = DefaultResponse
            End If
        End Function
    End Module
    I appreciate your add-on very much! I'm glad someone finally put the time in to make one. (Thank you!)

    I have attached the updated file for those of you who'd rather not copy/paste.

    Enjoy!
    Attached Files Attached Files
    Last edited by starryknight64; Jul 1st, 2009 at 03:32 PM. Reason: Added attachment

  3. #3

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Extended InputBox Function

    Glad someone likes it. I will have to update my version with the updates you added. Again thanks for the complements

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width