Показать сообщение отдельно
  #2  
Старый 02.06.2010, 13:27
Аватар для dr. F.I.N.
dr. F.I.N. dr. F.I.N. вне форума
I Like it!
 
Регистрация: 12.12.2009
Адрес: Россия, г. Новосибирск
Сообщения: 663
Версия Delphi: D6/D7
Репутация: 26643
По умолчанию

Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  i, x: Integer;
  s, s1: String;
begin
  with TCombobox(Control).Canvas do
  begin
    fillrect(rect);
    s := TCombobox(Control).items[index];
    i := Pos('^', s);
    s1 := Copy(s, 1, i - 1);
    textout(rect.left+2,rect.top + 4, s1);
    x := TextWidth(s1);
    Font.Size := Font.Size - 2;
    textout(rect.left+2+x,rect.top + 2, Copy(s, i + 1, Length(s) - Length(s1) - 1));
    Font.Size := Font.Size + 2;
  end;
end;

end.
Код:
object Form1: TForm1
  Left = 192
  Top = 124
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 224
    Top = 152
    Width = 145
    Height = 26
    Style = csOwnerDrawFixed
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ItemHeight = 20
    ParentFont = False
    TabOrder = 0
    OnDrawItem = ComboBox1DrawItem
    Items.Strings = (
      '10^2'
      '10^3'
      '545^-123')
  end
end
Ответить с цитированием