Come near VB.net (nine) Axagent animation form Implementation

Source: Internet
Author: User
Tags chr
Come near VB.net (nine) Axagent animation form Implementation

A few days ago to see some netizens to discuss msagent posts, in fact, in the vb.net to realize also very easy but always no one willing to try. Now I would like to introduce this very simple method, I hope to motivate more colleagues to join our team to promote each other (this time better than the "foreigner" a step earlier).
First add the control (do not know who said vb.net do not use the control, really more and more Xuan)




The second step is to draw the control on the form (which is not visible at run time, but he will appear on the form, not like the timer control appears below.)
The source code is as follows:


Imports System.ComponentModel

Imports System.Drawing

Imports system.winforms





Public Class Form1

Inherits System.WinForms.Form



' Specifies the animation data to use, where the Merlin.acs is a Santa Claus shape

Dim Genie as Agentobjects.iagentctlcharacterex

Const DataPath as String = "MERLIN." ACS "

' Unlike VB6, you don't have to download each of the 2M animation data, and all the animated files are built into the control.



Public Sub New ()

MyBase.New () ' invokes the New procedure of the parent class

Form1 = Me



' This is required by the Win Form Designer.

InitializeComponent ()

' Set the form without a title bar

Me.borderstyle = Formborderstyle.none

' Set the color of the form

Me.backcolor = Color.beige

' Todo:add any initialization on the InitializeComponent () call

Me.height = 100:button2. top = 20:button1. top = 20:button2. Text = "Exit program": Button1. Text = "Not Suitable for children"

' Load animation

AxAgent1.Characters.Load ("MERLIN", DataPath)

Genie = Axagent1.characters ("MERLIN")

Genie.languageid = &h409s

End Sub



' Form overrides dispose to clean up the component list.

Public Overrides Sub Dispose ()

Mybase.dispose () ' invokes the Dispose procedure of the parent class

Genie = Nothing ' Frees resources

Components. Dispose ()

End Sub









#Region "Windows Form Designer generated code"



' Required by the Windows Form Designer

Private Components as System.ComponentModel.Container

Private WithEvents Button2 as System.WinForms.Button

Private WithEvents Button1 as System.WinForms.Button

Private WithEvents AxAgent1 as Axagentobjects.axagent



Dim WithEvents Form1 as System.WinForms.Form



' Note:the following procedure is required by the Windows Form Designer

' It can be modified using the ' Windows Form Designer.

' Do not modify it using the ' Code Editor.

Private Sub InitializeComponent ()

Dim resources as System.Resources.ResourceManager = New System.Resources.ResourceManager (GetType (FORM1))



Me.components = New System.ComponentModel.Container ()

Me.button1 = New System.WinForms.Button ()

Me.button2 = New System.WinForms.Button ()

Me.axagent1 = New axagentobjects.axagent ()



Axagent1.begininit ()



' @design me.trayheight = 0

' @design Me.traylargeicon = False

' @design Me.trayautoarrange = True

Button1.location = New System.Drawing.Point (32, 8)

Button1.size = New System.Drawing.Size (80, 32)

Button1.tabindex = 1

Button1.Text = "Button1"



Button2.location = New System.Drawing.Point (120, 8)

Button2.size = New System.Drawing.Size (80, 32)

Button2.tabindex = 2

Button2.text = "Button2"



Axagent1.size = New System.Drawing.Size (56, 40)

Axagent1.ocxstate = CType (resources. GetObject ("Axagent1.ocxstate"), System.WinForms.AxHost.State)

Axagent1.tabindex = 0

Axagent1.location = New System.Drawing.Point (216, 32)

Me.Text = "Form1"

Me.autoscalebasesize = New System.Drawing.Size (6, 14)



ME.CONTROLS.ADD (Button2)

ME.CONTROLS.ADD (Button1)

ME.CONTROLS.ADD (AXAGENT1)



Axagent1.endinit ()

End Sub



#End Region



Protected Sub button2_click (ByVal sender as Object, ByVal e as System.EventArgs)

Me.dispose ()

End Sub



Protected Sub button1_click (ByVal sender as Object, ByVal e as System.EventArgs)

Genie. left = 500 ' Set the position of the agent

Genie.show () ' Use Show method to display agent

Genie. MoveTo (180) ' MoveTo method is to move the agent to a location, and if you add a timer, you can easily let him run on the screen

MessageBox. Show ("If you are mm, please press Ctrl+alt+del to close" & Chr & Chr () & "Do you really want to continue, until I don't move!" ")

Genie.speak ("Ni hao") ' makes a sound

MessageBox. Show ("Hello") dialog box, more parameters please see the previous related articles

Genie.speak ("WO SHI HAO KAN DI") ' makes a sound

MessageBox. Show ("I am good-looking") dialog box, more parameters please see previous related articles

Genie.speak ("NI SHI NAN KAN DI") ' makes a sound

MessageBox. Show ("You Are Ugly") dialog box, more parameters please see previous related articles

Genie.speak ("ZIA JIE MIMI") ' makes a sound

MessageBox. Show ("Goodbye MM") dialog box, more parameters please see previous related articles

Genie. Play ("wave") ' wave to greet

' mm Please do not be angry

' It's a little joke, if you want to really read Chinese, use the following

' Genie.speak ("cnstring", Cnstring.wav) ' Here's cnstring is the Chinese voice file

Genie. Hide () ' Hides the agent using the Hide method

End Sub

Private Sub Form1_mousedown (ByVal eventsender as Object, ByVal e as System.WinForms.MouseEventArgs)

' The Drop-down list in the form in the MouseDown event is not found, write one yourself, plus (ByVal eventsender as Object, ByVal e as System.WinForms.MouseEventArgs)

' The following code enables a form to drag

Me.capture () = False ' release mouse capture, equivalent to API ReleaseCapture ()

Me.sendmessage (&ha1s, 2, 0) ' Well, this is which SendMessage API, but the first handle parameter is no longer used.

End Sub

Protected Sub Form1_Click (ByVal sender as Object, ByVal e as System.EventArgs)

End Sub

End Class



This program if you want to run on another system, be sure to create the installer (of course, to upgrade the system components and install the SDK), please refer to the previous articles, because the need to support data, VB. NET differs from VB6 in that the installed support components are typically in the current directory, not in the system directory.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.