logo search
Учебник_ПОА

How to: Create a Tooltip for a Control

This example programmatically creates a ToolTip for a Windows Forms control.

Example

private void Form1_Load(object sender, System.EventArgs e)

{

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();

ToolTip1.SetToolTip(this.textBox1, "Hello");

}

Compiling the Code

This example requires:

Создание всплывающей подсказки для элемента управления

В этом примере программно создается объект ToolTip для элемента управления Windows Forms.

Пример

private void Form1_Load(object sender, System.EventArgs e)

{

System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();

ToolTip1.SetToolTip(this.textBox1, "Hello");

}

Компиляция кода13

Для этого примера необходимы следующие компоненты.

How to: Create a Shortcut Menu and Attach it to a Control

This example programmatically creates a Windows Forms ContextMenu and associates it with a control.

Example

private void Form1_Load(object sender, System.EventArgs e)

{

System.Windows.Forms.ContextMenu contextMenu1;

contextMenu1 = new System.Windows.Forms.ContextMenu();

System.Windows.Forms.MenuItem menuItem1;

menuItem1 = new System.Windows.Forms.MenuItem();

System.Windows.Forms.MenuItem menuItem2;

menuItem2 = new System.Windows.Forms.MenuItem();

System.Windows.Forms.MenuItem menuItem3;

menuItem3 = new System.Windows.Forms.MenuItem();

contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {menuItem1, menuItem2, menuItem3});

menuItem1.Index = 0;

menuItem1.Text = "MenuItem1";

menuItem2.Index = 1;

menuItem2.Text = "MenuItem2";

menuItem3.Index = 2;

menuItem3.Text = "MenuItem3";

textBox1.ContextMenu = contextMenu1;

}