Reputation: 19
I have a form in C# that has some buttons. I want that when the button is pressed, make the text bold.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\priority\bin.95\WINMENU.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
}
private void button2_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Program Files\UltraVNC\vncviewer.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button3_Click_1(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Program Files\UltraVNC\vncviewer.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
}
private void button4_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Windows\system32\mstsc.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
}
private void button5_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Program Files\Microsoft Office\Office14\winword.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
what should I do now ?
Upvotes: 1
Views: 7312
Reputation: 25
Here is the code:
private void button1_Click(object sender, EventArgs e)
{
button1.Font = new Font(this.Font, FontStyle.Bold);
}
Upvotes: 0
Reputation: 292
@hyprsleepy - i dont think that your answer can work because the property Button.Font.Bold is read only so you can only read the value to see what it is currently set as.
@asher - where you have these events:
private void button5_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Program Files\Microsoft Office\Office14\winword.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
}
use similar syntax to this:
private void button5_Click(object sender, EventArgs e)
{
// string str = @"C:\windows\system32\notepad.exe";
// string str = @"C:\windows\system32\winamp.exe";
string str = @"C:\Program Files\Microsoft Office\Office14\winword.exe";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
Button b = ((Button)sender);
b.Font = new Font(b.Font, FontStyle.Bold);
}
Upvotes: 1
Reputation: 292
Use the Click event for the button, something like this:
private void button_Click(object sender, EventArgs e)
{
Button b = ((Button)sender);
b.Font = new Font(b.Font, FontStyle.Bold);
}
Upvotes: 3