学用 TStringGrid [6] - Options
2024-09-29 01:04:41
本例运行效果图:
一般修改 TStringGrid 的 Options 直接在设计时选一下 True 或 False 就行了; 代码中可以像下面操作:
StringGrid1.Options := [goFixedVertLine];
StringGrid1.Options := [goFixedVertLine, goVertLine, goColSizing];
做完这个例子发现不太初级了, 但代码很简单:
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids; type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
GroupBox1: TGroupBox;
procedure FormCreate(Sender: TObject);
procedure GroupBox1Click(Sender: TObject);
end; var
Form1: TForm1; implementation {$R *.dfm} uses
TypInfo; {需要这个单元获取 StringGrid1.Options 选项名称} var
cb: TCheckBox; {准备动态生成 15 个 TCheckBox}
GridOpt: TGridOptions; {StringGrid1.Options 是一个 TGridOptions 类型(集合)}
{同时也应知道: TGridOptions 集合是根据 TGridOption 枚举定义的} {窗体建立时, 干了不少事}
procedure TForm1.FormCreate(Sender: TObject);
var
i,j: Integer;
gb: TGroupBox; {为简化 GroupBox1 名称用}
begin
StringGrid1.RowCount := ; {设 StringGrid1 为 16 行} {给每个单元赋值}
with StringGrid1 do
for i := to ColCount - do
for j := to RowCount - do
Cells[i,j] := Format('%.1x%.1x',[i,j]); {下面只是动态生成 15 个 TCheckBox, 并赋予标题与 OnClick 功能}
gb := Self.GroupBox1; {用 gb 简化 GroupBox1 的称谓}
j := ; {用来记录 TCheckBox 的纵向位置}
for i := to do
begin
if cb<>nil then Inc(j,cb.Height);
cb := TCheckBox.Create(Self);
cb.Parent := gb;
cb.Left := ; cb.Top := j;
cb.Caption := GetEnumName(TypeInfo(TGridOption),i);
cb.OnClick := gb.OnClick; {本来可以没有下面这句, 不然会隐藏部分名称, 可能是中文系统的支持问题}
cb.Width := Canvas.TextWidth(GetEnumName(TypeInfo(TGridOption),))+ ;
end;
end; {这个主要是让 TCheckBox 调用的}
procedure TForm1.GroupBox1Click(Sender: TObject);
var
i: Integer;
begin
GridOpt := [];
for i := to GroupBox1.ControlCount - do
begin
if TCheckBox(GroupBox1.Controls[i]).Checked then
GridOpt := GridOpt + [TGridOption(i)];
end;
StringGrid1.Options := GridOpt;
end; end.
附上窗体设计源码:
object Form1: TForm1
Left =
Top =
Caption = 'Form1'
ClientHeight =
ClientWidth =
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesigned
OnCreate = FormCreate
PixelsPerInch =
TextHeight =
object StringGrid1: TStringGrid
Left =
Top =
Width =
Height =
Align = alClient
TabOrder =
ExplicitWidth =
end
object GroupBox1: TGroupBox
Left =
Top =
Width =
Height =
Align = alRight
Caption = 'GroupBox1'
TabOrder =
OnClick = GroupBox1Click
ExplicitLeft =
end
end
最新文章
- 人之初,性本动 - G2 2.1 发布
- 更新整理本人所有博文中提供的代码与工具(C++,2014.01)
- VC++ 一个简单的Log类
- python基础——偏函数
- iOS:模态弹出窗控制器UIPopoverPresentationController
- javascript-函数的参数和return语句
- VS2012启用angularjs智能提示Intelligence
- 1. Apache ZooKeeper快速课程入门
- <;数据结构基础学习>;(四)链表 Part 1
- Actifio中的Group和Consistency Group
- 利用webpack手动构建vue工程
- 探讨e.target与e.currentTarget
- CocoaPods did not set the base configuration of your project because your project already has a custom config set.
- 为通过 ATS 检测 Tomcat 完全 TLS v1.2、完全正向加密及其结果检验
- 【Linux】通过SSH修改调整Linux时间和时区
- SVN目录权限配置
- outline的兼容性及使用限制
- 178. Rank Scores - database - 178. Rank Scores (Oracle)
- 直接下载jdk压缩包方式安装
- 泛型约束-swift
热门文章
- Centos 7 SSh--端口号的更改
- xavier_uniform/xavier_normal
- UEditor富文本编辑器简单使用
- 使用vux的x-input组件中show-clear=“true”清除icon点击失效的问题
- vue 中一些API 或属性的常见用法
- win10系统配置java环境及遇到问题的一些处理方法
- HDU-3081-Marriage Match 2(最大流, 二分答案, 并查集)
- JDBC与Hibernate的区别
- 【深入理解CLR】2:细谈值类型的装箱和拆箱
- 我的Android案例签到日历