OnShowHint ListBox



  • Hallo,

    seit 10 Jahren entwickle ich an meiner Software und auf einmal geht die OnShowHint Funktion nicht mehr, um den Inhalt einer ListBox als ToolTip anzeigen zu lassen. Entnommen hab ich sie von BytesAndMore.de

    In einer anderen Form des Projektes kann ich es problemlos einbauen. Im Hauptprogramm jedoch wird sie nicht mehr angesprochen. Gibt es irgendwo irgendwelche globalen Einstellungen, die ich versehentlich verändert habe ?

    C++ Builder 2009. Für nen Tip wäre ich sehr dankbar !

    Application->OnShowHint=DoShowHintLB;
    
    void __fastcall TfrmMain::DoShowHintLB(System::String &HintStr,
      bool &CanShow, THintInfo &HintInfo)
    {
      // Falls Hint zu einer ListBox angzeigt werden soll:
      if(HintInfo.HintControl->ClassNameIs("TListBox"))
      {
    	 // Zeiger casten:
    	 TListBox* pListBox = static_cast<TListBox *>(HintInfo.HintControl);
    	 // ListBox-Index des Eintrags unter dem Mouse-Cursor ermitteln:
    	 int ilIndex = pListBox->ItemAtPos(HintInfo.CursorPos, true);
    
    	 // Falls die Eintragsbreite grösser, als die ListBox-ClientBreite:
    	 //if(ilIndex >= 0 && pListBox->Canvas->
    		//TextWidth(pListBox->Items->Strings[ilIndex]) >
    		//  pListBox->ClientRect.Right-pListBox->ClientRect.Left)
    	 //{
    		if (ilIndex >= 0)
    		{
    		CanShow = true;
    
    		// Hint-Position, Farbe, Text etc. anpassen:
    		HintInfo.HintPos.x = 0;
    		HintInfo.HintPos.y = pListBox->ItemHeight*(ilIndex-pListBox->TopIndex);
    		HintInfo.HintPos = pListBox->ClientToScreen(HintInfo.HintPos);
    		HintInfo.HintColor = clWhite;
    		HintInfo.ReshowTimeout = 200;
    		HintInfo.HintStr = pListBox->Items->Strings[ilIndex];
    		}
    	 //}
    	 // Falls schon komplett sichtbar, Hint nicht anzeigen:
    	 //else CanShow = false;
      }
    }
    


  • Sorry für vlt harschen Worte, aber:

    Du entwickelst also seit 10 Jahren an deiner Software. Und hast du in der Zeit auch schon mal den Debugger kennengelernt und benutzt?
    Prüfe im Debugger doch erstmal, ob die Methode aus der Hautpform überhaupt aufgerufen wird.



  • Hallo,

    25 Jahre, aber 10 Jahre an diesem System - kaum zu glauben, aber ja.
    Zitat "Im Hauptprogramm jedoch wird sie nicht mehr angesprochen."

    Ich hab es jetzt anders gelöst:

    static int OldIndex = -1;
    	int Index = lstAuswahl->ItemAtPos(Point(X, Y), true);
    	if((Index > -1) && (Index != OldIndex))
    	{
    		lstAuswahl->Hint = Separator(lstAuswahl->Items->Strings[Index], "|", 2, false);
    		Application->ActivateHint(Mouse->CursorPos);
    	}
    	else
    	{
    	 lstAuswahl->Hint ="";
    	}
    	OldIndex = Index;
    


  • Super, das du das Problem gelöst hast. 👍 👍

    Sagt du uns auch, wo genau du deine Problemlösung eingebaut hast? 😉
    Edit: So wie es aussieht, wohl im MouseMove Event der Listbox. 😃



  • Sorry - hast recht, im MouseMove der Listbox 😉


Anmelden zum Antworten