這是期末考的題目之一(使用Visual Studio):
messagebox.show("有變化嗎");


-------------------------------------------------------------------------------------------------------
string fontName = comboBox1.SelectedItem.ToString();
textBox1.Font = new Font(fontName, 20);

-------------------------------------------------------------------------------------------------------
1.GroupBox + RadioButton + CheckBox

-------------------------------------------------------------------------------------------------------
private void Style_CheckedChanged(object sender, EventArgs e){ }
CheckedChanged 指到 Style_CheckedChanged
三個checkbox的CheckedChanged事件 都填上Style_CheckedChanged)

-------------------------------------------------------------------------------------------------------
FontStyle something = FontStyle.Regular;


something |= FontStyle.Bold;


-------------------------------------------------------------------------------------------------------
textBox1.Font = new Font(
textBox1.Font.FontFamily,
textBox1.Font.Size,
textBox1.Font.Style
);

-------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------
改顏色 textBox1.ForeColor = Color.Red;
-------------------------------------------------------------------------------------------------------
改畫面背景this.BackColor = Color.Yellow;
-------------------------------------------------------------------------------------------------------
成品:
namespace WinFormsApp4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "早安";
textBox1.Font = new Font(
textBox1.Font.FontFamily,
20,
textBox1.Font.Style
);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("有變化嗎");
string something = comboBox1.SelectedItem.ToString();
textBox1.Font = new Font(something, 20);
}
private void Style_CheckedChanged(object sender, EventArgs e)
{
MessageBox.Show("有反應嗎");
FontStyle something = FontStyle.Regular;
if (checkBox1Bold.Checked)
something |= FontStyle.Bold;
if (checkBox2Italic.Checked)
something |= FontStyle.Italic;
if (checkBox3Underline.Checked)
something |= FontStyle.Underline;
textBox1.Font = new Font(textBox1.Font.FontFamily, textBox1.Font.Size, something);
}
private void colorCheckedChange(object sender, EventArgs e)
{
if (radioButton1Red.Checked)
textBox1.ForeColor = Color.Red;
else if (radioButton2Yellow.Checked)
textBox1.ForeColor = Color.Yellow;
else if (radioButton3Green.Checked)
textBox1.ForeColor = Color.Green;
}
private void backCheckedChange(object sender, EventArgs e)
{
if (radioButton4Red.Checked)
this.BackColor=Color.Black;
else if (radioButton5White.Checked)
this.BackColor = Color.White;
else if (radioButton6Blue.Checked)
this.BackColor = Color.Blue;
}
}
}
*我是最前*
*我是最後*



















