请教有写WinForm控件经验的朋友.

moonewxp 2005-04-11 03:40:36
.NET控件库里没有Animate控件,我要升级一个原来VB6的程序到VB.NET,想把其中用到的所有VB6的ActiveX控件都升级到.NET的控件,可是惟独没有Animate,所以我就想自己写一个.NET的Animate控件.
我想ComCtl32.dll里包含了windows标准控件库(包含Animate),那些.NET的标准控件(比如TreeView等等)应该就是对这个标准控件的一个包装而已.所以我想自己包装一个Animate.但我没有找到如何从System.Window.Forms.Form继承写自定义WinForm控件的标准方法,该重写或实现哪些方法.
下面我贴自己写的这个控件,现在可以工作但还有一些问题,请高手帮忙看看.
主要问题是
1)Style ACS_TRANSPARENT没有起到应有作用.(如果设置ACS_TRANSPARENT,动画的背景色应该和父窗口的背景色一致,可是现在的问题是设置ACS_TRANSPARENT,动画背景变为白色)
MSDN对ACS_TRANSPARENT的解释:Allows you to match an animation's background color to that of the underlying window, creating a "transparent" background. The control will send a WM_CTLCOLORSTATIC message to its parent. Use SetBkColor to set the background color for the device context to an appropriate value. The control interprets the upper-left pixel of the first frame as the animation's default background color. It will remap all pixels with that color to the value you supplied in response to WM_CTLCOLORSTATIC.

2)包含控件的窗口最小化,然后返回后,要过好几秒动画才能恢复


代码如下:
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Text
Namespace CEInet.Windows.Forms
Public Class Animation
Inherits Control
'Animation ClassName
Private Const CNAnimate As String = "SysAnimate32"

Private Const WM_USER As Integer = &H400
'Animation Message
Private Const ACM_PLAY As Integer = WM_USER + 101
Private Const ACM_STOP As Integer = WM_USER + 102
Private Const ACM_OPEN As Integer = WM_USER + 103

'Animation Control Styles
Private Const ACS_AUTOPLAY As Integer = &H4
Private Const ACS_CENTER As Integer = &H1
Private Const ACS_TRANSPARENT As Integer = &H2


Private _bAutoPlay As Boolean = False
Private _bCenter As Boolean = False
Private _iBackStyle As Integer = 0

Public Property AutoPlay() As Boolean
Get
Return _bAutoPlay
End Get
Set(ByVal Value As Boolean)
_bAutoPlay = Value
End Set
End Property
Public Property Center() As Boolean
Get
Return _bCenter
End Get
Set(ByVal Value As Boolean)
_bCenter = Value
End Set
End Property

Public Property BackStyle() As Integer
Get
Return _iBackStyle
End Get
Set(ByVal Value As Integer)
_iBackStyle = Value
End Set
End Property

Public Sub New()
MyBase.New()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then

End If
MyBase.Dispose(disposing)
End Sub

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim p As System.Windows.Forms.CreateParams
p = MyBase.CreateParams()
p.ClassName = Me.CNAnimate
If AutoPlay Then p.Style = p.Style Or ACS_AUTOPLAY
If Center Then p.Style = p.Style Or ACS_CENTER
If BackStyle = 0 Then p.Style = p.Style Or ACS_TRANSPARENT
Return p
End Get
End Property
Public Sub Open(ByVal fileName As String)
Dim sb As New StringBuilder(fileName)
WinAPI.SendMessage(Me.Handle, ACM_OPEN, 0, sb)
End Sub
Public Sub Play(Optional ByVal Repeat As Short = -1, Optional ByVal Start As Short = 0, Optional ByVal [End] As Short = -1)
WinAPI.SendMessage(Me.Handle, ACM_PLAY, Repeat, Start Or [End] << 16)
End Sub
Public Sub [Stop]()
WinAPI.SendMessage(Me.Handle, ACM_STOP, 0, 0)
End Sub

End Class
End Namespace
...全文
369 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
moonewxp 2005-05-11
  • 打赏
  • 举报
回复
结贴
brando_beat 2005-04-28
  • 打赏
  • 举报
回复
up
moonewxp 2005-04-26
  • 打赏
  • 举报
回复
4楼说ComCtl32.dll添加引用后再写,ComCtl32.dll是传统意义的动态链接库,.NET P/I invoke又不用也不能引用呀.
10楼的贴的例子都是gif动画.我要做的是对windows标准动画控件(avi).
没办法,我只好用ILdasm看了,不过看IL代码还真是挺累...
tseyeunwah 2005-04-25
  • 打赏
  • 举报
回复
up
sgd 2005-04-25
  • 打赏
  • 举报
回复
up
timiil 2005-04-23
  • 打赏
  • 举报
回复
up
Bob 2005-04-20
  • 打赏
  • 举报
回复
CodeProject 里面有一些现成的 Animation Control:

http://www.codeproject.com/netcf/compframe3.asp
http://www.codeproject.com/cs/miscctrl/CsCounterArticle1.asp
http://www.codeproject.com/cs/miscctrl/walkingrabbit.asp

还有这个很搞笑:
http://www.codeproject.com/csharp/tweencs.asp
nytony 2005-04-19
  • 打赏
  • 举报
回复
gz
xubinhui 2005-04-16
  • 打赏
  • 举报
回复
路过
True1024 2005-04-14
  • 打赏
  • 举报
回复
学习,怎么这么多牛?
nytony 2005-04-13
  • 打赏
  • 举报
回复
楼上说得对
haoztao 2005-04-13
  • 打赏
  • 举报
回复
ComCtl32.dll添加引用后再写
niunj 2005-04-13
  • 打赏
  • 举报
回复
路过 正好学习一下.
顺便说下
楼主的名字比较酷
wjcking 2005-04-12
  • 打赏
  • 举报
回复
学习
poleax81 2005-04-12
  • 打赏
  • 举报
回复
学习..........
jxzhang615 2005-04-11
  • 打赏
  • 举报
回复
帮顶

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧