简体   繁体   English

在c#visual studio中使用文本框或标签,如按钮

[英]Using a textbox or label like a button in c# visual studio

Is it possible to use a label or textbox in the same way you would use a button in ac# visual studio document? 是否可以像使用ac#visual studio文档中的按钮一样使用标签或文本框?

ie can it be selected and have a result similiar to a button being clicked? 即它是否可以被选中并且具有与点击按钮类似的结果?

It would be best to use a link label. 最好使用链接标签。 That way whenever the mouse hovers over it, the person knows that clicking on it causes an action. 这样,只要鼠标悬停在它上面,该人就知道点击它会导致动作。

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
      {
        MessageBox.Show("you have clicked a link label");
        //or whatever action you want it to do.
      }

For Click Event : 对于Click事件:

You can use the Label.Click event or TextBox.Click event 您可以使用Label.Click事件或TextBox.Click事件


For Event when Some Text is selected in the TextBox : 对于在TextBox选择某些文本时的事件:

Although there is no Special Event For this, You can Utilize the TextBox.MouseUp event like this : 虽然没有特殊事件为此,您可以像这样使用TextBox.MouseUp事件:

private void txtBox_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) 
{
    TextBox txtbx = sender as TextBox;
    if (txtbx != null)
    {
        if (txtbx.SelectionLength > 0)
        {
            string seltxt = txtbx.SelectedText;
            //Do Work Here with 'seltxt' variable!
        }
    }
}

I guess you could use anything as a button if you wanted to, but why would you want to rather than using a button? 我想你可以使用任何东西作为按钮,但你为什么要而不是使用按钮?

http://msdn.microsoft.com/en-us/library/system.windows.forms.label_events http://msdn.microsoft.com/en-us/library/system.windows.forms.label_events

Everything that is a Control object in WinForms has a "Click" event that can be used. WinForms中作为Control对象的所有内容都有一个可以使用的“Click”事件。 Subscribe to that event with a custom method and do what you want to do in that event. 使用自定义方法订阅该事件,并在该事件中执行您想要执行的操作。 If you want the label to have a button look-and-feel I'd suggest putting a border and some hover, press and release decorations using the appropriate events. 如果您希望标签具有按钮外观,我建议使用边框和一些悬停,使用适当的事件按下并释放装饰。

Hope this helps. 希望这可以帮助。

他们也有Click事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#:如何在Visual Studio 2012中将诸如标签或文本框值之类的文本从窗体发送到Crystal报表? - C#: How to send text like label or textbox value from form to crystal reports in visual studio 2012? 删除按钮上的文本框/标签,单击C# - Removing textbox/label on button click C# 在 Visual Studio C# 中使用文本框过滤 DataGridView - Filter a DataGridView with Textbox in Visual Studio C# Visual Studio C#中的文本框验证 - TextBox Validation in Visual Studio C# 限制TextBox Visual Studio C#的内容 - Limiting Contents of a TextBox Visual Studio C# C#Visual Studio文本框转换为文本文件 - c# visual studio textbox into textfile Visual Studio C#将文本框连接到数据库 - visual studio C# connect textbox to database 如何在 Visual Studio C# 中制作一个将特定文本插入文本框中的按钮? - How do i make a button that inserts A Certain text into a textbox in Visual Studio C#? 将鼠标悬停在C#中的按钮效果上(使用Visual Studio 05) - Mouse Over Effects for Button in C# (using Visual Studio 05) 需要一些帮助,使用C#将SQL数据库中的单个文本检索到Visual Studio中的文本框中 - Need some help of retrieving a single text from SQL database into a textbox in Visual Studio using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM