can you write a program in c# so that when user mouseover on any existing buttons it will show its class name
Sure! Here's a simple program written in C# that displays the class name of a button when the user hovers over it:
using System;
using System.Windows.Forms;
namespace ButtonClassName
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_MouseHover(object sender, EventArgs e)
{
Button button = (Button)sender;
MessageBox.Show($"Class Name: {button.GetType().Name}");
}
}
}
To use this program, follow these steps:
- Create a new Windows Forms Application project in Visual Studio.
- Replace the contents of the
MainForm.csfile with the code provided. - Add a button to the form (e.g.,
button1). - Double-click on the form to generate the
InitializeComponent()method. - Build and run the program.
Now, when you hover over the button, a message box will appear displaying its class name
原文地址: http://www.cveoy.top/t/topic/hRjR 著作权归作者所有。请勿转载和采集!