다음과 같이 WinForm 환경에서 텍스트의 선택 강조 색상을 변경할 수 있습니까?
WinForm에서는 해당 컬러값은 시스템값을 사용하기 때문에
시스템 색상표에 해당하는 COLOR_HIGHLIGHT(13) 값을 변경하면 가능합니다. (SetSysColor)
하지만 시스템 설정값을 강제로 바꾼다면 다음과 같이 사용자에게 불편함을 안겨줄 수 있습니다.
WPF에서는 Selection Brush Color를 지원하고 있습니다.
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms.Integration;
using System.Windows.Media;
public class MyWPFTextBox : System.Windows.Forms.UserControl
{
private ElementHost elementHost = new ElementHost();
private TextBox textBox = new TextBox();
public MyWPFTextBox()
{
textBox.SelectionBrush = new SolidColorBrush(Colors.Gray);
textBox.SelectionOpacity = 0.5;
textBox.TextAlignment = TextAlignment.Left;
textBox.VerticalContentAlignment = VerticalAlignment.Center;
elementHost.Dock = System.Windows.Forms.DockStyle.Fill;
elementHost.Name = "elementHost";
elementHost.Child = textBox;
textBox.TextChanged += (s, e) => OnTextChanged(EventArgs.Empty);
Controls.Add(elementHost);
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
}