suicombobox.pas
来自「新颖按钮控件」· PAS 代码 · 共 230 行
PAS
230 行
////////////////////////////////////////////////////////////////////////////////
//
//
// FileName : SUIComboBox.pas
// Creator : Shen Min
// Date : 2002-09-29
// Comment :
//
// Copyright (c) 2002-2003 Sunisoft
// http://www.sunisoft.com
// Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////
unit SUIComboBox;
interface
uses SysUtils, Classes, Controls, StdCtrls, Graphics, Messages, Forms, Windows,
SUIThemes;
type
TsuiComboBox = class(TCustomComboBox)
private
m_BorderColor : TColor;
m_ButtonColor : TColor;
m_ArrowColor : TColor;
m_UIStyle : TsuiUIStyle;
procedure SetBorderColor(const Value: TColor);
procedure WMPAINT(var Msg : TMessage); message WM_PAINT;
procedure WMEARSEBKGND(var Msg : TMessage); message WM_ERASEBKGND;
procedure DrawButton();
procedure DrawArrow(const ACanvas : TCanvas;X, Y : Integer);
procedure SetArrowColor(const Value: TColor);
procedure SetButtonColor(const Value: TColor);
procedure SetUIStyle(const Value: TsuiUIStyle);
protected
procedure SetEnabled(Value: Boolean); override;
public
constructor Create(AOwner : TComponent); override;
published
property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
property BorderColor : TColor read m_BorderColor write SetBorderColor;
property ArrowColor : TColor read m_ArrowColor write SetArrowColor;
property ButtonColor : TColor read m_ButtonColor write SetButtonColor;
property Style; {Must be published before Items}
property Anchors;
property BiDiMode;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property Font;
property ImeMode;
property ImeName;
property ItemHeight;
property ItemIndex default -1;
property MaxLength;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnStartDock;
property OnStartDrag;
property Items; { Must be published after OnMeasureItem }
end;
implementation
uses SUIPublic;
{ TsuiComboBox }
constructor TsuiComboBox.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle + [csOpaque];
BorderWidth := 0;
UIStyle := GetSUIFormStyle(TCustomForm(AOwner));
end;
procedure TsuiComboBox.DrawArrow(const ACanvas : TCanvas; X, Y: Integer);
begin
if not Enabled then
begin
ACanvas.Brush.Color := clWhite;
ACanvas.Pen.Color := clWhite;
ACanvas.Polygon([Point(X + 1, Y + 1), Point(X + 7, Y + 1), Point(X + 4, Y + 4)]);
ACanvas.Brush.Color := clGray;
ACanvas.Pen.Color := clGray;
end
else
begin
ACanvas.Brush.Color := m_ArrowColor;
ACanvas.Pen.Color := m_ArrowColor;
end;
ACanvas.Polygon([Point(X, Y), Point(X + 6, Y), Point(X + 3, Y + 3)]);
end;
procedure TsuiComboBox.DrawButton;
var
R : TRect;
X, Y : Integer;
Btn : graphics.TBitmap;
ACanvas : TCanvas;
pcbi : tagCOMBOBOXINFO;
begin
pcbi.cbSize := SizeOf(pcbi);
GetComboBoxInfo(Handle, pcbi);
R := pcbi.rcButton;
ACanvas := TCanvas.Create();
ACanvas.Handle := GetDC(Handle);
if m_UIStyle = MacOS then
begin
Btn := graphics.TBitmap.Create();
Btn.LoadFromResourceName(hInstance, 'MACOS_COMBOBOX_BUTTON');
//ACanvas.Draw(R.Left, R.Top, Btn);
ACanvas.StretchDraw(R, Btn);
Btn.Free();
end
else
begin
ACanvas.Brush.Color := m_ButtonColor;
ACanvas.FillRect(R);
end;
X := (R.Right - R.Left) div 2 + R.Left - 4;
Y := (R.Bottom - R.Top) div 2;
DrawArrow(ACanvas, X, Y);
ReleaseDC(Handle, ACanvas.Handle);
ACanvas.Free();
end;
procedure TsuiComboBox.SetArrowColor(const Value: TColor);
begin
m_ArrowColor := Value;
Repaint();
end;
procedure TsuiComboBox.SetBorderColor(const Value: TColor);
begin
m_BorderColor := Value;
Repaint();
end;
procedure TsuiComboBox.SetButtonColor(const Value: TColor);
begin
m_ButtonColor := Value;
Repaint();
end;
procedure TsuiComboBox.SetEnabled(Value: Boolean);
begin
inherited;
Repaint();
end;
procedure TsuiComboBox.SetUIStyle(const Value: TsuiUIStyle);
begin
m_UIStyle := Value;
m_ButtonColor := GetThemeColor(m_UIStyle, SUI_COMBOBOX_BUTTON_COLOR);
m_ArrowColor := GetThemeColor(m_UIStyle, SUI_CONTROL_BORDER_COLOR);
m_BorderColor := GetThemeColor(m_UIStyle, SUI_CONTROL_BORDER_COLOR);
Repaint();
end;
procedure TsuiComboBox.WMEARSEBKGND(var Msg: TMessage);
begin
inherited;
DrawControlBorder(self, m_BorderColor, Color);
end;
procedure TsuiComboBox.WMPAINT(var Msg: TMessage);
begin
inherited;
DrawButton();
DrawControlBorder(self, m_BorderColor, Color);
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?