Студопедия

КАТЕГОРИИ:


Архитектура-(3434)Астрономия-(809)Биология-(7483)Биотехнологии-(1457)Военное дело-(14632)Высокие технологии-(1363)География-(913)Геология-(1438)Государство-(451)Демография-(1065)Дом-(47672)Журналистика и СМИ-(912)Изобретательство-(14524)Иностранные языки-(4268)Информатика-(17799)Искусство-(1338)История-(13644)Компьютеры-(11121)Косметика-(55)Кулинария-(373)Культура-(8427)Лингвистика-(374)Литература-(1642)Маркетинг-(23702)Математика-(16968)Машиностроение-(1700)Медицина-(12668)Менеджмент-(24684)Механика-(15423)Науковедение-(506)Образование-(11852)Охрана труда-(3308)Педагогика-(5571)Полиграфия-(1312)Политика-(7869)Право-(5454)Приборостроение-(1369)Программирование-(2801)Производство-(97182)Промышленность-(8706)Психология-(18388)Религия-(3217)Связь-(10668)Сельское хозяйство-(299)Социология-(6455)Спорт-(42831)Строительство-(4793)Торговля-(5050)Транспорт-(2929)Туризм-(1568)Физика-(3942)Философия-(17015)Финансы-(26596)Химия-(22929)Экология-(12095)Экономика-(9961)Электроника-(8441)Электротехника-(4623)Энергетика-(12629)Юриспруденция-(1492)Ядерная техника-(1748)

To display the color dialog box




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

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

Пример

Динамическое отображение компонента OpenFileDialog

Robust Programming

Compiling the Code

Example

// Create an OpenFileDialog object.

OpenFileDialog openFile1 = new OpenFileDialog();

 

// Initialize the OpenFileDialog to look for text files.

openFile1.Filter = "Text Files|*.txt";

 

// Check if the user selected a file from the OpenFileDialog.

if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

 

// Load the contents of the file into a RichTextBox control.

richTextBox1.LoadFile(openFile1.FileName, RichTextBoxStreamType.PlainText);

· Copy the code into the Load_Form1 event handler. When you run the program, you will be prompted to select a text file. The contents of the selected file will be displayed in a RichTextBox control.

Use the CheckFileExists, CheckPathExists, DefaultExt, Filter, Multiselect, and ValidateNames


Чтобы пользователи могли выбрать текстовый файл и загрузить его в элемент управления RichTextBox в форме Windows Forms, можно использовать компонент OpenFileDialog. В этом примере компонент OpenFileDialog создается во время выполнения.

// Create an OpenFileDialog object.

OpenFileDialog openFile1 = new OpenFileDialog();

 

// Initialize the OpenFileDialog to look for text files.

openFile1.Filter = "Text Files|*.txt";

 

// Check if the user selected a file from the OpenFileDialog.

if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

 

// Load the contents of the file into a RichTextBox control.

richTextBox1.LoadFile(openFile1.FileName, RichTextBoxStreamType.PlainText);

· Скопируйте код в обработчик событий Load_Form1. При выполнении программы будет выведен запрос на выбор текстового файла. Содержимое выбранного файла будет отображено в элементе управления RichTextBox.

Чтобы сократить число ошибок во время выполнения, используйте свойства CheckFileExists, CheckPathExists, DefaultExt, Filter, Multiselect и ValidateNames элемента управления OpenFileDialog.


How to: Display a Color Pallet

You can use the built-in ColorDialog component to display a color dialog box instead of creating your own color pallet. For example, you can enable users to select a color to apply to a Windows form when they click a button on the form.

1. On the File menu, click New Project.

The New Project dialog box appears.

2. Click Windows Forms Application and then click OK.

3. From the Toolbox, drag a Button control to the form, and change the following properties in the Properties window:

Property Value
Name formColor
Text Color

4. Drag a ColorDialog component from the Dialogs tab of the Toolbox to the form.

colorDialog1 appears in the component tray.

5. Double-click the Color button to create the default event handler in the Code Editor.

6. In the formColor_Click event handler, add the following code to display the color dialog box and change the background color of the form according to the user's choice.

if (colorDialog1.ShowDialog() == DialogResult.OK) { this.BackColor = colorDialog1.Color; }

7. Press F5 to run the code.

8. When the form opens, click Color, click a color in the resulting dialog box, and then click OK.

9. Verify that the chosen color is applied to the form.

10. Close the application.





Поделиться с друзьями:


Дата добавления: 2014-12-27; Просмотров: 343; Нарушение авторских прав?; Мы поможем в написании вашей работы!


Нам важно ваше мнение! Был ли полезен опубликованный материал? Да | Нет



studopedia.su - Студопедия (2013 - 2024) год. Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав! Последнее добавление




Генерация страницы за: 0.012 сек.