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

•  DeLiKaTeS Tetris (Тетрис)  151

•  TDictionary Custom Sort  3 332

•  Fast Watermark Sources  3 083

•  3D Designer  4 841

•  Sik Screen Capture  3 334

•  Patch Maker  3 548

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

•  ListBox Drag & Drop  3 011

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

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

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

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

•  Canvas Drawing  2 747

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

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

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

•  Paint on Shape  1 568

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

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

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

•  Пазл Numbrix  1 685

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

•  Игра HIP  1 282

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

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

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

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

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

•  HEX View  1 497

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

 
скрыть


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

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



Delphi Sources

Вывод строковой информации



Автор: Xavier Pacheco

{
Copyright © 1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}

unit MainFrm;

interface

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

const
  DString = 'Delphi 5 YES!';
  DString2 = 'Delphi 5 Rocks!';

type

  TMainForm = class(TForm)
    mmMain: TMainMenu;
    mmiText: TMenuItem;
    mmiTextRect: TMenuItem;
    mmiTextSize: TMenuItem;
    mmiDrawTextCenter: TMenuItem;
    mmiDrawTextRight: TMenuItem;
    mmiDrawTextLeft: TMenuItem;
    procedure mmiTextRectClick(Sender: TObject);
    procedure mmiTextSizeClick(Sender: TObject);
    procedure mmiDrawTextCenterClick(Sender: TObject);
    procedure mmiDrawTextRightClick(Sender: TObject);
    procedure mmiDrawTextLeftClick(Sender: TObject);
  public
    procedure ClearCanvas;
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.ClearCanvas;
begin
  with Canvas do
  begin
    Brush.Style := bsSolid;
    Brush.Color := clWhite;
    FillRect(ClipRect);
  end;
end;

procedure TMainForm.mmiTextRectClick(Sender: TObject);
var
  R: TRect;
  TWidth, THeight: integer;
begin
  ClearCanvas;
  Canvas.Font.Size := 18;
  // Calculate the width/height of the text string
  TWidth := Canvas.TextWidth(DString);
  THeight := Canvas.TextHeight(DString);

  { Initialize a TRect structure. The height of this rectangle will
    be 1/2 the height of the text string height. This is to
    illustrate clipping the text by the rectangle drawn }
  R := Rect(1, THeight div 2, TWidth + 1, THeight + (THeight div 2));
  // Draw a rectangle based on the text sizes
  Canvas.Rectangle(R.Left - 1, R.Top - 1, R.Right + 1, R.Bottom + 1);
  // Draw the Text within the rectangle
  Canvas.TextRect(R, 0, 0, DString);
end;

procedure TMainForm.mmiTextSizeClick(Sender: TObject);
begin
  ClearCanvas;
  with Canvas do
  begin
    Font.Size := 18;
    TextOut(10, 10, DString);
    TextOut(50, 50, 'TextWidth = ' + IntToStr(TextWidth(DString)));
    TextOut(100, 100, 'TextHeight = ' + IntToStr(TextHeight(DString)));
  end;
end;

procedure TMainForm.mmiDrawTextCenterClick(Sender: TObject);
var
  R: TRect;
begin
  ClearCanvas;
  Canvas.Font.Size := 10;
  R := Rect(10, 10, 80, 100);
  // Draw a rectangle to surround the TRect boundaries by 2 pixels }
  Canvas.Rectangle(R.Left - 2, R.Top - 2, R.Right + 2, R.Bottom + 2);
  // Draw text centered by specifying the dt_Center option
  DrawText(Canvas.Handle, PChar(DString2), -1, R, dt_WordBreak or dt_Center);
end;

procedure TMainForm.mmiDrawTextRightClick(Sender: TObject);
var
  R: TRect;
begin
  ClearCanvas;
  Canvas.Font.Size := 10;
  R := Rect(10, 10, 80, 100);
  // Draw a rectangle to surround the TRect boundaries by 2 pixels
  Canvas.Rectangle(R.Left - 2, R.Top - 2, R.Right + 2, R.Bottom + 2);
  // Draw text right-aligned by specifying the dt_Right option
  DrawText(Canvas.Handle, PChar(DString2), -1, R, dt_WordBreak or dt_Right);
end;

procedure TMainForm.mmiDrawTextLeftClick(Sender: TObject);
var
  R: TRect;
begin
  ClearCanvas;
  Canvas.Font.Size := 10;
  R := Rect(10, 10, 80, 100);
  // Draw a rectangle to surround the TRect boudries by 2 pixels
  Canvas.Rectangle(R.Left - 2, R.Top - 2, R.Right + 2, R.Bottom + 2);
  // Draw text left-aligned by specifying the dt_Left option
  DrawText(Canvas.Handle, PChar(DString2), -1, R, dt_WordBreak or dt_Left);
end;

end.




Похожие по теме исходники

Оптимальное кодирование информации




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

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