Interaction.InputBox(String, String, String, Int32, Int32) Método
Definição
Exibe um aviso em uma caixa de diálogo, aguarda até que o usuário insira um texto ou clique em um botão e retorna uma cadeia de caracteres que contém o conteúdo da caixa de texto.Displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a string containing the contents of the text box.
public static string InputBox (string Prompt, string Title = "", string DefaultResponse = "", int XPos = -1, int YPos = -1);
static member InputBox : string * string * string * int * int -> string
Public Function InputBox (Prompt As String, Optional Title As String = "", Optional DefaultResponse As String = "", Optional XPos As Integer = -1, Optional YPos As Integer = -1) As String
Parâmetros
- Prompt
- String
Expressão String necessária exibida como a mensagem na caixa de diálogo.Required String expression displayed as the message in the dialog box. O tamanho máximo de Prompt é de aproximadamente 1.024 caracteres, dependendo da largura dos caracteres usados.The maximum length of Prompt is approximately 1024 characters, depending on the width of the characters used. Se Prompt consistir em mais de uma linha, você poderá separar as linhas usando um caractere de retorno de carro (Chr(13)), um caractere de alimentação de linha (Chr(10)) ou uma combinação de retorno de carro/alimentação de linha (Chr(13) & Chr(10)) entre cada linha.If Prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a line feed character (Chr(10)), or a carriage return/line feed combination (Chr(13) & Chr(10)) between each line.
- Title
- String
Opcional.Optional. Expressão String exibida na barra de título da caixa de diálogo.String expression displayed in the title bar of the dialog box. Se você omitir Title, o nome do aplicativo será colocado na barra de título.If you omit Title, the application name is placed in the title bar.
- DefaultResponse
- String
Opcional.Optional. Expressão String exibida na caixa de texto como a resposta padrão se nenhuma outra entrada for fornecida.String expression displayed in the text box as the default response if no other input is provided. Se você omitir DefaultResponse, a caixa de texto exibida estará vazia.If you omit DefaultResponse, the displayed text box is empty.
- XPos
- Int32
Opcional.Optional. Expressão numérica que especifica, em twips, a distância desde a borda esquerda da caixa de diálogo até a borda esquerda da tela.Numeric expression that specifies, in twips, the distance of the left edge of the dialog box from the left edge of the screen. Se você omitir XPos, a caixa de diálogo será centralizada horizontalmente.If you omit XPos, the dialog box is centered horizontally.
- YPos
- Int32
Opcional.Optional. Expressão numérica que especifica, em twips, a distância desde a borda superior da caixa de diálogo até a parte superior da tela.Numeric expression that specifies, in twips, the distance of the upper edge of the dialog box from the top of the screen. Se você omitir YPos, a caixa de diálogo será posicionada verticalmente, a aproximadamente um terço da parte inferior da tela.If you omit YPos, the dialog box is positioned vertically approximately one-third of the way down the screen.
Retornos
Exibe um aviso em uma caixa de diálogo, aguarda até que o usuário insira um texto ou clique em um botão e retorna uma cadeia de caracteres que contém o conteúdo da caixa de texto.Displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a string containing the contents of the text box.
Exemplos
Este exemplo mostra várias maneiras de usar a InputBox função para solicitar que o usuário insira um valor.This example shows various ways to use the InputBox function to prompt the user to enter a value. Se as posições x e y forem omitidas, a caixa de diálogo será automaticamente centralizada para os respectivos eixos.If the x and y positions are omitted, the dialog box is automatically centered for the respective axes. A variável MyValue contém o valor inserido pelo usuário se o usuário clicar em OK ou pressionar a tecla Enter.The variable MyValue contains the value entered by the user if the user clicks OK or presses the ENTER key.
Dim message, title, defaultValue As String
Dim myValue As Object
' Set prompt.
message = "Enter a value between 1 and 3"
' Set title.
title = "InputBox Demo"
defaultValue = "1" ' Set default value.
' Display message, title, and default value.
myValue = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is "" Then myValue = defaultValue
' Display dialog box at position 100, 100.
myValue = InputBox(message, title, defaultValue, 100, 100)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is "" Then myValue = defaultValue
Comentários
Se o usuário clicar em Cancelar, uma cadeia de caracteres de comprimento zero será retornada.If the user clicks Cancel, a zero-length string is returned.
Para especificar mais do que o primeiro argumento, você deve usar a InputBox função em uma expressão.To specify more than the first argument, you must use the InputBox function in an expression. Se você omitir qualquer argumento posicional, deverá manter o delimitador de vírgula correspondente.If you omit any positional arguments, you must retain the corresponding comma delimiter.
Observação
A InputBox função requer UIPermission no SafeTopLevelWindows nível, o que pode afetar sua execução em situações de confiança parcial.The InputBox function requires UIPermission at the SafeTopLevelWindows level, which may affect its execution in partial-trust situations. Para obter mais informações, consulte solicitando permissões e UIPermission .For more information, see Requesting Permissions and UIPermission .