Inputbox

11 posts, 1 answers
  1. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 09 Dec 2010 Link to this post

    Hi,

    I would like to suggest an Inputbox for the Winforms control set. I think if you offer a radmessagebox it would only be normal to include an Inputbox.

    Thanks
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 10 Dec 2010 Link to this post

    Hi Dean,

    I think that this would be something that would be quite easy to make as a user control. If I get the time, I'll try and put one together for you.
    All the best
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 10 Dec 2010 Link to this post

    Thanks alot Richard
  5. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 10 Dec 2010 Link to this post

    Hi Dean,

    Have a go with this. It's pretty simple, but an Input Box isn't too complex. It can probably be improved but it's a start. Just create a new class called RadInputBox and drop in the following code:

    Imports Telerik.WinControls
    Imports Telerik.WinControls.UI
      
    Public Class RadInputBox
      
        Shared Function Show(ByVal Prompt As String, ByVal Title As String, Optional ByVal DefaultResponse As String = "") As String
            Dim inputBox As New RadInputBoxInternal()
            inputBox.StartPosition = FormStartPosition.CenterParent
            inputBox.LabelQuestion.Text = Prompt
            inputBox.Text = Title
      
            If inputBox.ShowDialog() = DialogResult.OK Then
                Return inputBox.TextBoxInput.Text
            Else
                Return DefaultResponse
            End If
        End Function
      
        Private Class RadInputBoxInternal
            Inherits Telerik.WinControls.UI.RadForm
      
            Friend Sub New()
                Me.InitializeComponent()
            End Sub
      
            <System.Diagnostics.DebuggerNonUserCode()> _
            Protected Overrides Sub Dispose(ByVal disposing As Boolean)
                Try
                    If disposing AndAlso components IsNot Nothing Then
                        components.Dispose()
                    End If
                Finally
                    MyBase.Dispose(disposing)
                End Try
            End Sub
      
            Private components As System.ComponentModel.IContainer
      
            <System.Diagnostics.DebuggerStepThrough()> _
            Private Sub InitializeComponent()
                Me.ButtonOk = New Telerik.WinControls.UI.RadButton()
                Me.ButtonCancel = New Telerik.WinControls.UI.RadButton()
                Me.TextBoxInput = New Telerik.WinControls.UI.RadTextBox()
                Me.LabelQuestion = New Telerik.WinControls.UI.RadLabel()
                CType(Me.ButtonOk, System.ComponentModel.ISupportInitialize).BeginInit()
                CType(Me.ButtonCancel, System.ComponentModel.ISupportInitialize).BeginInit()
                CType(Me.TextBoxInput, System.ComponentModel.ISupportInitialize).BeginInit()
                CType(Me.LabelQuestion, System.ComponentModel.ISupportInitialize).BeginInit()
                CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
                Me.SuspendLayout()
                '
                'ButtonOk
                '
                Me.ButtonOk.Location = New System.Drawing.Point(342, 12)
                Me.ButtonOk.Name = "ButtonOk"
                Me.ButtonOk.Size = New System.Drawing.Size(97, 24)
                Me.ButtonOk.TabIndex = 0
                Me.ButtonOk.Text = "Ok"
                '
                'ButtonCancel
                '
                Me.ButtonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
                Me.ButtonCancel.Location = New System.Drawing.Point(342, 42)
                Me.ButtonCancel.Name = "ButtonCancel"
                Me.ButtonCancel.Size = New System.Drawing.Size(97, 24)
                Me.ButtonCancel.TabIndex = 1
                Me.ButtonCancel.Text = "Cancel"
                '
                'TextBoxInput
                '
                Me.TextBoxInput.Location = New System.Drawing.Point(13, 87)
                Me.TextBoxInput.Name = "TextBoxInput"
                Me.TextBoxInput.Size = New System.Drawing.Size(426, 20)
                Me.TextBoxInput.TabIndex = 2
                Me.TextBoxInput.TabStop = False
                '
                'LabelQuestion
                '
                Me.LabelQuestion.AutoSize = False
                Me.LabelQuestion.Location = New System.Drawing.Point(13, 12)
                Me.LabelQuestion.Name = "LabelQuestion"
                Me.LabelQuestion.Size = New System.Drawing.Size(323, 69)
                Me.LabelQuestion.TabIndex = 3
                Me.LabelQuestion.Text = "text"
                '
                'RadForm1
                '
                Me.AcceptButton = Me.ButtonOk
                Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
                Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
                Me.CancelButton = Me.ButtonCancel
                Me.ClientSize = New System.Drawing.Size(451, 119)
                Me.Controls.Add(Me.LabelQuestion)
                Me.Controls.Add(Me.TextBoxInput)
                Me.Controls.Add(Me.ButtonCancel)
                Me.Controls.Add(Me.ButtonOk)
                Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
                Me.MaximizeBox = False
                Me.MinimizeBox = False
                Me.Name = "RadInputInternal"
                '
                '
                '
                Me.RootElement.ApplyShapeToControl = True
                Me.Text = "RadInputInternal"
                CType(Me.ButtonOk, System.ComponentModel.ISupportInitialize).EndInit()
                CType(Me.ButtonCancel, System.ComponentModel.ISupportInitialize).EndInit()
                CType(Me.TextBoxInput, System.ComponentModel.ISupportInitialize).EndInit()
                CType(Me.LabelQuestion, System.ComponentModel.ISupportInitialize).EndInit()
                CType(Me, System.ComponentModel.ISupportInitialize).EndInit()
                Me.ResumeLayout(False)
                Me.PerformLayout()
      
            End Sub
            Friend WithEvents ButtonOk As Telerik.WinControls.UI.RadButton
            Friend WithEvents ButtonCancel As Telerik.WinControls.UI.RadButton
            Friend WithEvents TextBoxInput As Telerik.WinControls.UI.RadTextBox
            Friend WithEvents LabelQuestion As Telerik.WinControls.UI.RadLabel
      
            Private Sub RadForm1_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
                Me.TextBoxInput.SelectionLength = 0
                Me.TextBoxInput.Focus()
            End Sub
      
            Private Sub ButtonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click
                Me.DialogResult = Windows.Forms.DialogResult.Cancel
                Me.Close()
            End Sub
      
            Private Sub ButtonOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOk.Click
                Me.DialogResult = DialogResult.OK
                Me.Close()
            End Sub
      
        End Class
    End Class


    and call it like so...
    Private Sub RadButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
        Me.RadTextBox1.Text = RadInputBox.Show("What's your name?", "Name")
    End Sub


    screenshot attached.. hope this helps
    Richard
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 13 Dec 2010 Link to this post

    Hello, 

    how did this go? If it helped, please remember to mark as answer. 
    Thanks
    Richard
  7. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 13 Dec 2010 Link to this post

    Hi Richard,

    Thanks a lot for your help with the Inputbox, it's much appreciated.
  8. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 13 Dec 2010 Link to this post

    Oh, I would still like to put this forward as a suggestion to add this to the WinForms Control Set.
  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 14 Dec 2010 Link to this post

    Hello guys, 

    @Dean - in order to create the desired component, you can follow the approach suggested by Richard. I will forward your suggestion to our development team for further discussion.

    @Richard - thank you for your help. Your Telerik Points have been updated accordingly.

    If there is anything else I can assist you with, do not hesitate to contact me.
     
    Greetings,
    Stefan
    the Telerik team
    Get started with RadControls for WinForms with numerous videos and detailed documentation.
  10. Guy
    Guy avatar
    6 posts
    Member since:
    May 2014

    Posted 29 Oct 2014 Link to this post

    For this input box ,
    Has anyone translate this in C# ?
    regards


  11. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 30 Oct 2014 Link to this post

    Hi Guy,

    Here is the class in C#:

    class RadInputBox
    {
        public static string Show(string Prompt, string Title, string DefaultResponse = "")
        {
            RadInputBoxInternal inputBox = new RadInputBoxInternal();
            inputBox.StartPosition = FormStartPosition.CenterParent;
            inputBox.LabelQuestion.Text = Prompt;
            inputBox.Text = Title;
     
            if (inputBox.ShowDialog() == DialogResult.OK)
            {
                return inputBox.TextBoxInput.Text;
            }
            else
            {
                return DefaultResponse;
            }
        }
     
        private class RadInputBoxInternal : Telerik.WinControls.UI.RadForm
        {
     
            internal RadInputBoxInternal()
            {
                Shown += RadForm1_Shown;
                this.InitializeComponent();
            }
     
            [System.Diagnostics.DebuggerNonUserCode()]
            protected override void Dispose(bool disposing)
            {
                try
                {
                    if (disposing && components != null)
                    {
                        components.Dispose();
                    }
                }
                finally
                {
                    base.Dispose(disposing);
                }
            }
     
            private System.ComponentModel.IContainer components;
     
            [System.Diagnostics.DebuggerStepThrough()]
            private void InitializeComponent()
            {
                this.ButtonOk = new Telerik.WinControls.UI.RadButton();
                this.ButtonCancel = new Telerik.WinControls.UI.RadButton();
                this.TextBoxInput = new Telerik.WinControls.UI.RadTextBox();
                this.LabelQuestion = new Telerik.WinControls.UI.RadLabel();
                ((System.ComponentModel.ISupportInitialize)this.ButtonOk).BeginInit();
                ((System.ComponentModel.ISupportInitialize)this.ButtonCancel).BeginInit();
                ((System.ComponentModel.ISupportInitialize)this.TextBoxInput).BeginInit();
                ((System.ComponentModel.ISupportInitialize)this.LabelQuestion).BeginInit();
                ((System.ComponentModel.ISupportInitialize)this).BeginInit();
                this.SuspendLayout();
                //
                //ButtonOk
                //
                this.ButtonOk.Location = new System.Drawing.Point(342, 12);
                this.ButtonOk.Name = "ButtonOk";
                this.ButtonOk.Size = new System.Drawing.Size(97, 24);
                this.ButtonOk.TabIndex = 0;
                this.ButtonOk.Text = "Ok";
                //
                //ButtonCancel
                //
                this.ButtonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.ButtonCancel.Location = new System.Drawing.Point(342, 42);
                this.ButtonCancel.Name = "ButtonCancel";
                this.ButtonCancel.Size = new System.Drawing.Size(97, 24);
                this.ButtonCancel.TabIndex = 1;
                this.ButtonCancel.Text = "Cancel";
                //
                //TextBoxInput
                //
                this.TextBoxInput.Location = new System.Drawing.Point(13, 87);
                this.TextBoxInput.Name = "TextBoxInput";
                this.TextBoxInput.Size = new System.Drawing.Size(426, 20);
                this.TextBoxInput.TabIndex = 2;
                this.TextBoxInput.TabStop = false;
                //
                //LabelQuestion
                //
                this.LabelQuestion.AutoSize = false;
                this.LabelQuestion.Location = new System.Drawing.Point(13, 12);
                this.LabelQuestion.Name = "LabelQuestion";
                this.LabelQuestion.Size = new System.Drawing.Size(323, 69);
                this.LabelQuestion.TabIndex = 3;
                this.LabelQuestion.Text = "text";
                //
                //RadForm1
                //
                this.AcceptButton = this.ButtonOk;
                this.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.CancelButton = this.ButtonCancel;
                this.ClientSize = new System.Drawing.Size(451, 119);
                this.Controls.Add(this.LabelQuestion);
                this.Controls.Add(this.TextBoxInput);
                this.Controls.Add(this.ButtonCancel);
                this.Controls.Add(this.ButtonOk);
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.Name = "RadInputInternal";
                //
                //
                //
                this.RootElement.ApplyShapeToControl = true;
                this.Text = "RadInputInternal";
                ((System.ComponentModel.ISupportInitialize)this.ButtonOk).EndInit();
                ((System.ComponentModel.ISupportInitialize)this.ButtonCancel).EndInit();
                ((System.ComponentModel.ISupportInitialize)this.TextBoxInput).EndInit();
                ((System.ComponentModel.ISupportInitialize)this.LabelQuestion).EndInit();
                ((System.ComponentModel.ISupportInitialize)this).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();
     
            }
            private Telerik.WinControls.UI.RadButton withEventsField_ButtonOk;
            internal Telerik.WinControls.UI.RadButton ButtonOk
            {
                get { return withEventsField_ButtonOk; }
                set
                {
                    if (withEventsField_ButtonOk != null)
                    {
                        withEventsField_ButtonOk.Click -= ButtonOk_Click;
                    }
                    withEventsField_ButtonOk = value;
                    if (withEventsField_ButtonOk != null)
                    {
                        withEventsField_ButtonOk.Click += ButtonOk_Click;
                    }
                }
            }
            private Telerik.WinControls.UI.RadButton withEventsField_ButtonCancel;
            internal Telerik.WinControls.UI.RadButton ButtonCancel
            {
                get { return withEventsField_ButtonCancel; }
                set
                {
                    if (withEventsField_ButtonCancel != null)
                    {
                        withEventsField_ButtonCancel.Click -= ButtonCancel_Click;
                    }
                    withEventsField_ButtonCancel = value;
                    if (withEventsField_ButtonCancel != null)
                    {
                        withEventsField_ButtonCancel.Click += ButtonCancel_Click;
                    }
                }
            }
            internal Telerik.WinControls.UI.RadTextBox TextBoxInput;
            internal Telerik.WinControls.UI.RadLabel LabelQuestion;
     
            private void RadForm1_Shown(System.Object sender, System.EventArgs e)
            {
                this.TextBoxInput.SelectionLength = 0;
                this.TextBoxInput.Focus();
            }
     
            private void ButtonCancel_Click(System.Object sender, System.EventArgs e)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.Close();
            }
     
            private void ButtonOk_Click(System.Object sender, System.EventArgs e)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
     
        }
    }

    and here is how to use it:
    this.radTextBox1.Text = RadInputBox.Show("What is your name?", "Name");

    FYI you can use our free online converter to convert code between C# and VB at the following address: http://converter.telerik.com/.

    I hope this helps.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Guy
    Guy avatar
    6 posts
    Member since:
    May 2014

    Posted 30 Oct 2014 in reply to Stefan Link to this post

    HI Stefan,
    That's great.
    Thanks for the converter tip ! Very useful !
    Regards .
    Guy

Back to Top
UI for WinForms is Visual Studio 2017 Ready