CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

GetString Method (.NET)

2023-1-1 15:35| 发布者: admin| 查看: 395| 评论: 0|来自: AutoCAD

该方法在命令提示符下提示用户输入字符串。该对象允许您控制输入的输入以及提示消息的显示方式。对象的属性控制在提示符下是否允许空格。如果设置为 false,则按空格键将终止输入。GetStringPromptStringOptionsAllowSpacesPromptStringOptions

在命令行从用户处获取字符串值

下面的示例显示“输入您的姓名”提示,并要求通过按 Enter 终止来自用户的输入(输入字符串中允许空格)。输入的字符串将显示在消息框中。

VB.NET

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
 
<CommandMethod("GetStringFromUser")> _
Public Sub GetStringFromUser()
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
 
    Dim pStrOpts As PromptStringOptions = New PromptStringOptions(vbLf & _
                                                                 "Enter your name: ")
    pStrOpts.AllowSpaces = True
    Dim pStrRes As PromptResult = acDoc.Editor.GetString(pStrOpts)
 
    Application.ShowAlertDialog("The name entered was: " & _
                                pStrRes.StringResult)
End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
 
[CommandMethod("GetStringFromUser")]
public static void GetStringFromUser()
{
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
    PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter your name: ");
    pStrOpts.AllowSpaces = true;
    PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);
 
    Application.ShowAlertDialog("The name entered was: " +
                                pStrRes.StringResult);
}

VBA/ActiveX 代码参考

Sub GetStringFromUser()
    Dim retVal As String
    retVal = ThisDrawing.Utility.GetString _
                                    (1, vbCrLf & "Enter your name: ")
    MsgBox "The name entered was: " & retVal
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:58

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部