博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
delphi Tab Item Badge Value 消息数标记
阅读量:6207 次
发布时间:2019-06-21

本文共 3188 字,大约阅读时间需要 10 分钟。

https://community.embarcadero.com/blogs?view=entry&id=9074

 

unit TabBadgeFrm; interface uses  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl, FMX.Controls.Presentation, FMX.Edit,  FMX.EditBox, FMX.SpinBox, FMX.StdCtrls, FMX.Layouts, FMX.ListBox,  FMX.NumberBox; type  TForm16 = class(TForm)    TabItem1: TTabItem;    TabItem2: TTabItem;    BadgeItem: TTabItem;    SpinBox1: TSpinBox;    ToolBar1: TToolBar;    Switch1: TSwitch;    ListBox1: TListBox;    ListBoxItem1: TListBoxItem;    ToolLabel: TLabel;    TabControl1: TTabControl;    procedure BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);    procedure SpinBox1Change(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure Switch1Switch(Sender: TObject);    procedure StepperUpClick(Sender: TObject);  private    FBadge: Integer;    FShowBadge: Boolean;    procedure SetBadge(const Value: Integer);    procedure SetShowBadge(const Value: Boolean);    {
Private declarations } public {
Public declarations } property Badge: Integer read FBadge write SetBadge; property ShowBadge: Boolean read FShowBadge write SetShowBadge; end; var Form16: TForm16; implementation {
$R *.fmx}{
$R *.iPhone55in.fmx IOS} procedure DrawBadge(Canvas: TCanvas; const ARect: TRectF; const Text: string; const Color: TAlphaColor = TAlphaColorRec.Red);const Padding = 2; HorzTextMargin = 6; VertTextMargin = 4;var R: TRectF; TextSize: TSizeF; Brush: TBrush; BadgeRadius: Single;begin Canvas.Font.Size := 12; // Measure text width TextSize := TSizeF.Create(Canvas.TextWidth(Text), Canvas.TextHeight(Text)); // Calculate badge rect R := TRectF.Create(0, 0, HorzTextMargin * 2 + TextSize.Width, VertTextMargin * 2 + TextSize.Height); if R.Width < R.Height then R.Width := R.Height; // Position rect R := TRectF.Create(ARect.Right - R.Width, ARect.Top, ARect.Right, ARect.Top + R.Height); R.Offset(-Padding, Padding); // Draw badge BadgeRadius := R.Height / 2; Brush := TBrush.Create(TBrushKind.Solid, Color); try Canvas.FillRect(R, BadgeRadius, BadgeRadius, AllCorners, 1, Brush); finally Brush.Free; end; // Draw text Canvas.Fill.Color := TAlphaColorRec.White; Canvas.FillText(R, Text, False, 1, [], TTextAlign.Center, TTextAlign.Center);end; procedure TForm16.BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);begin if ShowBadge then DrawBadge(Canvas, ARect, FBadge.ToString);end; procedure TForm16.FormCreate(Sender: TObject);begin FBadge := 1;end; procedure TForm16.SetBadge(const Value: Integer);begin if FBadge Value then begin FBadge := Value; BadgeItem.Repaint; end;end; procedure TForm16.SetShowBadge(const Value: Boolean);begin if FShowBadge Value then begin FShowBadge := Value; BadgeItem.Repaint; end;end; procedure TForm16.SpinBox1Change(Sender: TObject);begin Badge := Trunc(SpinBox1.Value);end; procedure TForm16.StepperUpClick(Sender: TObject);begin Badge := Trunc(SpinBox1.Value);end; procedure TForm16.Switch1Switch(Sender: TObject);begin ShowBadge := Switch1.IsChecked;end; end.

 

转载地址:http://odzja.baihongyu.com/

你可能感兴趣的文章
Button和ImageButton
查看>>
TCP具体解释(3):重传、流量控制、拥塞控制……
查看>>
Material Design Get Started
查看>>
基于 Red5 的流媒体服务器的搭建和应用
查看>>
基于轻量型Web服务器Raspkate的RESTful API的实现
查看>>
POJ 2406 Power Strings KMP运用题解
查看>>
lintcode:Ugly Number I
查看>>
Java设计模式系列之适配器模式
查看>>
深入理解JavaScript系列(37):设计模式之享元模式
查看>>
使用top命令查看最消耗CPU和最消耗内存的进程
查看>>
如何获取Android系统中申请对象的信息
查看>>
jQuery图片延迟加载
查看>>
indent guides 格式化代码(添加竖线)
查看>>
Nodejs爬虫进阶教程之异步并发控制
查看>>
PHP数字补零的两种方法
查看>>
Windows 7个性化配置,关闭Win7动画效果,设置窗口背景为“ 豆绿色”,移动“我的文档”...
查看>>
ASP.NET MVC Bootstrap极速开发框架
查看>>
HDU 5810 Balls and Boxes 数学
查看>>
EditText监听键盘输入
查看>>
git 服务器搭建,在自己服务器上搭建私有仓库
查看>>