![]() |
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.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:38 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 by Thomas Breitkreuz