Apply Agent technology in VB.NET

xiaoxiao2021-03-06  116

In Office Help file, Kingsoft Internet Security, Rising anti-virus software has a function of assistant, used to make help information or construction. This feature can be easily implemented using Microsoft Agent Control 2.0 components in Visual Basic .NET.

First, add Agent components

Start Visual Studio .Net2003, create a new Visual Basic .NET should be program. Right-click the toolbox in Visual Basic .NET, select "Add / Transfer" (i) ... "or select the Tool menu in the toolbar, select Add / Remove Toolbox (x) ..." In the "Custom Toolbox" pop-up, select the COM page, select the "Microsoft Agent Control 2.0" component, as shown in Figure 1 below:

Figure 1: Add agent component

After clicking "OK", a "Microsoft Agent Control 2.0" component will be added to the toolbox, such as

Figure 2 shows:

Figure 2: Adding agent component successfully

Second, the design program interface

Add three Button components to make the user an action assistant's different features.

A ComboBox component allows the user to select the action of the assistant.

A TextBox component allows the user to enter the text of the assistant reading.

An Agent component

Two label components

Running Interface Figure 3 shows:

Figure 3: Run interface

Third, write code

1, load assistant

To use the agent, you must first load the assistant into the program, you can use the AxAgent1.Characters.Load method to load the assistant, and the Assistant ID gives the prior definition assistant type Objagent, followed by Objagent Operation Assistant, the code is as follows:

'Define Assistant Types

Dim Objagent As AgentObjects.iagentctlcharacterex

Private sub button1_click_1 (byval sender as system.Object, byval e as system.eventargs) Handles Button1.click

Try

'Loading assistant

Axagent1.Characters.Load ("Merlin", "C: /Winnt/Msagent/Chars/merlin.acs")

Objagent = axAgent1.characters ("Merlin")

'Show assistant

Objagent.show ()

Button2.enabled = TRUE

Button3.enabled = TRUE

Label1.enabled = TRUE

Label2.enabled = TRUE

ComboBox1.enabled = TRUE

TextBox1.enabled = true

Button1.enabled = false

Catch exception

Messagebox.show (ex.Message)

END TRY

End Sub

Press the F5 test program to load and display the assistant, Figure 4 is shown:

Figure 4: Load and display the assistant

2. Implement assistant action

After loading the assistant, you can let the assistant execute the specified action.

It mainly performs an assistant animation through the Play method, and the Play method has a parameter animation, indicating the specified action. The AxAgent component provides dozens of the assistant action, which gives some common assistant actions:

Parameter action

RESEPOSE restores the initial state

Acknowledge recognizes

LOOKDOWN

Sad sadness

Alert warning

LOOKDOWNBLINK looks down in blinking Search

Announce declaration

Lookup looks up

STARTLISTENING starts listening

Blink blink

LOOKUPBLINK looks down

Stoplistening stops listening

Confused confused

Lookleft to the left

Suggest advice

Congratulate congratulations

Lookleftblink wink to the left

Surprised surprise

Decline refused

LOOKRIGHT looks right

Think thinking

DONTRECognize does not recognize

LOOKRIGHTBLINK 眨 眨

Wave waves

Explain explanation

MoveDown moves down

Write writing

GestureDown downwards

Moveup moves upward

Processing calculation

GESTUREUP upwards

Moveright moves to the right

Reading reading

GestureLeft to the left

Moveleft moves left

Searching looking for

Gestureright to right.

Pleased happy

Writing writing

GetAttrtion gets note

Read reading

Greet greetings

We choose several commonly used action parameters

Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load

ComboBox1.Items.Add ("Show")

ComboBox1.Items.Add ("Greetings")

ComboBoX1.Items.Add ("Hidden")

ComboBoX1.Items.Add ("Mobile")

ComboBox1.Items.Add ("Reading")

ComboBoX1.Items.Add ("thinking")

ComboBoX1.Items.Add (Read ")

ComboBox1.Items.Add ("Writing")

ComboBox1.Items.Add ("Happy")

ComboBox1.Items.Add ("Congratulations")

ComboBoX1.SelectedIndIndex = 0

End Sub

'Different from users, perform different action

Private sub Button2_click (byvalgend, byval e as system.eventargs) Handles Button2.click

Try

Select Case ComboBox1.SelectedIndex

Case 0

Objagent.show ()

Case 1

Objagent.play ("Greet")

Case 2

Objagent.hide ()

Case 3

Objagent.moveto (Me.Width, Me.Height)

Case 4

If TextBox1.Text <> "" "

Objagent.Speak (TextBox1.text)

END IF

Case 5

If TextBox1.Text <> "" "

Objagent.think (TextBox1.text)

END IF

Case 6

Objagent.play ("Reading")

Case 7

Objagent.play ("Write")

Case 8

Objagent.play ("pleased")

Case 9

Objagent.play ("CONGRATULATE")

End SELECT

Catch exception

Messagebox.show (ex.Message)

END TRY

End Sub

The operation is shown in Figure 5:

Figure 5: Hand reading action

3, uninstall assistant

You can use the AxAgent1.Characters.unload method to uninstall the assistant, implement the code as follows:

Private sub button3_click (byval sender as system.object, byval e as system.eventargs) Handles Button3.click

Try

Axagent1.Characters.unload ("Merlin")

Button2.enabled = false

Button3.enabled = false

Label1.enabled = FALSE

Label2.enabled = false

ComboBox1.enabled = false

TextBox1.enabled = false

Button1.enabled = TRUE

Catch exception

Messagebox.show (ex.Message)

END TRY

End Sub

转载请注明原文地址:https://www.9cbs.com/read-101874.html

New Post(0)