2016-08-31 15 views
0

通过重复如何确定是否选择的是文本框的几个文本框的内部或不

Set Shp = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, 
      Left:=0, Top:=0, Width:=100, Height:=100) 

创建如何确定是否当前光标(或选择)是内部的文本框的一个或不?我想移动光标移出文本框,如果它是的,如果它不是在不移动光标

+0

您可以使用'Selection.StoryType'来检查选择内容是否在TextFrame中。 'Selection.Shaperange(1)'获取文本框。如果不是内联形状,将光标移动到文本框的外面会很棘手。 (使用锚点是我现在可以想到的唯一方法) – arcadeprecinct

+0

Selection.StoryType可以做到这一点。非常感谢你。 – ThisPaul

回答

-1

您将需要从这里得到的代码来获得/设置鼠标的位置: https://support.microsoft.com/en-us/kb/152969

然后写以下

Private Sub TextBox1_MouseMove(ByVal intButton As Integer, ByVal intShift As Integer, ByVal sngWidth As Single, ByVal sngHeight As Single) 

    If (sngWidth < 5 Or sngWidth > TextBox1.Width - 5) Or (sngHeight < 5 Or sngHeight > TextBox1.Height - 5) Then 
     SetCursorPos x, y 
    End If 
End Sub 
+0

问题是关于Microsoft Word文档中的文本框,而不是关于Windows窗体文本框,因此您的代码示例在此不适用。 –

0

你可以决定你的选择是否是一个文本框里面通过检查所选范围的StoryType属性:

Set Shp = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _ 
       Left:=0, Top:=0, Width:=100, Height:=100) 

If Selection.StoryType = WdStoryType.wdTextFrameStory Then 

    ' select the paragraph the shape is anchored to 
    Shp.Anchor.Select 

    ' collapse to the beginning of the paragraph 
    Selection.Collapse 
End If 
相关问题