下拉多行文本框 [英] dropdown multiline textbox

查看:129
本文介绍了下拉多行文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建具有下拉功能的文本框?

当用户在其中单击开始输入内容时,我需要一个TextBox进行扩展

当我单击或输入单个文本框时,多行文本框应出现在文本框下方
例如组合框.

我正在寻找C#中的组合框之类的东西,当我按下文本框旁边的按钮时,该文本框下方应显示一个多行文本框.
我知道多行文本框和自动完成文本框.

您可以在Visual Studio的文本字段的文本框属性中找到所需的内容.
此属性对于没有足够空间的表单很有用.

您可以输入多行文本框,然后在多行文本框关闭后在文本框中看到它的第一行.

How can I create a text box with drop down ability?

i need a single TextBox to expand when the user clicks inside it to begin typing

When I click or enter single text box, a multi line text box should appear under text box
like combo box for instance.

I am looking for something like combo box in C# and when I press button beside text box, a multi line text box should appear under that.
I know multi line text box and auto complete text box.

You can find what I need in Visual Studio in the properties of a text box in text field.
This attribute is useful for forms that do not have enough space.

You can type in multi line text box and after that multi line text box closes and you see first line of it in text box.

is there any component?

推荐答案

你好,
这是我的解决方案:

我创建了一个仅带textBox1的简单表单应用程序,
重要的是,文本框可以使用以下命令更改其尺寸(以像素为单位):textBox1.Width和textBox.Height最初为300 x 200像素

文本框的大小也将通过鼠标单击打开和鼠标双击关闭来更改

MainForm.cs的代码:

Hello,
here is my solution :

I have created simple form application with only textBox1 on it,
the important thing is that the text box can change its dimensions in pixels using : textBox1.Width and textBox.Height initially it is 300 x 200 pixels

Also size of the text box will be changed by mouse click to open and mouse double click to close

code for MainForm.cs:

/*
 * Created by SharpDevelop.
 * User: Peric Zeljko
 * Date: 6.10.2011
 * Time: 14:10
 *
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Test_app
{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
        public MainForm()
        {
            //
            // The InitializeComponent() call is required for 
            //  Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Initially Set Height to only one line ,
            //        watch out for font size in text box it is set to 8
            //         Width is 300
            //
            textBox1.Multiline = false;
            textBox1.Width = 300;
            textBox1.Height = 20;
            textBox1.Refresh();
        }

        void TextBox1MouseClick(object sender, MouseEventArgs e)
        {
            // TODO: Implement TextBox1MouseClick
            // When you click with mouse on text box it opens
            // by changing its Height
            textBox1.Multiline = true;
            textBox1.Width = 300;
            textBox1.Height = 200;
            textBox1.Refresh();
        }

        void TextBox1MouseDoubleClick(object sender, MouseEventArgs e)
        {
            // TODO: Implement TextBox1MouseDoubleClick
            // When you double click with mouse on text box it closes
            // by changing its Height
            textBox1.Multiline = false;
            textBox1.Multiline = true;
            textBox1.Width = 300;
            textBox1.Height = 20;
            textBox1.Refresh();
        }
    }
}




现在,可以将多行文本输入到仅可见的一行中,
只需输入即可分隔文本行,然后单击以打开所有行.也就是在文本框中输入文本行,然后双击
它关闭的文本框,因此第一行是可见的.

Program.cs的代码:





Right now it is possible to enter multiline text into only one line visible,
separating text lines with simply enter, and when you click to open all lines are there.Allso when you enter text lines into text box , and double click
the text box it closes, allso the first line is visible.

code for Program.cs:


/*
 * Created by SharpDevelop.
 * User: Peric Zeljko
 * Date: 6.10.2011
 * Time: 14:10
 *
 */
using System;
using System.Windows.Forms;

namespace Test_app
{
    /// <summary>
    /// Class with program entry point.
    /// </summary>
    internal sealed class Program
    {
        /// <summary>
        /// Program entry point.
        /// </summary>
        [STAThread]
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }

    }
}




和MainForm.Designer.cs的代码





and code for MainForm.Designer.cs


/*
 * Created by SharpDevelop.
 * User: Peric Zeljko
 * Date: 6.10.2011
 * Time: 14:10
 *
 */
namespace Test_app
{
    partial class MainForm
    {
        /// <summary>
        /// Designer variable used to keep track of non-visual components.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Disposes resources used by the form.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                if (components != null) {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        /// <summary>
        /// This method is required for Windows Forms designer support.
        /// Do not change the method contents inside the source code editor. The Forms designer might
        /// not be able to load this method if it was changed manually.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(3, 12);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(300, 200);
            this.textBox1.TabIndex = 2;
            this.textBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.TextBox1MouseDoubleClick);
            this.textBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.TextBox1MouseClick);
            //
            // MainForm
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(348, 244);
            this.Controls.Add(this.textBox1);
            this.Name = "MainForm";
            this.Text = "Test app";
            this.ResumeLayout(false);
            this.PerformLayout();
        }
        public System.Windows.Forms.TextBox textBox1;

    }
}




我希望这段代码足以解决您的问题.

祝一切顺利,
佩里克(Peric Zeljko)
< removed> @ yahoo.com




I hope that this code would be enough to resolve your problem.

All the best,
Peric Zeljko
<removed>@yahoo.com


我不确定您要寻找的是什么,但我会猜测.
如果您正在寻找自动完成功能(例如当您在Google搜索文本框中键入内容时),则可以使用以下内容;

AJAX工具包 [
I am not sure exactly what you are looking for but I am going to guess.
If you are looking for an auto complete like when you type in the google search text box you can use the following;

AJAX TOOL KIT[^]

If you just want the text box to extend to multiline you will have to set the property to multi rows and set the number of rows. You can do this with javascript or witht the code behind or both.

If this isn''t what you are looking for update your post with more info.


这篇关于下拉多行文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆