उपयोगकर्ता अनुभव टिप्पणियों को छोड़कर, जिस पर मैं सहमत हूं, प्रश्न का समाधान वास्तव में कठिन नहीं है।
आप इस प्रकार,, csOwnerDrawFixed
करने के लिए Style
संपत्ति की स्थापना OnDrawItem
स्थिति में अपने आप को आइटम ड्राइंग, और उदाहरण के लिए OnSelect
घटना में चयनित आइटम को हटा कर ऐसा कर सकते हैं:
unit Unit1;
interface
uses
Winapi.Windows, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls,
Vcl.Imaging.PNGIMage;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ComboBox1Select(Sender: TObject);
private
FDeleteGraphic: TPNGImage;
FDeleteRect: TRect;
end;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
ComboBox1.Canvas.FillRect(Rect);
if Index >= 0 then
ComboBox1.Canvas.TextOut(Rect.Left + 2, Rect.Top, ComboBox1.Items[Index]);
if (odSelected in State) and not (odComboBoxEdit in State) then
begin
FDeleteRect := Rect;
FDeleteRect.Left := FDeleteRect.Right - FDeleteGraphic.Width;
ComboBox1.Canvas.Draw(FDeleteRect.Left, FDeleteRect.Top, FDeleteGraphic);
end;
end;
procedure TForm1.ComboBox1Select(Sender: TObject);
var
MousePos: TPoint;
begin
MousePos := ComboBox1.ScreenToClient(Mouse.CursorPos);
MousePos.Offset(0, -ComboBox1.Height);
if PtInRect(FDeleteRect, MousePos) then
begin
ComboBox1.Items.Delete(ComboBox1.ItemIndex);
ComboBox1.Invalidate;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDeleteGraphic := TPNGImage.Create;
FDeleteGraphic.LoadFromFile('H:\Icons\FamFam Common\Delete.png');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FDeleteGraphic.Free;
end;
end.
इस परिणाम के साथ :
आप (फिर) की दुकान पिछले ItemIndex
सेटिंग कर सकते हैं। अपनी इच्छाओं को अनुकूलित करें।
बिल्कुल TSpeedButton होने के लिए आवश्यक नहीं है, लेकिन एक बटन जिसमें ऑनक्लिक हैंडलर है। कोई सुझाव? – Alex
मैंने सवाल संपादित किया .. चित्रण करने के लिए एक छवि है, लेकिन प्रतिनिधि बहुत कम है। – Alex
वैसे भी, मुझे लगता है कि आप एक डिलीट बटन सहित कॉम्बो आइटम को कस्टम आकर्षित करने की तलाश करेंगे, और फिर क्लिक का पता लगाएंगे। व्यक्तिगत रूप से मैं एक अलग यूआई खोजने की कोशिश कर रहा था। –