有些朋友向我提出,怎样使编辑状态下的单元格文本垂直居中显示。Spread 表格控件单元格有两种状态,编辑状态和普通显示状态。在显示状态下,我们可以通过单元格的格式相关属性来设置单元格样式、对齐方式。该功能我们需要通过自定义单元格方式实现。
实现该功能的核心代码如下:
1: public override Control GetEditorControl(Control parent, FarPoint.Win.Spread.Appearance appearance, float zoomFactor) 2: { 3: TextBox tb = new TextBox(); 4: FarPoint.Win.Spread.FpSpread spread = parent as FarPoint.Win.Spread.FpSpread; 5: float height = spread.Sheets[0].ActiveRow.Height; 6: float width = spread.Sheets[0].ActiveColumn.Width; 7: tb.Width = (int)width; 8: tb.Location = new Point(0, (int)(height / 2 - tb.Height / 2) + 2); 9: tb.Text = spread.Sheets[0].ActiveCell.Text; 10: uc = new MyEditorControl(tb); 11: uc.Height = (int)height; 12: uc.Width = (int)width; 13: return uc; 14: }
自定义单元格编译器由 TextBox 和 UserControl 组成。我们可以通过调整 TextBox 的位置来实现输入时文本居中。主要是通过获取当前编辑单元格的大小,来设置自定义编辑器的大小,从而确定 TextBox 的位置。
在设置单元格内容之后,我们通过以下代码返回单元格值:
1: public override object GetEditorValue() 2: { 3: return uc.Tb.Text; 4: }
基于 UserControl 实现的自定义编辑器代码如下:
1: public partial class MyEditorControl : UserControl 2: { 3: TextBox tb; 4: 5: public MyEditorControl(TextBox tb1) 6: { 7: this.BackColor = Color.White; 8: tb = tb1; 9: tb.BorderStyle = System.Windows.Forms.BorderStyle.None; 10: this.Controls.Add(tb); 11: } 12: public TextBox Tb 13: { 14: get { return tb; } 15: set { tb = value; } 16: } 17: }
效果图:
源码下载:VS 2010 + Spread Studio .NET 7 + .NET 4.0:点击下载
使用控件查看地址:点击查看
相关推荐
Spread for WinForm 5 中文版 Demo 源码.完整示例.值得习
Spread Studio for强大的报表功能,这是Spread Studio for使用说明书,看了肯定能帮到你。
Farpoint Spread5 Winform 中文帮助文档
.NET平台最流行的表格控件Spread for Windows Forms5.0的完整中文手册,包括: (1)开发指南:为Spread for Windows Forms的开发人员提供了概念性介绍材料和常规任务的操作说明。 该指南描述了一个应用程序开发者...
Spread Studio for .NET 试用版 试用版 开发语言: .NET 可用平台: Visual Studio 2008/2010/2012/2013 当前版本: 9.0 Studio for .NET是一个功能和Excel类似的表格控件工具包。用于在您的应用系统中实现表格数据...
这是Spread for WinForms V7.0 API中文文档。里面记载很详细,很方便开发!
本文档专为国内广大开发者写作而成,通过大家最熟悉的语言和文化帮助您快速查找和理解Spread众多API的使用方法。文档提供接口和参数描述,同时提供大量例子和代码片段,以方便您了解产品的易用性、扩展性和灵活性。
Spread for Windows Forms 5.0 中文帮助chm,开发者指南
Spread for asp.net 5.0 使用手册
Vue+SpringBoot+SpreadJS 实现的在线文档功能.docxVue+SpringBoot+SpreadJS 实现的在线文档功能.docxVue+SpringBoot+SpreadJS 实现的在线文档功能.docxVue+SpringBoot+SpreadJS 实现的在线文档功能.docxVue+...
1 Spread spectrum signals and systems 1 1.1 Basic definition 1 1.2 Historical sketch 5 2 Classical reception problems and signal design 7 2.1 Gaussian channel, general reception problem and optimal ...
Farpoint.Spread5.winform公式指南中文版
Spread for ASP.NET 表格控件 V7.0 使用指南 http://www.gcpowertools.com.cn/products/spread_studio_demo.htm
Physical Layer Standard for cdma2000 Spread Spectrum Systems Release 0
Vue+SpringBoot+SpreadJS 实现的在线文档,教程:https://blog.csdn.net/qq_28136751/article/details/111404923
Spread for WinForms 表格控件 V7.0 使用指南
本文档专为国内广大开发者写作而成,通过大家最熟悉的语言和文化帮助您快速查找和理解Spread众多API的使用方法。文档提供接口和参数描述,同时提供大量例子和代码片段,以方便您了解产品的易用性、扩展性和灵活性。 ...
Spread for ASP.NET V7.0 API文档,很详细的好资料.做前台表格的应该会用到!
spreadjs_自定义单元格实现层级树-demo