Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Учебник_ПОА.doc
Скачиваний:
93
Добавлен:
13.02.2015
Размер:
2.65 Mб
Скачать

How to: Determine the Span Between Two Dates

This example calculates the difference in days between two dates and constructs a TimeSpan value for that difference.

Example

DateTime oldDate = new DateTime(2002,7,15);

DateTime newDate = DateTime.Now;

// Difference in days, hours, and minutes.

TimeSpan ts = newDate - oldDate;

// Difference in days.

int differenceInDays = ts.Days;

System.Console.WriteLine("Difference in days: {0} ", differenceInDays);

System.Console.ReadLine();

Compiling the Code

Copy the code and paste it into the Main method of a console application.

Определение интервала между двумя датами

В этом примере вычисляется разница в днях между двумя датами и создается для нее значение TimeSpan.

Пример

DateTime oldDate = new DateTime(2002,7,15);

DateTime newDate = DateTime.Now;

// Difference in days, hours, and minutes.

TimeSpan ts = newDate - oldDate;

// Difference in days.

int differenceInDays = ts.Days;

System.Console.WriteLine("Difference in days: {0} ", differenceInDays);

System.Console.ReadLine();

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

Скопируйте код и вставьте его в метод Main консольного приложения.

TreeView Controls

You can design an application to resemble Windows Explorer by using a TreeView control. This section provides links to topics that show you how to add nodes to a TreeView control.

How to: Add Nodes to a TreeView Control

This example adds three first-level nodes to an existing TreeView control.

Example

treeView1.Nodes.Add("First Node");

treeView1.Nodes.Add("Second Node");

treeView1.Nodes.Add("Third Node");

Compiling the Code

This example requires:

  • A TreeView control named treeView1.

How to: Add Nested Nodes to a TreeView Control

This example adds a first-level node and a second-level node to an existing TreeView control.

Example

TreeNode node = treeView1.Nodes.Add("Level one node");

node.Nodes.Add("Level two node");

Элементы управления "TreeView"

С помощью элемента управления TreeView можно разработать приложение, напоминающее Windows Explorer. Здесь представлены ссылки на разделы, где описывается добавление узлов к элементу управления TreeView.

Добавление узлов к элементу управления "TreeView"

В этом примере три узла первого уровня добавляются в существующий элемент управления TreeView.

Пример

treeView1.Nodes.Add("First Node");

treeView1.Nodes.Add("Second Node");

treeView1.Nodes.Add("Third Node");

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

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

  • Элемент управления TreeView с именем treeView1.

Добавление вложенных узлов в элемент управления "TreeView"

В этом примере узел первого уровня и узел второго уровня добавляется в существующий элемент управления TreeView.

Пример11

TreeNode node = treeView1.Nodes.Add("Level one node");

node.Nodes.Add("Level two node");

How to: Add a Node to the Selected Node of a TreeView Control

This example adds one node to the selected node of an existing TreeView control.

Example

try

{

TreeNode node = treeView1.SelectedNode;

node.Nodes.Add("New node below selected node");

}

catch (Exception)

{

// Handle the exception.

}

Compiling the Code

This example requires:

  • A TreeView control named treeView1.

Robust Programming

The following conditions may cause an exception:

  • The TreeView control has no nodes or none of the nodes is selected.

Добавление узла в выбранный узел элемента управления "TreeView"

Этот пример добавляет один узел в выбранный узел существующего элемента управления TreeView.

Пример

try

{

TreeNode node = treeView1.SelectedNode;

node.Nodes.Add("New node below selected node");

}

catch (Exception)

{

// Handle the exception.

}

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

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

  • Элемент управления TreeView с именем treeView1.

Надежное программирование

Исключение может возникнуть при следующих условиях:

  • Элемент управления treeView1 не имеет узлов либо ни один из узлов не был выбран.

Creating a Custom UI

You can customize the user interface (UI) of an application by adding standard toolbars, and shortcut menus. You can also add tooltips to controls in an application. This section provides links to topics that describe how to customize an application's UI.

How to: Add Toolbars to a Windows Forms Application

You can easily add a toolbar to your application by adding a ToolStrip control and then adding buttons to the toolbar. You can add individual ToolStripButton controls, or you can select from a group of controls, such as the ToolStripTextBox control. You can easily add a set of standard toolbar buttons to the toolbar by using the ToolStrip Tasks pane. This task pane lets you insert seven standard buttons onto the toolbar, as shown in the following illustration.

Accessing the ToolStrip Tasks pane