捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  沪ICP备05001939号 DELPHI盒子 | 盒子论坛 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 论坛检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
盒子资源分类
全部展开 - 全部合拢
自己写的颜色下拉列表控件
关键字:自己写的ComBox颜色下拉列表控件
来 自:原创
平 台:Win2K/2003/NT/XP 下载所需:0 火柴
深浅度:中级 完成时间:2013/8/5
发布者:abcjingtong (奖励50火柴) 发布时间:2013/8/6
编辑器:delphi2010 语  种:简体中文
分 类:列表与选项框 下载浏览:135/7971
加入到我的收藏
下载错误报错
登陆以后才能下载
 用户名:
 密 码:
自动登陆(30天有效)
图片如果打不开,说明流量不够了,请稍候下载……
一个下拉显示颜色的ColorComBox,和系统自带的区别:
1.下拉颜色可以自定义;
2.颜色可配中文标题(见附图)
Google
 
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们
龙脉加密锁 15元起 Grid++Report 报表 申请支付@网
 相关文章
没有相关文章
相关评论
共有评论2条 当前显示最后2条评论
ozhy1 2013/8/7 9:38:36
TColorComboBox 提示已经存在 我修改了下
保存为 ColorComboBoxzhy.pas

----------
unit ColorComboBoxzhy;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, Graphics, Types;

type
  TColorComboBoxzhy = class(TCustomComboBox)
  private
    { Private declarations }
    FSelected: TColor;
    procedure SetSelected(Value: TColor);
    function GetSelected: TColor;
  protected
    { Protected declarations }
    function GetColor(AIndex: Integer): TColor;
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
    procedure CreateWnd; override;
    procedure Change; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Selected: TColor read GetSelected write SetSelected;
    property Items;
    property ItemIndex default 0;
    property OnChange;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('zhy', [TColorComboBoxzhy]);
end;

{ TColorComboBox }

procedure TColorComboBoxzhy.Change;
begin
  inherited;
  FSelected := GetColor(ItemIndex);
end;

constructor TColorComboBoxzhy.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Style := csOwnerDrawFixed;
end;

procedure TColorComboBoxzhy.CreateWnd;
begin
  inherited CreateWnd;
  //Items.Clear;
  if Items.Count = 0 then
  begin
    Items.Add('无');      //clNone
    Items.Add('黑');      //clBlack
    Items.Add('白');      //clWhite
    Items.Add('绿');      //clGreen
    Items.Add('橄榄');    //clOlive
    Items.Add('海蓝');    //clNavy
    Items.Add('紫');      //clPurple
    Items.Add('青');      //clTeal
    Items.Add('灰');      //clGray
    Items.Add('银');      //clSilver
    Items.Add('红');      //clRed
    Items.Add('黄绿');    //clLime
    Items.Add('黄');      //clYellow
    Items.Add('蓝');      //clBlue
    Items.Add('紫红');    //clFuchsia
    Items.Add('浅绿');    //clAqua
    Items.Add('浅灰');    //clLtGray
    Items.Add('深灰');    //clDkGray
    Items.Add('红褐');    //clMaroon
  end;
end;

destructor TColorComboBoxzhy.Destroy;
begin

  inherited Destroy;
end;

procedure TColorComboBoxzhy.DrawItem(Index: Integer; Rect: TRect;
  State: TOwnerDrawState);
var
  viTextW: Integer;
begin
  inherited;
  Canvas.Brush.Color := GetColor(Index);
  viTextW := Canvas.TextWidth('金金'); //Items[Index]
  Canvas.Rectangle(Rect.Left + 1, Rect.Top + 1, Rect.Right - viTextW - 5,
    Rect.Bottom - 1);
  Canvas.Brush.Style := bsClear;
  Canvas.TextOut(Rect.Right - viTextW - 2, Rect.Top + 1, Items[Index]);
end;

function TColorComboBoxzhy.GetColor(AIndex: Integer): TColor;
begin
  Result := clNone;
  case AIndex of
    //0: Result := clNone;
    1: Result := clBlack;
    2: Result := clWhite;
    3: Result := clGreen;
    4: Result := clOlive;
    5: Result := clNavy;
    6: Result := clPurple;
    7: Result := clTeal;
    8: Result := clGray;
    9: Result := clSilver;
    10: Result := clRed;
    11: Result := clLime;
    12: Result := clYellow;
    13: Result := clBlue;
    14: Result := clFuchsia;
    15: Result := clAqua;
    16: Result := clLtGray;
    17: Result := clDkGray;
    18: Result := clMaroon;
  end;
end;

function TColorComboBoxzhy.GetSelected: TColor;
begin
  FSelected := GetColor(ItemIndex);
  Result := FSelected;
end;

procedure TColorComboBoxzhy.SetSelected(Value: TColor);
var
  I: Integer;
begin
  for I := 0 to Items.Count - 1 do
  begin
    if GetColor(i) = Value then
    begin
      ItemIndex := i;
      Break;
    end;
  end;
end;

end.
abcjingtong 2013/8/7 10:13:56
多谢站长
我要发表评论 查看全部评论
 
  DELPHI盒子版权所有 1999-2023 V4.01 粤ICP备10103342号-1 更新RSS列表