2009-04-29 3 views
11

CheckedListBox의 항목 위로 사용자의 마우스를 가져 가면 툴팁에 추가 텍스트가 표시되도록 설정할 수 있습니까? 내가 코드에서 할 수 있기를 기대하는 무엇CheckedListBox 항목에 대한 툴팁?

은 다음과 같습니다

uiChkLstTables.DisplayOnHoverMember = "DisplayOnHoverProperty"; //Property contains extended details 

사람이 작업을 수행하려면 올바른 방향으로 날 지점 수 있습니까? 이미 마우스가 어느 항목에 있는지 감지하고 새로운 툴팁 인스턴스를 만드는 몇 가지 기사를 찾았습니다.하지만이 방법이 가장 효과적이라고 생각됩니다.

미리 감사드립니다.

답변

12

양식에 도구 설명 개체를 추가 한 다음 ShowToolTip() 메서드를 호출하는 CheckedListBox.MouseHover에 대한 이벤트 처리기를 추가하십시오. 다음 코드를 가지고 당신의 CheckedListBox의 MouseMove 이벤트를 추가

//Make ttIndex a global integer variable to store index of item currently showing tooltip. 
//Check if current location is different from item having tooltip, if so call method 
if (ttIndex != checkedListBox1.IndexFromPoint(e.Location)) 
       ShowToolTip(); 

는 그 다음 ShowToolTip 방법을 만듭니다

private void ShowToolTip() 
    { 
     ttIndex = checkedListBox1.IndexFromPoint(checkedListBox1.PointToClient(MousePosition)); 
     if (ttIndex > -1) 
     { 
      Point p = PointToClient(MousePosition); 
      toolTip1.ToolTipTitle = "Tooltip Title"; 
      toolTip1.SetToolTip(checkedListBox1, checkedListBox1.Items[ttIndex].ToString()); 

     } 
    } 
+1

의' 포인트 p' 라인은 필요 없습니다 – Maslow

0

인위적인 것; 그게 거기에 무엇입니까 ...

나는 당신이 이미 설명한 것보다 쉬운 방법을 알지 못합니다. (나는 항상 새로운 것을 만드는 것이 아니라 툴팁 인스턴스를 다시 사용합니다). 이것을 보여주는 기사가 있다면, 그것을 사용하십시오. 또는 이것을 기본적으로 지원하는 타사 컨트롤을 사용하십시오 (아무런 도약도하지 마십시오).

5

또는, 대신 체크 박스와 ListView를 사용할 수 있습니다. 이 컨트롤은 입니다. 툴팁에 대한 지원은입니다.

+0

제안 주셔서 감사합니다, 그것을 보지 못했어요. –

+0

성가신 것은 ListView가 데이터 바인딩을 지원하지 않는다는 것입니다. –

0

나는 그의 훌륭한 솔루션을 약간 더 분명하게하기 위해 Fermin의 답변을 확대하고 싶습니다.

.Designer.cs 파일에서 작업하는 형태로 CheckedListBox에 MouseMove 이벤트 처리기를 추가해야합니다 (Fermin은 원래 MouseHover 이벤트 처리기를 제안했지만이 기능은 작동하지 않았습니다). 나를).

this.checkedListBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.showCheckBoxToolTip); 

다음, 두 개의 클래스가 도구 팁 마지막으로

private ToolTip toolTip1; 
private int toolTipIndex; 

나타났다 마지막으로 체크 박스를 추적 할 양식, 도구 설명 개체와 정수 속성을 추가, 당신은 showCheckBoxToolTip를 구현해야() 메소드를 호출합니다. 이 메소드는 이벤트 콜백 메소드를 ShowToolTip() 메소드와 결합한다는 점을 제외하고 Fermin의 대답과 매우 유사합니다. 또한 메서드 매개 변수 중 하나는 MouseEventArgs입니다. 이는 MouseMove 속성에 MouseEventHandler가 필요하므로 MouseEventArgs를 제공하기 때문입니다.

private void showCheckBoxToolTip(object sender, MouseEventArgs e) 
{ 
    if (toolTipIndex != this.checkedListBox.IndexFromPoint(e.Location)) 
    { 
     toolTipIndex = checkedListBox.IndexFromPoint(checkedListBox.PointToClient(MousePosition)); 
     if (toolTipIndex > -1) 
     { 
      toolTip1.SetToolTip(checkedListBox, checkedListBox.Items[toolTipIndex].ToString()); 
     } 
    } 
} 
0
항목의 당신의 체크 박스 목록에서 많은 ListItems를 통해

실행하고 항목 '제목'속성으로 적절한 텍스트를 설정하고,이 호버에 표시됩니다 ... 노트의

foreach (ListItem item in checkBoxList.Items) 
       { 
        //Find your item here...maybe a switch statement or 
        //a bunch of if()'s 
        if(item.Value.ToString() == "item 1") 
        { 
         item.Attributes["title"] = "This tooltip will display when I hover over item 1 now, thats it!!!"; 
        } 
        if(item.Value.ToString() == "item 2") 
        { 
         item.Attributes["title"] = "This tooltip will display when I hover over item 2 now, thats it!!!"; 
        } 
       }