⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m64.htm

📁 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程 vb教程
💻 HTM
字号:
<html>
<head>
<title>VB教程</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 
</head>
<p align="center"><script src="../../1.js"></script></a>

<body bgcolor="#ffffff" leftmargin="5" topmargin="1" marginheight="5" marginwidth="5">
<div align=center> 
  <table border=0 cellpadding=0 cellspacing=0 width=680 align="center">
    <tbody> 
     
    <tr> 
      <td bgcolor=#000000 height=9> 
        <div align=center class=H1>    <font color="#FFFFFF">增加 MsFlexGrid 的编辑功能</font> </font> </font></div>
      </td>
    </tr>
    <tr valign=top> 
      <td class=H1 height=76> 
        <p align="left">  <br>
           </font> 概述</font> </span></p>
        <p>   MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 
          实现编辑当前网格的功能。<br>
          <br>
          在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。 
          </font></span></p>
        <h3> <font color="#000000">实现步骤</font></span></h3>
        <p> <font color="#000000">1 打开 VB5, 开启一个新的工程。</font></span></p>
        <p> <font color="#000000">2 在菜单“工程” 中选择 “部件”, 在列表中选中 
          “Microsoft FlexGrid Control ..”</font></span></p>
        <p> <font color="#000000">3 放一个 MsFlexGrid 控件和一个TextBox 
          控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 为 4, 固定行,列为 
          0。 设置 Text1 的 Visiable 为 False, BorderStyle 为 None(0)。</font></span></p>
        <p> <font color="#000000">4 在Form1 的代码中增加声明:<br>
          <br>
          Const ASC_ENTER = 13 '回车<br>
          Dim gRow As Integer<br>
          Dim gCol As Integer</font></span></p>
        <p> <font color="#000000">5 增加代码到 Grid_KeyPress 
          过程:<br>
          <br>
          Private Sub Grid1_KeyPress(KeyAscii As Integer)<br>
          ' Move the text box to the current grid cell:<br>
          Text1.Top = Grid1.CellTop + Grid1.Top<br>
          Text1.Left = Grid1.CellLeft + Grid1.Left<br>
          ' Save the position of the grids Row and Col for later:<br>
          gRow = Grid1.Row<br>
          gCol = Grid1.Col<br>
          ' Make text box same size as current grid cell:<br>
          Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX<br>
          Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY<br>
          ' Transfer the grid cell text:<br>
          Text1.Text = Grid1.Text<br>
          ' Show the text box:<br>
          Text1.Visible = True<br>
          Text1.ZOrder 0 ' 把 Text1 放到最前面!<br>
          Text1.SetFocus<br>
          ' Redirect this KeyPress event to the text box:<br>
          If KeyAscii &lt;&gt; ASC_ENTER Then<br>
          SendKeys Chr$(KeyAscii)<br>
          End If<br>
          End Sub</font></span></p>
        <p> <font color="#000000">6 增加代码到 Text1_KeyPress 
          过程:<br>
          <br>
          Private Sub Text1_KeyPress(KeyAscii As Integer)<br>
          If KeyAscii = ASC_ENTER Then<br>
          Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.<br>
          KeyAscii = 0 ' Ignore this KeyPress.<br>
          End If<br>
          End Sub</font></span></p>
        <p> <font color="#000000">7 增加代码到 Text1_LostFocus 
          过程:<br>
          <br>
          Private Sub Text1_LostFocus()<br>
          Dim tmpRow As Integer<br>
          Dim tmpCol As Integer<br>
          ' Save current settings of Grid Row and col. This is needed only if<br>
          ' the focus is set somewhere else in the Grid.<br>
          tmpRow = Grid1.Row<br>
          tmpCol = Grid1.Col<br>
          ' Set Row and Col back to what they were before Text1_LostFocus:<br>
          Grid1.Row = gRow<br>
          Grid1.Col = gCol<br>
          Grid1.Text = Text1.Text ' Transfer text back to grid.<br>
          Text1.SelStart = 0 ' Return caret to beginning.<br>
          Text1.Visible = False ' Disable text box.<br>
          ' Return row and Col contents:<br>
          Grid1.Row = tmpRow<br>
          Grid1.Col = tmpCol<br>
          End Sub</font></span></p>
        <p> <font color="#000000">8 好了。 按 F5 开始测试。 您可以自由地在 
          Grid 中移动, 按回车可以开始或结束编辑。 </font></span>
        <p align="left">                                          <br>
           
  </table>
</div>
<p align="center"><a href="../../pian/vb.htm">回首页</a>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -