![]() |
Delphi-Version: 6
ComboBox Hint onItem?
Hallo, ich möchte gerne ein Hint bei jedem Item der Combobox (csDropDownList) anzeigen lassen.
So wie ich es verstanden habe, soll es recht kompliziert sein und ich habe kein Beispielcode gefunden bis auf die Anleitung ![]() Danke! |
AW: ComboBox Hint onItem?
.. möchtest Du den Hint sehen, wenn die Liste aufgeklappt ist und ein Iten ge-high-lighted wird-
oder wenn ein Item ausgewählt wurde und die Liste ist wieder zugeklappt? Für das letztere (wie schon imSO Artikelt erwähnt)
Delphi-Quellcode:
Hier wird der HintText anhand des Indexes des ausgewählten Items gesetzt.
procedure TForm1.ComboBox1Select(Sender: TObject);
begin case (sender as TComboBox).ItemIndex of 0: (sender as TComboBox).Hint := 'null'; 1: (sender as TComboBox).Hint := 'eins'; 2: (sender as TComboBox).Hint := 'zwei'; 3: (sender as TComboBox).Hint := 'drei'; 4: (sender as TComboBox).Hint := 'vier'; end; end; Grüße Klaus |
AW: ComboBox Hint onItem?
Ja eigentlich das schwierige: Beim Aufklappen der ComboBox mit der Maus über die Items gehen (also nicht auswählen).
|
AW: ComboBox Hint onItem?
|
AW: ComboBox Hint onItem?
Und wenn du ans MouseMove über dem DropDown ran kommst, dann kannst den Hint auch selber anzeigen.
|
AW: ComboBox Hint onItem?
Zitat:
|
AW: ComboBox Hint onItem?
Liste der Anhänge anzeigen (Anzahl: 1)
Hmm..
Mit den Beispielen aus meinem vorherigen Link + Google, ein Beispiel! |
AW: ComboBox Hint onItem?
@Holger, vielen Dank!
Code:
war das Problem, ich dachte man macht es mit ShowHint
FHintWnd.ActivateHint(Rect(pt.X+10,pt.Y,pt.X+100,pt.Y+20),tmpHint);
:wall: |
AW: ComboBox Hint onItem?
Basierend auf dem Beispiel von Holger könnte man auch die Komponente erweitern.
Delphi-Quellcode:
unit Unit1;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TComboBox = class(Vcl.StdCtrls.TComboBox) private FcbHintIndex: Integer; FHintWindow: THintWindow; protected procedure Change; override; procedure DropDown; override; procedure CloseUp; override; procedure InitiateAction; override; end; TForm1 = class(TForm) cb: TComboBox; procedure cbChange(Sender: TObject); procedure FormCreate(Sender: TObject); private protected public end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.cbChange(Sender: TObject); var P: TPoint; begin case (Sender as TComboBox).ItemIndex of 0: (Sender as TComboBox).Hint := 'null'; 1: (Sender as TComboBox).Hint := 'eins'; 2: (Sender as TComboBox).Hint := 'zwei'; 3: (Sender as TComboBox).Hint := 'drei'; 4: (Sender as TComboBox).Hint := 'vier'; end; end; procedure TForm1.FormCreate(Sender: TObject); var I: Integer; begin for I := 0 to 4 do cb.Items.Add(I.ToString); end; { TComboBox } procedure TComboBox.Change; var P: TPoint; begin inherited; if (Hint <> '') and DroppedDown and GetCursorPos(P) then FHintWindow.ActivateHint(Rect(P.X + 10, P.Y + 20, P.X + 100, P.Y + 40), Hint); end; procedure TComboBox.CloseUp; begin inherited; FHintWindow.Hide; ControlStyle := ControlStyle - [csActionClient]; end; procedure TComboBox.DropDown; begin inherited; if not Assigned(FHintWindow) then FHintWindow := THintWindow.Create(Self); FcbHintIndex := -1; ControlStyle := ControlStyle + [csActionClient]; end; procedure TComboBox.InitiateAction; var Idx: Integer; begin inherited; Idx := ItemIndex; if Idx <> FcbHintIndex then begin FcbHintIndex := ItemIndex; Change; end; end; end.
Code:
Besser wäre natürlich eine neue abzuleiten und in Delphi zu registrieren.
object Form1: TForm1
Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 220 ClientWidth = 471 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -12 Font.Name = 'Segoe UI' Font.Style = [] ShowHint = True OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 15 object cb: TComboBox Left = 32 Top = 24 Width = 145 Height = 23 Style = csDropDownList ParentShowHint = False ShowHint = True TabOrder = 0 OnChange = cbChange end end |
AW: ComboBox Hint onItem?
Hallo, kann man bei dem THintWindow irgendwie eine Verzögerung bevor der Hint angezeigt wird realisieren? Ein einfaches sleep ganz am Anfang der OnIdle Funktion tut es zwar gut, aber nur solange ich nur diese combobox habe und die Funktion bei anderen Fenstern nicht durchgelaufen wird.
|
AW: ComboBox Hint onItem?
Gibt's die bei Delphi 6 schon?
Delphi-Quellcode:
Delphi 7 hat's jedenfalls.
Application.HintPause := 250;
Application.HintHidePause := 10000; Application.HintShortPause := 250; Application.HintShortCuts := True; Werte nach Deinen Vorstellungen anpassen. |
AW: ComboBox Hint onItem?
Ein Timer mit der gewünschten Verzögerung und im OnTimer dann FHintWindow.ActivateHint usw.
|
AW: ComboBox Hint onItem?
Ich weiß zwar nicht was ich tue aber irgendwie scheint es so zu funktionieren
Code:
Die eine Punktkoordinate schreibe ich irgendwohin, damit es noch einmal updateted wird und lösche die dann später mit CloseUp.
procedure TForm1.ApplicationIdle(sender: TObject; var Done: boolean);
var pt, pt2 : TPoint; wnd: HWND; buf: array[0..128] of Char; i : Integer; begin GetCursorPos(pt); wnd := WindowFromPoint(pt); if wnd <> 0 then begin buf[0] := #0; GetClassName(wnd, buf, SizeOf(buf)); if (StrIComp(buf, 'ComboLBox') = 0) then begin Windows.ScreenToClient(wnd, pt); i := SendMessage(wnd, LB_ITEMFROMPOINT, 0, lparam(PointToSmallpoint(pt))); if (i >= 0) and (i < 65536) then begin if (FHintIndex <> i) then begin SendMessage(wnd, LB_GETTEXT, i, integer(@buf)); Sleep(500); GetCursorPos(pt2); Windows.ScreenToClient(wnd, pt2); StatusBar1.Panels[1].Text := inttostr(pt2.y); if (comboBox1.DroppedDown = true) and PointsEqual(pt,pt2) then begin GetCursorPos(pt); FHintWnd.ActivateHint(Rect(pt.X+10,pt.Y,pt.X+410,pt.Y+180), StandardHint[i]); FHintIndex := i; end; end; end; end; end; end; |
AW: ComboBox Hint onItem?
Hmm..
Euch ist schon bewusst, dass das hier verwendete FHintWnd NICHT das gleiche ist welches intern bei Application verwendet wird? Sleep ist auch eine ungünstige Idee.. Denn hier wird die Applikation für die Zeit angehalten, somit komplett verzögert.. Ich hatte schon FHintIndex eingesetzt damit nicht beim gleichen Intex der Hint wieder neu gezeichnet wird und somit flackert. Wenn Ihr Pausen und automatisches Schließen, sprich die Funktion von Application haben wollt, dann müsst Ihr das ganze Hint-System mit Timer und Co. nachbauen oder dort extrahieren. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:23 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz