#region Windows Form. Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.axAgent1 = new AxAgentObjects.AxAgent();
((System.ComponentModel.ISupportInitialize)(this.axAgent1)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(112, 24);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(224, 152);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "
Type anything here for the character to read for you!(Only English)";
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "导入精灵";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 80);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "朗读文本";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(16, 136);
this.button3.Name = "button3";
this.button3.TabIndex = 1;
this.button3.Text = "隐藏精灵";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// axAgent1
//
this.axAgent1.Enabled = true;
this.axAgent1.Location = new System.Drawing.Point(320, 176);
this.axAgent1.Name = "axAgent1";
this.axAgent1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgent1.OcxState")));
this.axAgent1.Size = new System.Drawing.Size(32, 32);
this.axAgent1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(360, 213);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button3,
this.button2,
this.textBox1,
this.button1,
this.axAgent1});
this.Name = "Form1";
this.Text = "CoolUI";
((System.ComponentModel.ISupportInitialize)(this.axAgent1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
axAgent1.Characters.Load("Genie", (object)"GENIE.ACS");//导入吉尼这个精灵
Character = axAgent1.Characters["Genie"];
Character.LanguageID = 0x409;//把语言设置为英语,这里不能是中文
Character.Show(null);//显示精灵
button1.Enabled=false;//重新设置按钮的有效性
button2.Enabled=true;
button3.Enabled=true;
}
private void button2_Click(object sender, System.EventArgs e)
{
if(textBox1.Text.Length == 0) //如果没有字符的话,就不读
return;
Character.Speak(textBox1.Text, null);//让精灵朗读文本
}
private void button3_Click(object sender, System.EventArgs e)
{
Character.Play("Wave");
Character.Play("Hide");//隐藏精灵
} }
}
4.好了,现在完成了所有的工作了,安Ctrl+F5试试效果吧!
四.总结从以上的例子,我们可以发现用C#做Windows平台下的开发是相当迅速而有效的。其实上面的例子还可以大大扩充,使之实现像电子小说阅读、英文听力测试、英文单词学习等功能,读者不妨一试。