When you want to change display text of the Button , you can change the Text property of the button.
button1.Text = "Click Here";
Similarly if you want to load an Image to a Button control , you can code like this.
How to Call a Button's Click Event Programmatically
button1.Image = Image.FromFile("C:\\testimage.jpg");
The Click event is raised when the Button control is clicked. This event is commonly used when no command name is associated with the Button control. Raising an event invokes the event handler through a delegate.
private void Form1_Load(object sender, EventArgs e)
{
Button b = new Button();
b.Click += new EventHandler(ShowMessage);
Controls.Add(b);
}
private void ShowMessage(object sender, EventArgs e)
{
MessageBox.Show("Button Click");
}
The following C# source code shows how to change the button Text property while Form loading event and to display a message box when pressing a Button Control.
Example code :
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "Click Here";
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("https://www.hungvb.com/csharp");
}
}
}
Good luck.
Nhưng thứ này thì cơ bản với các coder r :D
Trả lờiXóaChắc cũng nên tình hiểu C# quá...
Trả lờiXóa