Недавно добавленные исходники

•  TDictionary Custom Sort  3 227

•  Fast Watermark Sources  2 992

•  3D Designer  4 751

•  Sik Screen Capture  3 259

•  Patch Maker  3 467

•  Айболит (remote control)  3 528

•  ListBox Drag & Drop  2 904

•  Доска для игры Реверси  80 793

•  Графические эффекты  3 843

•  Рисование по маске  3 172

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 674

•  Рисование Луны  2 501

•  Поворот изображения  2 094

•  Рисование стержней  2 121

•  Paint on Shape  1 525

•  Генератор кроссвордов  2 183

•  Головоломка Paletto  1 731

•  Теорема Монжа об окружностях  2 158

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 017

•  Игра HIP  1 262

•  Игра Go (Го)  1 201

•  Симулятор лифта  1 425

•  Программа укладки плитки  1 178

•  Генератор лабиринта  1 512

•  Проверка числового ввода  1 297

•  HEX View  1 466

•  Физический маятник  1 322

•  Задача коммивояжера  1 357

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Многостроковый TComboBox




unit Unit1; 

interface 

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

type 
  TForm1 = class(TForm) 
    ComboBox1: TComboBox; 
    procedure FormCreate(Sender: TObject); 
    procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer; 
      var Height: Integer); 
    procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer; 
      Rect: TRect; State: TOwnerDrawState); 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.DFM} 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
  Combobox1.Style := csOwnerDrawVariable; 
  // die Combobox mit einigen Beispielen fullen 
  // fill the combobox with some examples 
  with Combobox1.Items do 
  begin 
    Add('Short, kurzer String'); 
    Add('A long String. / Ein langer String.....'); 
    Add('Another String'); 
    Add('abcd defg hijk lmno'); 
    Add('..-.-.-.-.-.-.-.-.-'); 
  end; 
end; 

procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer; 
  var Height: Integer); 
  // Berechnet die notwendige Hohe fur einen mehrzeiligen Text 
  // Calculates the required height for a multiline text 
var  
  i, PosSp: Integer; 
  strVal: string; 
  strTmp: string; 
begin 
  if Index >= 0 then 
  begin 
    strVal := Combobox1.Items[Index]; 
    // String auf mehrere Zeilen aufteilen, Zeilen sind mit #$D#$A getrennt 
    // wrap string to multiple lines, each line separated by #$D#$A 
    strTmp := WrapText(strVal, 20); 
    // Anzahl der Zeilentrennungen plus eins = Anzahl Zeilen 
    // Number of line separators + 1 = number of lines 
    i := 1; 
    while Pos(#$D#$A, strTmp) > 0 do 
    begin 
      i      := i + 1; 
      strTmp := Copy(strTmp, Pos(#13#10, strTmp) + 2, Length(strTmp)); 
    end; 
    // Hohe fur den Text berechnen 
    // calcualte the height for the text 
    Height := i * Combobox1.ItemHeight; 
  end; 
end; 

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; 
  Rect: TRect; State: TOwnerDrawState); 
  // Schreibt einen Text auf die Combobox. Wenn der Text zu lange ist, wird er 
  // auf mehrere Zeilen aufgeteilt 
  // Writes a text to the combobox. If the text is too long, then it will be 
  // wrapped 
var 
  strVal: string; 
  strTmp: string; 
  intPos: Integer; 
  i: Integer; 
  rc: TRect; 
begin 
  // Text auf mehrere Zeilen aufteilen 
  // wrap the text 
  strVal := WrapText(Combobox1.Items[Index], 20); 
  i      := 0; 
  Combobox1.Canvas.FillRect(Rect); 
  // jede Textzeile einzeln ausgeben 
  // output each single line 
  while Pos(#$D#$A, strVal) > 0 do 
  begin 
    intPos := Pos(#$D#$A, strVal); 
    // Aktuelle Zeile aus dem String kopieren 
    // copy current line from string 
    if intPos > 0 then 
      strTmp := Copy(strVal, 1, intPos - 1)  
    else 
      strTmp := strVal; 
    rc     := Rect; 
    rc.Top := Rect.Top + i * Combobox1.ItemHeight; 
    ComboBox1.Canvas.TextRect(rc, Rect.Left, Rect.Top + i * Combobox1.ItemHeight, 
      strTmp); 
    // die ausgegebene Zeile aus dem String loschen 
    // delete the written line from the string 
    strVal := Copy(strVal, intPos + 2, Length(strVal)); 
    Inc(i); 
  end; 
  rc     := Rect; 
  rc.Top := Rect.Top + i * Combobox1.ItemHeight; 
  // Letzte Zeile schreiben 
  // write the last line 
  ComboBox1.Canvas.TextRect(rc, Rect.Left, Rect.Top + i * Combobox1.ItemHeight, strVal); 
  Combobox1.Canvas.Brush.Style := bsClear; 
  // den Text mit einem Rechteck umrunden 
  // surround the text with a rectangle 
  Combobox1.Canvas.Rectangle(Rect); 
end; 

end.








Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте