首页 > 编程 > .NET > 正文

走近VB.Net(九) AxAgent动画窗体的实现

2024-07-10 13:01:28
字体:
来源:转载
供稿:网友
注册会员,创建你的web开发资料库,走近vb.net(九) axagent动画窗体的实现

前几天看到一些网友讨论msagent的贴子,其实在vb.net中实现也很容易却总是没有人肯动手一试。现在我就介绍一下这个很简单的方法,希望激励更多的同道加入我们的队伍,以能相互间促进(这次最好比“洋人”早一步)。
首先添加控件(不知道谁说vb.net不使用控件,真是越传越玄)




第二步将控件在窗体上画出来(这也是运行时不可见的,不过他会出现在窗体上,而不是象timer控件出现在下面。
源代码如下:


imports system.componentmodel

imports system.drawing

imports system.winforms





public class form1

inherits system.winforms.form



'指定要使用的动画数据,这里的merlin.acs是一个圣诞老人的造型

dim genie as agentobjects.iagentctlcharacterex

const datapath as string = "merlin.acs"

'与vb6不同的是你不需要下载每一个都有2m多的动画数据,在控件中已内置了所有的动画文件



public sub new()

mybase.new() '调用父类的new过程

form1 = me



'this call is required by the win form designer.

initializecomponent()

'设置窗体没有标题栏

me.borderstyle = formborderstyle.none

'设置窗体的色彩

me.backcolor = color.beige

'todo: add any initialization after the initializecomponent() call

me.height = 100 : button2.top = 20 : button1.top = 20 : button2.text = "退出程序" : button1.text = "少儿不宜"

'装载动画

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() '调用父类的dispose过程

genie = nothing '释放资源

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 '设定agent的位置

genie.show() '使用show方法显示agent

genie.moveto(12, 180) 'moveto方法是移动agent到一个位置,如果加上定时器,你可以很容易地让他在屏幕上乱跑

messagebox.show("如果你是mm,请按ctrl+alt+del关闭 " & chr(10) & chr(13) & "您真的要继续吗, 等到我不 动再说!")

genie.speak("ni hao") '发出声音

messagebox.show("你好") '对话框,更多的参数请看以前的相关文章

genie.speak("wo shi hao kan di") '发出声音

messagebox.show("我是好看的") '对话框,更多的参数请看以前的相关文章

genie.speak("ni shi nan kan di") '发出声音

messagebox.show("你是难看的") '对话框,更多的参数请看以前的相关文章

genie.speak("zia jie mimi ") '发出声音

messagebox.show("再见 mm") '对话框,更多的参数请看以前的相关文章

genie.play("wave") '挥手致意

'众mm请勿生气

'上面是开一个小玩笑,如果要真正的读中文,就用下面的

'genie.speak("cnstring ",cnstring.wav) '这里的cnstring就是中文的语音文件

genie.hide() '使用hide方法隐藏agent

end sub

private sub form1_mousedown(byval eventsender as object, byval e as system.winforms.mouseeventargs)

'mousedown的事件中窗体中的下拉列表是找不到的,自己写一个吧,加上(byval eventsender as object, byval e as system.winforms.mouseeventargs)即可

'下面的代码使窗体可以拖动

me.capture() = false '释放鼠标捕获,等同于api的releasecapture()

me.sendmessage(&ha1s, 2, 0) '唔,这个就是哪个sendmessage的api了,只是第一个句柄参数不再用了。

end sub

protected sub form1_click(byval sender as object, byval e as system.eventargs)

end sub

end class



这个程序如果要在别的系统上运行,一定要制作安装程序(当然先要升级系统组件并安装sdk),请参考前面的几篇文章,因为需要支持数据,vb.net与vb6不同的是安装的支持组件一般会在当前目录,而不是在系统目录。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表