[英]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.
}
Click
Event : 对于Click
事件: You can use the Label.Click
event or TextBox.Click
event 您可以使用Label.Click
事件或TextBox.Click
事件
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.