ToolTip.SetToolTip(Control, String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Associa o texto do ToolTip ao controlo especificado.
public:
void SetToolTip(System::Windows::Forms::Control ^ control, System::String ^ caption);
public void SetToolTip(System.Windows.Forms.Control control, string caption);
member this.SetToolTip : System.Windows.Forms.Control * string -> unit
Public Sub SetToolTip (control As Control, caption As String)
Parâmetros
- caption
- String
O texto da ToolTip para mostrar quando o ponteiro está no controlo.
Exemplos
O exemplo de código seguinte cria uma instância da ToolTip classe e associa a instância à Form que a instância é criada. O código inicializa então as propriedades AutoPopDelayde atraso , InitialDelay, e ReshowDelay. Além disso, a instância da ToolTip classe define a ShowAlways propriedade para true permitir que o texto ToolTip seja exibido independentemente de o formulário estar ativo ou não. Finalmente, o exemplo associa o texto ToolTip a dois controlos num formulário, a Button e um CheckBox. Este exemplo exige que o método definido no exemplo esteja localizado dentro de um Form que contenha um Button controlo nomeado button1 e um CheckBox controlo nomeado checkBox1, e que o método seja chamado do construtor do Form.
// This example assumes that the Form_Load event handling method
// is connected to the Load event of the form.
void Form1_Load( Object^ sender, System::EventArgs^ e )
{
// Create the ToolTip and associate with the Form container.
ToolTip^ toolTip1 = gcnew ToolTip;
// Set up the delays for the ToolTip.
toolTip1->AutoPopDelay = 5000;
toolTip1->InitialDelay = 1000;
toolTip1->ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1->ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1->SetToolTip( this->button1, "My button1" );
toolTip1->SetToolTip( this->checkBox1, "My checkBox1" );
}
// This example assumes that the Form_Load event handling method
// is connected to the Load event of the form.
private void Form1_Load(object sender, System.EventArgs e)
{
// Create the ToolTip and associate with the Form container.
ToolTip toolTip1 = new ToolTip();
// Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(this.button1, "My button1");
toolTip1.SetToolTip(this.checkBox1, "My checkBox1");
}
' This example assumes that the Form_Load event handling method
' is connected to the Load event of the form.
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
' Create the ToolTip and associate with the Form container.
Dim toolTip1 As New ToolTip()
' Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000
toolTip1.InitialDelay = 1000
toolTip1.ReshowDelay = 500
' Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = True
' Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(Me.button1, "My button1")
toolTip1.SetToolTip(Me.checkBox1, "My checkBox1")
End Sub
Observações
Para além de especificar o texto da ToolTip para ser exibido para um controlo, também pode usar este método para modificar o texto da ToolTip para um controlo. Chamar o SetToolTip método mais do que uma vez para um determinado controlo não especifica múltiplos textos de ToolTip para mostrar para um controlo, mas sim altera o texto atual do ToolTip para o controlo. Para determinar o texto da ToolTip associado a um controlo em tempo de execução, use o GetToolTip método.
Como regra geral, o texto utilizado deve ser curto; No entanto, podes inserir quebras de linha usando a sequência de \r\n caracteres escape. Os e ampersands (&) no texto são tratados conforme descrito pela StripAmpersands propriedade.