2016-11-28 25 views
1

ToolStripButton이있는 ToolStrip이 포함 된 WinForms 응용 프로그램이 있습니다. 일부 단추 조치는 단추 조치가 수행되는 동안 기본 양식을 사용 불가능하게하고 완료 될 때 다시 사용 가능하게합니다. 이 작업은 작업이 수행되는 동안 다른 장소를 클릭하지 않고 WaitCursor를 표시하지만 문제와 관련이 없는지 확인하기 위해 수행됩니다.양식이 비활성화되거나 활성화 될 때 ToolStripButton이 여전히 강조 표시됩니다.

양식을 사용할 수 없을 때 사용자가 단추를 클릭하고 경계 밖으로 마우스 커서를 이동하면 나중에 양식을 다시 활성화 할 때도 단추는 강조 표시 된 채로 유지됩니다 (투명 파란색). 마우스가 버튼을 입력/나가면 다시 올바르게 표시됩니다.

다음 코드를 사용하여 MessageBox를 표시하여 인위적으로 문제를 복제 할 수 있습니다. 실제 작업은 메시지 상자를 표시하지 않지만 새 양식을 열고 표를 채우지 만 그물 효과는 동일합니다.

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void toolStripButton1_Click(object sender, EventArgs e) 
    { 
     // Disable the form 
     Enabled = false; 

     // Some action where the user moved the mouse cursor to a different location 
     MessageBox.Show(this, "Message"); 

     // Re-enable the form 
     Enabled= true; 
    } 
} 
+0

당신을 했을

나는 부모의 ToolStrip의 개인 방법 "ClearAllSelections"을 호출 반사를 사용이 확장 방법을 만들어 'toolStripButton1_Click'의 첫 번째 줄에'this.Refresh();'를 추가해보십시오. – ispiro

+0

이제 MessageBox를 닫으면 코드가 사라지고 파란색 배경이 사라집니다. – ispiro

+0

@ispiro 'this.Refresh();'로 시도했지만 여전히 문제가 발생합니다. 아마도 당신은 마우스로 클릭하는 대신 Enter를 사용하여 MessageBox를 닫았을 것입니까? 관련성이 있는지는 모르겠지만 Visual Studio 2013 및 .NET Framework 4.5를 사용하고 있습니다. – Andres

답변

2

나는 마침내 해결책을 발견 : 여기

문제를 복제 할 수있는 코드이다.

public static void ClearAllSelections(this ToolStrip toolStrip) 
    { 
     // Call private method using reflection 
     MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance); 
     method.Invoke(toolStrip, null); 
    } 

양식 다시 활성화 한 후 호출 :

private void toolStripButton1_Click(object sender, EventArgs e) 
{ 
    // Disable the form 
    Enabled = false; 

    // Some action where the user moved the mouse cursor to a different location 
    MessageBox.Show(this, "Message"); 

    // Re-enable the form 
    Enabled= true; 

    // Hack to clear the button highlight 
    toolStrip1.ClearAllSelections(); 
}