【asp精品源码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。
网学会员整理了asp精品源码-C#自定义控件七水波纹 - 其它资料的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
C自定义控件七水波纹效果图:这个是网上搞来的,本人修改了一小点代码,不过用 C写这个效率有点低,还是汇编写的最好。
贴出全部代码://控件名:myWaterWave//作者:刘典武//时间:2011-06-09using Systemusing System.Collections.Genericusing System.ComponentModelusing System.Drawingusing System.Datausing System.Textusing System.Windows.Formsusing System.Runtime.InteropServicesusing System.Drawing.Imagingnamespace myControl public struct DropData public int x public int y public int radius public int height public partial class myWaterWave : UserControl public myWaterWave InitializeComponent this.SetStyleControlStyles.AllPaintingInWmPaint true this.SetStyleControlStyles.DoubleBuffer true this.SetStyleControlStyles.ResizeRedraw true this.SetStyleControlStyles.Selectable true this.SetStyleControlStyles.SupportsTransparentBackColor true this.SetStyleControlStyles.UserPaint true myWaterTimer new Timer myWaterTimer.Interval 50 myWaterTimer.Tick new EventHandlermyWaterTimer_Tick myDropsTimer new Timer myDropsTimer.Interval 50000 myDropsTimer.Tick new EventHandlermyDropsTimer_Tick private void myDropsTimer_Tickobject sender EventArgs e try this.myDropsTimer.Enabled false int _percent int0.005 this.Width this.Height int _dropsNumber r.Next_percent int _drop 0 for int i 0 i _dropsNumber i _drop r.Nextdrops.Length DropWaterdrops_drop.x drops_drop.ydrops_drop.radius drops_drop.height this.myDropsTimer.Interval r.Next15 _percent 1 this.myDropsTimer.Enabled true catch private void myWaterTimer_Tickobject sender EventArgs e try if fastImage.IsLocked return this.myWaterTimer.Stop PaintWater this.myWaterTimer.Start catch private static int bitmapWidth 0private static int bitmapHeight 0private static int bits 4private static DropData dropsprivate FastBitmap fastImage nullprivate FastBitmap originalImage nullpublic int currentHeightBuffer 0public int newHeightBuffer 0private byte bitmapOriginalBytesprivate Random r new Randomprivate static int waveHeightbool isLoaded falseprivate Image imageprivate bool autoprivate int numberprivate Timer myWaterTimer myDropsTimer////// 绘画的图片///public Image Image get return image set image value ////// 自动产生///public bool Auto get return auto set auto value /// /// 源点数 /// public int Number get return number set number value public void load try isLoaded true this.Width image.Width this.Height image.Height bitmapWidth image.Width bitmapHeight image.Height waveHeight new intbitmapWidth for int i 0 i bitmapWidth i waveHeighti new intbitmapHeight for int j 0 j bitmapHeight j waveHeightij new int2 CreateBitmap if auto CreateWaterDrops this.myWaterTimer.Enabled true this.myDropsTimer.Interval 50 this.myDropsTimer.Enabled true else this.MouseMove newMouseEventHandlermyWaterWave_MouseMove catch private void CreateBitmap originalImage new FastBitmapBitmapimage.Clone bits originalImage.LockBits fastImage new FastBitmapBitmapimage.Clone bits bitmapOriginalBytes new bytebits fastImage.Width fastImage.Height fastImage.LockBits Mars