你是怎么模拟的啊??
当MSHFlexGrid调整宽度时,让文本框不显示啊,
当调整好后,当表格单元格获得输入焦点时,在将文本框显示啊,而且将它的长和宽设成和单元格相等不就行了。
这是我写的模拟电子表格的代码Const ASC_ENTER = 13 '回车
Dim gRow As Integer
Dim gCol As IntegerPrivate 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
  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.SetFocus  ' Redirect this KeyPress event to the text box: If KeyAscii <> ASC_ENTER Then   SendKeys Chr$(KeyAscii) End IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER ThenGrid1.SetFocus ' Set focus back to grid, see Text_LostFocus.KeyAscii = 0 ' Ignore this KeyPress.End IfEnd SubPrivate Sub Text1_LostFocus()
Dim tmpRow As IntegerDim 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 = tmpColEnd Sub

解决方案 »

  1.   

    回复dragon525
    我和你的做法类似,但我想调整表格宽度的同时,文本框的宽度也同时跟着变,做到时时都和表格列同宽?
      

  2.   

    是啊!是这样的啊,当我调整宽度后,文本框的宽度本来就和列同宽啊。如这句:Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
    Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY或这样写:
    Text1.Width = Grid1.CellWidth 
    Text1.Height = Grid1.CellHeight 你把我的代码运行试一试,然后再和你的比较看看?再找找原因。
      

  3.   

    兄台的意思是否是在Text的Visible为true时用鼠标调整进行列宽调整,我也遇到此问题,不知如何解决
      

  4.   

    调整列的宽时,为什么要使text.visible=true呢? 那么这时的textbox在哪个单元格上显示呢?麻烦楼上的解释一下。