以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]用内部函数更改表的样式 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=179265) |
||||||||
-- 作者:2425004926 -- 发布时间:2022/8/15 21:41:00 -- [求助]用内部函数更改表的样式 老师指点一下 ==================================================== 表的样式更换,为何不能执行?是不是不能这样表达 内部函数:TableTheme Dim t As Table = Args(0) \'样式设置1--------------------------------------------------------------------Dim cs1 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add("样式1") cs1.forecolor = Color.red \'表头字体颜色 cs1.backcolor = Color.yellow \'表头背景颜色 cs1.Border.Width = 1 \'表头轮廓宽度 cs1.Border.Color = Color.Silver \'表头轮廓颜色 cs1.Border.Direction = 3 \'这个数值没有影响 t.DataTable.SysStyles("Normal").BorderColor = Color.Silver \'网格线 \'样式设置2-------------------------------------------------------------------- Dim cs2 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add("样式1") cs2.forecolor = Color.red \'表头字体颜色 cs2.backcolor = Color.Pink \'表头背景颜色 cs2.Border.Width = 1 \'表头轮廓宽度 cs2.Border.Color = Color.Silver \'表头轮廓颜色 cs2.Border.Direction = 3 \'这个数值没有影响 t.DataTable.SysStyles("Normal").BorderColor = Color.Silver \'网格线 \'表头颜色--------------------------------------------------------------------- For i As Integer = 0 To t.HeaderRows - 1 \'表头行数 For j As Integer = 0 To t.cols.count \'所有列,0为行号列,不含行号列就由1开始 t.Grid.SetCellStyle(i, j, Args(1)) Next Next 按钮代码: Functions.Execute("TableTheme", Tables(e.Form.name & "_table1"),"cs1") ‘不能执行 Functions.Execute("TableTheme", Tables(e.Form.name & "_table1"),cs1) ‘显示未命名cs1 ==================================================== 如果单独表示没有问题 内部函数:TableTheme Dim t As Table = Args(0) \'样式设置1--------------------------------------------------------------------Dim cs1 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add("样式1") cs1.forecolor = Color.red \'表头字体颜色 cs1.backcolor = Color.yellow \'表头背景颜色 cs1.Border.Width = 1 \'表头轮廓宽度 cs1.Border.Color = Color.Silver \'表头轮廓颜色 cs1.Border.Direction = 3 \'这个数值没有影响 t.DataTable.SysStyles("Normal").BorderColor = Color.Silver \'网格线 \'表头颜色--------------------------------------------------------------------- For i As Integer = 0 To t.HeaderRows - 1 \'表头行数 For j As Integer = 0 To t.cols.count \'所有列,0为行号列,不含行号列就由1开始 t.Grid.SetCellStyle(i, j, cs1) Next Next 按钮代码: Functions.Execute("TableTheme", Tables(e.Form.name & "_table1")) ‘OK ==================================================== 另外再问一下,Direction = 3 \'这个是什么意思,为何更改数值没有影响
|
||||||||
-- 作者:有点蓝 -- 发布时间:2022/8/15 21:58:00 -- Direction应该是设置单元格边框,不同数字应该指不同的位置,比如左边框,右边框。 没看懂第一个函数想干什么?2个样式分别用到哪里? 另外建议按照帮助使用,底层的用法不保证一直可用:
|
||||||||
-- 作者:2425004926 -- 发布时间:2022/8/15 22:06:00 -- 第一个函数:我把表的两个样式放在了一个内部函数里,函数名TableTheme,用按钮来更改样式,想着把代码写在一个函数里,没有测试成功 按钮代码1: Functions.Execute("TableTheme", Tables(e.Form.name & "_table1"),"cs1") ‘不能执行 Functions.Execute("TableTheme", Tables(e.Form.name & "_table1"),cs1) ‘显示未命名cs1 按钮代码2: Functions.Execute("TableTheme", Tables(e.Form.name & "_table1"),"cs2") ‘不能执行 Functions.Execute("TableTheme", Tables(e.Form.name & "_table1"),cs2) ‘显示未命名cs2 第二个函数:是把样式分开了,是OK的。 |
||||||||
-- 作者:有点蓝 -- 发布时间:2022/8/15 22:29:00 -- 内部函数:TableTheme Dim t As Table = Args(0) Dim 样式 As Table = Args(1) Dim cs1 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add(样式) if 样式 = "cs1" then cs1.forecolor = Color.red \'表头字体颜色 cs1.backcolor = Color.yellow \'表头背景颜色 …… else cs1.forecolor = Color.red \'表头字体颜色 cs1.backcolor = Color.pink \'表头背景颜色 …… end if \'表头颜色---------------------------------------------------------------------
For i As Integer = 0 To t.HeaderRows - 1 \'表头行数 For j As Integer = 0 To t.cols.count \'所有列,0为行号列,不含行号列就由1开始 t.Grid.SetCellStyle(i, j, cs1) Next Next |
||||||||
-- 作者:2425004926 -- 发布时间:2022/8/15 23:06:00 -- 感谢老师:测试OK! 总结一下代码,供大家参考 ----------------------------------------------------------------------- 内部函数:TableTheme Dim t As Table = Args(0) Dim 样式 As String = Args(1) Dim cs As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add(样式) If 样式 = "cs01" Then cs.forecolor = Color.red \'表头字体颜色 cs.backcolor = Color.yellow \'表头背景颜色 cs.Border.Width = 1 \'表头轮廓宽度 cs.Border.Color = Color.Silver \'表头轮廓颜色 cs.Border.Direction = 3 ‘0表示有竖线,有下横线;1表示无竖线,有下横线;2表示有竖线,无下横线;3及以后都是有竖线,有下横线 t.DataTable.SysStyles("Normal").BorderColor = Color.Silver \'网格线 ElseIf 样式 = "cs02" Then cs.forecolor = Color.red \'表头字体颜色 cs.backcolor = Color.Pink \'表头背景颜色 cs.Border.Width = 1 \'表头轮廓宽度 cs.Border.Color = Color.Silver \'表头轮廓颜色 cs.Border.Direction = 3 t.DataTable.SysStyles("Normal").BorderColor = Color.Silver \'网格线 End If \'表头颜色 For i As Integer = 0 To t.HeaderRows - 1 \'表头行数 For j As Integer = 0 To t.cols.count \'所有列,0为行号列,不含行号列就由1开始 t.Grid.SetCellStyle(i, j, cs) Next Next ----------------------------------------------------------------------- 按钮测试 按钮1:Functions.Execute("TableTheme",Tables(e.Form.name & "_table1"),"cs01") 按钮2:Functions.Execute("TableTheme",Tables(e.Form.name & "_table1"),"cs02") ----------------------------------------------------------------------- 选择区域或列时表头更换颜色 AfterSelRangeChange事件
Dim t As Table = Tables(e.Form.name & "_table1") Dim cs1 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add("样式1") \'cs1.forecolor = Color.red \'表头字体颜色 cs1.backcolor = Color.yellow \'表头背景颜色 Dim cs2 As C1.Win.C1FlexGrid.CellStyle = t.Grid.Styles.Add("样式2") \'cs2.forecolor = Color.red \'表头字体颜色 cs2.backcolor = Color.Orchid \'表头背景颜色 \'选择区域时表头更换颜色 For i As Integer = 0 To t.HeaderRows - 1 For j As Integer = 1 To t.cols.count \'所有列,0为行号列,不含行号列就由1开始 If j >= t.LeftCol + 1 AndAlso j <= t.RightCol + 1 Then t.Grid.SetCellStyle(i, j, cs2) Else t.Grid.SetCellStyle(i, j, cs1) End If Next Next |