Agent Tryout : Agent Help « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » Agent HelpScreenshots 
Agent Tryout
Agent Tryout

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AgentTryout
{
  /// <summary>
  /// Summary description for AgentTryout.
  /// </summary>
  public class AgentTryout : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.Button cmdClose;
    internal System.Windows.Forms.GroupBox GroupBox3;
    internal System.Windows.Forms.Label Label2;
    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.TextBox txtY;
    internal System.Windows.Forms.TextBox txtX;
    internal System.Windows.Forms.Button cmdMove;
    internal System.Windows.Forms.GroupBox GroupBox2;
    internal System.Windows.Forms.Button cmdSpeak;
    internal System.Windows.Forms.TextBox txtSpeak;
    internal System.Windows.Forms.GroupBox GroupBox1;
    internal System.Windows.Forms.Button cmdStop;
    internal System.Windows.Forms.Button cmdPlay;
    internal System.Windows.Forms.ListBox lstAnimations;
    private AxAgentObjects.AxAgent axAgent1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public AgentTryout()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form 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()
    {
      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AgentTryout));
      this.cmdClose = new System.Windows.Forms.Button();
      this.GroupBox3 = new System.Windows.Forms.GroupBox();
      this.Label2 = new System.Windows.Forms.Label();
      this.Label1 = new System.Windows.Forms.Label();
      this.txtY = new System.Windows.Forms.TextBox();
      this.txtX = new System.Windows.Forms.TextBox();
      this.cmdMove = new System.Windows.Forms.Button();
      this.GroupBox2 = new System.Windows.Forms.GroupBox();
      this.cmdSpeak = new System.Windows.Forms.Button();
      this.txtSpeak = new System.Windows.Forms.TextBox();
      this.GroupBox1 = new System.Windows.Forms.GroupBox();
      this.axAgent1 = new AxAgentObjects.AxAgent();
      this.cmdStop = new System.Windows.Forms.Button();
      this.cmdPlay = new System.Windows.Forms.Button();
      this.lstAnimations = new System.Windows.Forms.ListBox();
      this.GroupBox3.SuspendLayout();
      this.GroupBox2.SuspendLayout();
      this.GroupBox1.SuspendLayout();
      ((System.ComponentModel.ISupportInitialize)(this.axAgent1)).BeginInit();
      this.SuspendLayout();
      // 
      // cmdClose
      // 
      this.cmdClose.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
      this.cmdClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdClose.Location = new System.Drawing.Point(295331);
      this.cmdClose.Name = "cmdClose";
      this.cmdClose.Size = new System.Drawing.Size(9624);
      this.cmdClose.TabIndex = 12;
      this.cmdClose.Text = "Close";
      this.cmdClose.Click += new System.EventHandler(this.cmdClose_Click);
      // 
      // GroupBox3
      // 
      this.GroupBox3.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left
        | System.Windows.Forms.AnchorStyles.Right);
      this.GroupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
                                          this.Label2,
                                          this.Label1,
                                          this.txtY,
                                          this.txtX,
                                          this.cmdMove});
      this.GroupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.GroupBox3.Location = new System.Drawing.Point(8251);
      this.GroupBox3.Name = "GroupBox3";
      this.GroupBox3.Size = new System.Drawing.Size(38464);
      this.GroupBox3.TabIndex = 11;
      this.GroupBox3.TabStop = false;
      this.GroupBox3.Text = "Move";
      // 
      // Label2
      // 
      this.Label2.Location = new System.Drawing.Point(8428);
      this.Label2.Name = "Label2";
      this.Label2.Size = new System.Drawing.Size(2016);
      this.Label2.TabIndex = 11;
      this.Label2.Text = "Y:";
      // 
      // Label1
      // 
      this.Label1.Location = new System.Drawing.Point(1628);
      this.Label1.Name = "Label1";
      this.Label1.Size = new System.Drawing.Size(2016);
      this.Label1.TabIndex = 10;
      this.Label1.Text = "X:";
      // 
      // txtY
      // 
      this.txtY.Location = new System.Drawing.Point(10424);
      this.txtY.Name = "txtY";
      this.txtY.Size = new System.Drawing.Size(3620);
      this.txtY.TabIndex = 9;
      this.txtY.Text = "";
      // 
      // txtX
      // 
      this.txtX.Location = new System.Drawing.Point(3624);
      this.txtX.Name = "txtX";
      this.txtX.Size = new System.Drawing.Size(3620);
      this.txtX.TabIndex = 8;
      this.txtX.Text = "";
      // 
      // cmdMove
      // 
      this.cmdMove.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdMove.Location = new System.Drawing.Point(24824);
      this.cmdMove.Name = "cmdMove";
      this.cmdMove.Size = new System.Drawing.Size(7220);
      this.cmdMove.TabIndex = 7;
      this.cmdMove.Text = "Move";
      this.cmdMove.Click += new System.EventHandler(this.cmdMove_Click);
      // 
      // GroupBox2
      // 
      this.GroupBox2.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left
        | System.Windows.Forms.AnchorStyles.Right);
      this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
                                          this.cmdSpeak,
                                          this.txtSpeak});
      this.GroupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.GroupBox2.Location = new System.Drawing.Point(8163);
      this.GroupBox2.Name = "GroupBox2";
      this.GroupBox2.Size = new System.Drawing.Size(38480);
      this.GroupBox2.TabIndex = 10;
      this.GroupBox2.TabStop = false;
      this.GroupBox2.Text = "Speak";
      // 
      // cmdSpeak
      // 
      this.cmdSpeak.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdSpeak.Location = new System.Drawing.Point(24820);
      this.cmdSpeak.Name = "cmdSpeak";
      this.cmdSpeak.Size = new System.Drawing.Size(7220);
      this.cmdSpeak.TabIndex = 6;
      this.cmdSpeak.Text = "Speak";
      this.cmdSpeak.Click += new System.EventHandler(this.cmdSpeak_Click);
      // 
      // txtSpeak
      // 
      this.txtSpeak.AcceptsReturn = true;
      this.txtSpeak.Location = new System.Drawing.Point(820);
      this.txtSpeak.Multiline = true;
      this.txtSpeak.Name = "txtSpeak";
      this.txtSpeak.Size = new System.Drawing.Size(23248);
      this.txtSpeak.TabIndex = 4;
      this.txtSpeak.Text = "";
      // 
      // GroupBox1
      // 
      this.GroupBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom
        | System.Windows.Forms.AnchorStyles.Left
        | System.Windows.Forms.AnchorStyles.Right);
      this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                          this.axAgent1,
                                          this.cmdStop,
                                          this.cmdPlay,
                                          this.lstAnimations});
      this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.GroupBox1.Location = new System.Drawing.Point(811);
      this.GroupBox1.Name = "GroupBox1";
      this.GroupBox1.Size = new System.Drawing.Size(384144);
      this.GroupBox1.TabIndex = 9;
      this.GroupBox1.TabStop = false;
      this.GroupBox1.Text = "Animate";
      // 
      // axAgent1
      // 
      this.axAgent1.ContainingControl = this;
      this.axAgent1.Enabled = true;
      this.axAgent1.Location = new System.Drawing.Point(33632);
      this.axAgent1.Name = "axAgent1";
      this.axAgent1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgent1.OcxState")));
      this.axAgent1.Size = new System.Drawing.Size(3232);
      this.axAgent1.TabIndex = 7;
      // 
      // cmdStop
      // 
      this.cmdStop.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdStop.Location = new System.Drawing.Point(24848);
      this.cmdStop.Name = "cmdStop";
      this.cmdStop.Size = new System.Drawing.Size(7220);
      this.cmdStop.TabIndex = 6;
      this.cmdStop.Text = "Stop";
      this.cmdStop.Click += new System.EventHandler(this.cmdStop_Click);
      // 
      // cmdPlay
      // 
      this.cmdPlay.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdPlay.Location = new System.Drawing.Point(24824);
      this.cmdPlay.Name = "cmdPlay";
      this.cmdPlay.Size = new System.Drawing.Size(7220);
      this.cmdPlay.TabIndex = 5;
      this.cmdPlay.Text = "Play";
      this.cmdPlay.Click += new System.EventHandler(this.cmdPlay_Click);
      // 
      // lstAnimations
      // 
      this.lstAnimations.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom
        | System.Windows.Forms.AnchorStyles.Left);
      this.lstAnimations.IntegralHeight = false;
      this.lstAnimations.Location = new System.Drawing.Point(822);
      this.lstAnimations.Name = "lstAnimations";
      this.lstAnimations.Size = new System.Drawing.Size(232109);
      this.lstAnimations.TabIndex = 4;
      // 
      // AgentTryout
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(400366);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.cmdClose,
                                      this.GroupBox3,
                                      this.GroupBox2,
                                      this.GroupBox1});
      this.Name = "AgentTryout";
      this.Text = "AgentTryout";
      this.Load += new System.EventHandler(this.AgentTryout_Load);
      this.GroupBox3.ResumeLayout(false);
      this.GroupBox2.ResumeLayout(false);
      this.GroupBox1.ResumeLayout(false);
      ((System.ComponentModel.ISupportInitialize)(this.axAgent1)).EndInit();
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new AgentTryout());
    }

    private AgentController controller;

    private void AgentTryout_Load(object sender, System.EventArgs e)
    {
      controller = new AgentController(axAgent1, "Genie");
      
      lstAnimations.DataSource=controller.GetAnimations();
      
      controller.Show();
    }

    private void cmdPlay_Click(object sender, System.EventArgs e)
    {
      controller.Animate(lstAnimations.Text);
    }

    private void cmdStop_Click(object sender, System.EventArgs e)
    {
      controller.StopAll();
    }

    private void cmdSpeak_Click(object sender, System.EventArgs e)
    {
      controller.Speak(txtSpeak.Text);
    }

    private void cmdMove_Click(object sender, System.EventArgs e)
    {
      controller.MoveTo(short.Parse(txtX.Text)short.Parse(txtY.Text));
    }

    private void cmdClose_Click(object sender, System.EventArgs e)
    {
      this.Close();
    }
  }
}


//================================================================
//================================================================

using System;
using AxAgentObjects;
using System.Collections;

namespace AgentTryout
{
  public class AgentController
  {
    // Agent variable.
    private AgentObjects.IAgentCtlCharacterEx agentChar;

    // Name of the initialized character.
    private string characterName;

    // Balloon constants
    private const short BalloonOn = 1;
    private const short SizeToText = 2;
    private const short AutoHide = 4;
    private const short AutoPace = 8;

    public AgentController(AxAgentObjects.AxAgent agentHost, 
      string character)
    {
      agentHost.Characters.Load(character, null);
      agentChar = agentHost.Characters[character];

      characterName = character;

      // You could put your own options in this menu, if desired.
      agentChar.AutoPopupMenu = false;

      // Set balloon style.
      agentChar.Balloon.Style = agentChar.Balloon.Style | BalloonOn;
      agentChar.Balloon.Style = agentChar.Balloon.Style | SizeToText;
      agentChar.Balloon.Style = agentChar.Balloon.Style | AutoHide;
      //agentChar.Balloon.Style = agentChar.Balloon.Style & !(AutoPace);
    }

    public void Dispose()
    {
      if (agentChar.Visible)
      {
        agentChar.StopAll(null);
        agentChar.Hide(null);
      }
    }

    public void Show()
    {
      agentChar.Show(null);
    }

    public void Hide()
    {
      agentChar.Hide(null);
    }

    public void StopAll()
    {
      agentChar.StopAll(null);
    }

    public void Speak(string text)
    {
      agentChar.StopAll(null);
      agentChar.Speak(text, "");
    }

    public void Think(string text)
    {
      agentChar.StopAll(null);
      agentChar.Think(text);
    }

    public void Animate(string animation)
    {
      agentChar.StopAll(null);
      agentChar.Play(animation);
    }

    public void MoveTo(short x, short y)
    {
      agentChar.MoveTo(x, y, null);
    }

    public void GestureAt(short x, short y)
    {
      agentChar.GestureAt(x, y);
    }

    public Array GetAnimations()
    {
      ArrayList list = new ArrayList();
      foreach (string animation in agentChar.AnimationNames)
      {
        list.Add(animation);
      }
      return list.ToArray(typeof(string));
    }

    // Tests if the agent is visible.
    // If the agent is not visible it will be shown.
    private bool IsAgentVisible()
    {
      if (agentChar.Visible)
      {
        return true;
      }
      else
      {
        agentChar.Show(null);
          return false;
      }
    }
  }

}



           
       
AgentTryout.zip( 76 k)
Related examples in the same category
1.SMK Agent
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.