2017-02-11 2 views

답변

0

WinForms에서 콤보 상자의 스타일에 대해 잘 모르지만 System.Drawings.Graphics를 사용하여 원하는대로 정확하게 작업 할 수 있습니다. 다음 코드 스 니펫을 확인하십시오.

public partial class Form1 : Form 
{ 
    System.Drawing.Graphics graphics; 
    System.Drawing.Rectangle rectangle; 

    public Form1() 
    { 
     InitializeComponent(); 
     comboBox1.Enter += ComboBox1_Enter; 
     comboBox1.Leave += ComboBox1_Leave; 
    } 

    private void ComboBox1_Leave(object sender, EventArgs e) 
    { 
     graphics.Clear(this.BackColor); 
    } 

    private void ComboBox1_Enter(object sender, EventArgs e) 
    { 
     ChangeActiveControlStyle((Control)sender); 
    } 

    private void ChangeActiveControlStyle(Control control) 
    { 
     graphics = this.CreateGraphics();   
     rectangle = new System.Drawing.Rectangle(control.Location.X -2, control.Location.Y-2, control.Width+4, control.Height+4); 
     graphics.FillRectangle(Brushes.Yellow, rectangle); 
    } 
} 
관련 문제