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

•  DeLiKaTeS Tetris (Тетрис)  4 298

•  TDictionary Custom Sort  6 345

•  Fast Watermark Sources  6 135

•  3D Designer  9 068

•  Sik Screen Capture  6 456

•  Patch Maker  6 869

•  Айболит (remote control)  6 856

•  ListBox Drag & Drop  5 732

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

•  Графические эффекты  7 075

•  Рисование по маске  6 376

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

•  Canvas Drawing  5 620

•  Рисование Луны  5 319

•  Поворот изображения  4 868

•  Рисование стержней  3 453

•  Paint on Shape  2 713

•  Генератор кроссвордов  3 589

•  Головоломка Paletto  2 883

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

•  Пазл Numbrix  2 422

•  Заборы и коммивояжеры  3 105

•  Игра HIP  2 062

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

•  Симулятор лифта  2 350

•  Программа укладки плитки  2 050

•  Генератор лабиринта  2 510

•  Проверка числового ввода  2 195

•  HEX View  2 521

•  Физический маятник  2 137

 
скрыть

  Форум  

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-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

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