zoukankan      html  css  js  c++  java
  • 再学 GDI+[35]: TGPPen 虚线画笔位移 SetDashOffset

    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure FormPaint(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses GDIPOBJ, GDIPAPI;
    
    var
      n: Integer;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Interval := 100;
    end;
    
    procedure TForm1.FormPaint(Sender: TObject);
    var
      g: TGPGraphics;
      p: TGPPen;
    begin
      g := TGPGraphics.Create(Canvas.Handle);
      p := TGPPen.Create(aclChocolate, 8);
      p.SetDashStyle(DashStyleDashDotDot);
    
      p.SetDashOffset(n);
    
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, 0, 0);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, ClientWidth div 2, 0);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, ClientWidth, 0);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, ClientWidth, ClientHeight div 2);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, ClientWidth, ClientHeight);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, ClientWidth div 2, ClientHeight);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, 0, ClientHeight);
      g.DrawLine(p, ClientWidth div 2, ClientHeight div 2, 0, ClientHeight div 2);
    
      Dec(n);
      if n > Sqrt(Sqr(ClientWidth) + Sqr(ClientWidth)) then n := 0;
    
      p.Free;
      g.Free;
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Repaint;
    end;
    
    end.
    
    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 167
      ClientWidth = 242
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      Position = poDesktopCenter
      OnCreate = FormCreate
      OnPaint = FormPaint
      PixelsPerInch = 96
      TextHeight = 13
      object Timer1: TTimer
        OnTimer = Timer1Timer
        Left = 112
        Top = 88
      end
    end
    
  • 相关阅读:
    Xcode 10 storyBoard中控件区域位置修改
    使用WeexSDK,网络请求信任证书的问题
    真机调试包,解决xcode跑不了高版本iOS系统问题,及Deployment Target不显示高版本系统的问题
    vim进阶学习
    Linux中的inode(转载)
    Linux的文件权限
    远程连接Linux服务器
    WinSDK绘制文本
    (转载)Win32 SDK编程系列文章——菜单(快捷菜单)——动态加载
    (转载)Windows Socket五种I/O模型——代码全攻略
  • 原文地址:https://www.cnblogs.com/del/p/1221078.html
Copyright © 2011-2022 走看看