我想缩短文件名以适应TEdit,比如
Edit1.Text := MinimizeName(FileName, Edit1.Canvas, Edit1.Width);
不幸的是,这不能编译,因为TEdit Canvas
直接拥有属性.其字体指标需要画布.如何访问TEdit的画布?
(MinimizeName
在Vcl.FileCtrl中声明.)
你可以用TControlCanvas
.您还应该考虑控件的Font.
例如:
var Canvas: TControlCanvas; Canvas := TControlCanvas.Create; try Canvas.Control := Edit1; Canvas.Font.Assign(Edit1.Font); // Do something with Canvas... finally Canvas.Free; end;