| Украина, Киев |
Опубликован: 13.07.2010 | Уровень: специалист | Доступ: платный
Самостоятельная работа 26:
Пользовательские элементы управления
Настройка части свойств объектов музыкальных кнопок в конструкторе класса SoundButtonBox
-
Добавьте
в конец конструктора класса SoundButtonBox одноименного
файла C# код, чтобы класс стал таким
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace MyCompany.UserControls
{
public partial class SoundButtonBox : UserControl
{
public SoundButtonBox()
{
InitializeComponent();
// Подключить первую кнопку к звуковому файлу
soundButton1.WaveFile = System.IO.Path.Combine( // Склеить два пути
Environment.GetEnvironmentVariable("windir"), // Каталог системы
@"Media\tada.wav");
// Подключить вторую кнопку к звуковому файлу
soundButton2.WaveFile = "SOUND827.WAV";
// Подключить третью кнопку к звуковому файлу из файла ресурсов сборки
Stream.WaveStream = this.GetType().Assembly.GetManifestResourceStream(
"MyCompany.UserControls.Trumpet1.wav");
}
}
}
Листинг
19.9.
Класс SoundButtonBox в файле SoundButtonBox.cs
Ниже приведен код, формируемый оболочкой при настройке компонента SoundButtonBox в визуальном режиме
namespace MyCompany.UserControls
{
partial class SoundButtonBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.flow = new System.Windows.Forms.FlowLayoutPanel();
this.soundButton1 = new MyCompany.UserControls.SoundButton(this.components);
this.soundButton2 = new MyCompany.UserControls.SoundButton(this.components);
this.Stream = new MyCompany.UserControls.SoundButton(this.components);
this.Web = new MyCompany.UserControls.SoundButton(this.components);
this.flow.SuspendLayout();
this.SuspendLayout();
//
// flow
//
this.flow.AutoSize = true;
this.flow.Controls.Add(this.soundButton1);
this.flow.Controls.Add(this.soundButton2);
this.flow.Controls.Add(this.Stream);
this.flow.Controls.Add(this.Web);
this.flow.Dock = System.Windows.Forms.DockStyle.Fill;
this.flow.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flow.Location = new System.Drawing.Point(0, 0);
this.flow.Name = "flow";
this.flow.Size = new System.Drawing.Size(440, 172);
this.flow.TabIndex = 0;
this.flow.WrapContents = false;
//
// soundButton1
//
this.soundButton1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.soundButton1.AutoSize = true;
this.soundButton1.Location = new System.Drawing.Point(88, 8);
this.soundButton1.Margin = new System.Windows.Forms.Padding(8);
this.soundButton1.Name = "soundButton1";
this.soundButton1.Size = new System.Drawing.Size(264, 27);
this.soundButton1.TabIndex = 0;
this.soundButton1.Text = "Файл tada.wav в системном каталоге";
this.soundButton1.UseVisualStyleBackColor = true;
this.soundButton1.WaveFile = "";
this.soundButton1.WaveStream = null;
//
// soundButton2
//
this.soundButton2.Anchor = System.Windows.Forms.AnchorStyles.None;
this.soundButton2.AutoSize = true;
this.soundButton2.Location = new System.Drawing.Point(28, 51);
this.soundButton2.Margin = new System.Windows.Forms.Padding(8);
this.soundButton2.Name = "soundButton2";
this.soundButton2.Size = new System.Drawing.Size(384, 27);
this.soundButton2.TabIndex = 1;
this.soundButton2.Text = "Файл SOUND827.WAV в каталоге исполняемой сборки";
this.soundButton2.UseVisualStyleBackColor = true;
this.soundButton2.WaveStream = null;
//
// Stream
//
this.Stream.Anchor = System.Windows.Forms.AnchorStyles.None;
this.Stream.AutoSize = true;
this.Stream.Location = new System.Drawing.Point(41, 94);
this.Stream.Margin = new System.Windows.Forms.Padding(8);
this.Stream.Name = "Stream";
this.Stream.Size = new System.Drawing.Size(358, 27);
this.Stream.TabIndex = 2;
this.Stream.Text = "Файл Trumpet1.wav в ресурсе исполняемой сборки";
this.Stream.UseVisualStyleBackColor = true;
this.Stream.WaveFile = "";
this.Stream.WaveStream = null;
//
// Web
//
this.Web.Anchor = System.Windows.Forms.AnchorStyles.None;
this.Web.AutoSize = true;
this.Web.Location = new System.Drawing.Point(8, 137);
this.Web.Margin = new System.Windows.Forms.Padding(8);
this.Web.Name = "Web";
this.Web.Size = new System.Drawing.Size(424, 27);
this.Web.TabIndex = 3;
this.Web.Text = "Файл azlinsnd.wav, загружаемый из Web по URL (отключено)";
this.Web.UseVisualStyleBackColor = true;
this.Web.WaveFile = "http://www.oaklandzoo.org/atoz/azlinsnd.wav";
this.Web.WaveStream = null;
//
// SoundButtonBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.Controls.Add(this.flow);
this.Name = "SoundButtonBox";
this.Size = new System.Drawing.Size(440, 172);
this.flow.ResumeLayout(false);
this.flow.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.FlowLayoutPanel flow;
private SoundButton soundButton1;
private SoundButton soundButton2;
private SoundButton Stream;
private SoundButton Web;
}
}
Листинг
19.10.
Код файла SoundButtonBox.Designer.cs