AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

ComboBox Hint onItem?

Ein Thema von kagi3624 · begonnen am 20. Dez 2021 · letzter Beitrag vom 24. Dez 2021
 
BerndS

Registriert seit: 8. Mär 2006
Ort: Jüterbog
492 Beiträge
 
Delphi 12 Athens
 
#9

AW: ComboBox Hint onItem?

  Alt 22. Dez 2021, 09:11
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:
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
Besser wäre natürlich eine neue abzuleiten und in Delphi zu registrieren.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:27 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