首页 增加 MsFlexGrid 的编辑功能

增加 MsFlexGrid 的编辑功能

举报
开通vip

增加 MsFlexGrid 的编辑功能增加 MsFlexGrid 的编辑功能 概述 MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能。 在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。 实现步骤 1 打开 VB5, 开启一个新的工程。 2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..” 3 放一个 MsFlexGri...

增加 MsFlexGrid 的编辑功能
增加 MsFlexGrid 的编辑功能 概述 MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能。 在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。 实现步骤 1 打开 VB5, 开启一个新的工程。 2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..” 3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, BorderStyle 为 None(0)。 4 在Form1 的代码中增加声明: Const ASC_ENTER = 13 '回车 Dim gRow As Integer Dim gCol As Integer 5 增加代码到 Grid_KeyPress 过程: Private Sub Grid1_KeyPress(KeyAscii As Integer) ' Move the text box to the current grid cell: Text1.Top = Grid1.CellTop + Grid1.Top Text1.Left = Grid1.CellLeft + Grid1.Left ' Save the position of the grids Row and Col for later: gRow = Grid1.Row gCol = Grid1.Col ' Make text box same size as current grid cell: Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY ' Transfer the grid cell text: Text1.Text = Grid1.Text ' Show the text box: Text1.Visible = True Text1.ZOrder 0 ' 把 Text1 放到最前面! Text1.SetFocus ' Redirect this KeyPress event to the text box: If KeyAscii <> ASC_ENTER Then SendKeys Chr$(KeyAscii) End If End Sub 6 增加代码到 Text1_KeyPress 过程: Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = ASC_ENTER Then Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus. KeyAscii = 0 ' Ignore this KeyPress. End If End Sub 7 增加代码到 Text1_LostFocus 过程: Private Sub Text1_LostFocus() Dim tmpRow As Integer Dim tmpCol As Integer ' Save current settings of Grid Row and col. This is needed only if ' the focus is set somewhere else in the Grid. tmpRow = Grid1.Row tmpCol = Grid1.Col ' Set Row and Col back to what they were before Text1_LostFocus: Grid1.Row = gRow Grid1.Col = gCol Grid1.Text = Text1.Text ' Transfer text back to grid. Text1.SelStart = 0 ' Return caret to beginning. Text1.Visible = False ' Disable text box. ' Return row and Col contents: Grid1.Row = tmpRow Grid1.Col = tmpCol End Sub 8 好了。 按 F5 开始测试。 您可以自由地在 Grid 中移动, 按回车可以开始或结束编辑。
本文档为【增加 MsFlexGrid 的编辑功能】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_633808
暂无简介~
格式:doc
大小:15KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-10-16
浏览量:16