public void SetFont(Font font) { if (control.IsDisposed) return; if (control.InvokeRequired) { SetFontDelegate del = new SetFontDelegate(SetFont); control.Invoke(del, new object[] { font }); } else control.Font = font; }
public void SetFont(Font font) { if (control.IsDisposed) { return; } if (control.InvokeRequired) { SetFontDelegate del = new SetFontDelegate(SetFont); control.Invoke(del, new object[] { font }); } else { control.Font = font; } }
/// <summary> /// 設定對話框文字顏色 /// </summary> /// <param name="text"></param> public void SetFont(string text) { if (rtf_MessageInfo.InvokeRequired) { SetFontDelegate d = new SetFontDelegate(SetFont); this.Invoke(d, new object[] { text }); } else { string[] splitString = text.ToLower().Split(','); if (splitString[3] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Bold); } if (splitString[4] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Italic); } if (splitString[5] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Underline); } if (splitString[5] == "true" && splitString[4] == "true" && splitString[4] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Underline | FontStyle.Bold | FontStyle.Italic); } if (splitString[3] == "true" && splitString[4] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Bold | FontStyle.Italic); } if (splitString[5] == "true" && splitString[3] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Underline | FontStyle.Bold); } if (splitString[5] == "true" && splitString[3] == "true") { rtf_MessageInfo.SelectionFont = new Font(splitString[0], float.Parse(splitString[1]), FontStyle.Underline | FontStyle.Italic); } string color = splitString[2]; switch (color) { case "黑色": rtf_MessageInfo.SelectionColor = Color.Black; break; case "紅色": rtf_MessageInfo.SelectionColor = Color.Red; break; case "橘色": rtf_MessageInfo.SelectionColor = Color.Orange; break; case "黃色": rtf_MessageInfo.SelectionColor = Color.Yellow; break; case "綠色": rtf_MessageInfo.SelectionColor = Color.Green; break; case "藍色": rtf_MessageInfo.SelectionColor = Color.Blue; break; case "紫色": rtf_MessageInfo.SelectionColor = Color.Purple; break; } } }