【Asp.net精品源码栏目提醒】:网学会员为广大网友收集整理了,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 Marshal.CopyfastImage.Data.Scan0 bitmapOriginalBytes 0bitmapOriginalBytes.Length fastImage.Release private void DropWaterint x int y int radius int height long _distance int _x int _y Single _ratio _ratio SingleMath.PI / Singleradius for int i -radius i 5 _offX waveHeight_x - 1_ynewHeightBuffer -waveHeight_x 1_ynewHeightBuffer 3 _offY waveHeight_x_y - 1newHeightBuffer -waveHeight_x_y 1newHeightBuffer 3 if _offX 0 _offY 0 continue if _x _offX bitmapWidth - 1 _offX bitmapWidth -_x - 1 if _y _offY bitmapHeight - 1 _offY bitmapHeight -_y - 1 _bufferBitsbits _x _y bitmapWidth 0 bitmapOriginalBytesbits _x _offX _y _offY bitmapWidth 0 _bufferBitsbits _x _y bitmapWidth 1 bitmapOriginalBytesbits _x _offX _y _offY bitmapWidth 1 _bufferBitsbits _x _y bitmapWidth 2 bitmapOriginalBytesbits _x _offX _y _offY bitmapWidth 2 Marshal.Copy_bufferBits 0 fastImage.Data.Scan0_bufferBits.Length currentHeightBuffer newHeightBuffer this.Invalidate private void CreateWaterDrops int _dropX int _dropY int _dropRadius int _height int _percent int0.0015 this.Width this.Height drops new DropDatanumber for int i 0 i drops.Length i _dropX r.NextbitmapWidth _dropY r.NextbitmapHeight _height r.Next400 _dropRadius r.Next4 _percent if _dropRadius 4 _dropRadius 4 dropsi.x _dropX dropsi.y _dropY dropsi.radius _dropRadius dropsi.height _height private void myWaterWave_Paintobject sender PaintEventArgs e try if isLoaded fastImage.Release e.Graphics.DrawImagefastImage.Bitmap 0 0fastImage.Width fastImage.Height catch private void myWaterWave_MouseMoveobject sender MouseEventArgs e int dropX int dropY int dropRadius int height int percent int0.0015 this.Width this.Height drops new DropData1 dropX e.X dropY e.Y height r.Next400 dropRadius r.Next4 percent if dropRadius 4 dropRadius 4 drops0.x dropX drops0.y dropY drops0.radius dropRadius drops0.height height this.myWaterTimer.Enabled true this.myDropsTimer.Interval 50 this.myDropsTimer.Enabled true private void myWaterWave_MouseLeaveobject sender EventArgs e this.myDropsTimer.Enabled false public unsafe class FastBitmap public struct PixelData public byte blue public byte green public byte red public byte alphaBitmap Subjectint SubjectWidthBitmapData bitmapData nullByte pBase nullbool isLocked falseint _bits 0public FastBitmapBitmap SubjectBitmap int bits this.Subject SubjectBitmap _bits bits try //LockBits catch Exception ex throw ex public void Release try UnlockBits catch Exception ex throw ex public Bitmap Bitmap get return Subject public void SetPixelint X int Y Color Colour try PixelData p PixelAtX Y p-red Colour.R p
上一篇:
基于Asp. net 和JQquery 的课件下载系统
下一篇:
法律专业开题报告范文