Click here to Skip to main content
Click here to Skip to main content

A C# water effect picture control

By , 29 Aug 2002
 

Cool eh ?

Intro

This control is a C# implementation of the well known water effect. There are already two implementations of this algorithm on CodeProject: Really cool visual FX - a C++ variant - and a OpenGL Interactive water effect.

The algorithm itself is well described here and here.

How to use it

The control itself is derived from System.Windows.Forms.Panel. So all you have to do is to place a standard PictureBox control onto your form and change the type of this control to WaterEffectControl.

Then adjust the image source property as follows:

waterControl.ImageBitmap = ((System.Drawing.Bitmap)
               (resources.GetObject("waterControl.ImageBitmap")));

Now run the program, and move the mouse over the image while the left button is pressed. The effect is clearly better than the picture above shows.

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Christian Tratz
Web Developer
Germany Germany
Member
If you are not living on the edge you are wasting space Wink | ;)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberDavid Goebet11 Oct '12 - 22:19 
cool Big Grin | :-D
GeneralMy vote of 5memberatoi_powered8 Jul '12 - 2:21 
wow, just wow!
QuestionLicensememberDanieBeckett19 Sep '11 - 23:37 
Great Control! But what license are you using? I need something cimilar to the CPOL license. Would it be possible to use this in a internally distributed (only distributed within my company) commercial application?
GeneralNeed HelpmemberJames Noah Black17 Sep '11 - 20:09 
Error in Dragging the WaterEffectControl from the toolbox.
Any thoughts on how to fix this?
GeneralThis water effect controlmemberJohn Chaffins17 Dec '09 - 7:05 
Sorry, but my knowledge of how C# works is minimal. I have struggled for days working to put this wave effect onto a picture on a tab control. In fact, I can't even get it to work on a new WinForm. When I drag the Toolbox item "WaterEffectControl" onto a form, I get "Object reference not set to an instance of an object".
 
For example, in the exact same project that is provided, I have started a new Form1 project, added an identical class to the project "WaterEffectPictureBox.cs", and then dragged the Toolbox control onto either a picturebox or a panel or a plain form1. The error message always appears.
 
My usual experience with Toolbox controls is that all I have to do is drag-and-drop and then set properties and events.
 
I realize the instructions say: "The control itself is derived from System.Windows.Forms.Panel. So all you have to do is to place a standard PictureBox control onto your form and change the type of this control to WaterEffectControl." <=== I don't understand how to do that.
 
Can someone please help provide a "drag-and-drop" Toolbox item?
GeneralF U C K I N G C O O L!!!membericcb101316 Jul '09 - 20:10 
C O O L!!!
THANKS
Generalhi i want to draw an drawing like a rugmembercuteAisha29 Aug '07 - 21:45 
hi
i want to draw an drawing like a rug
im using the following code
it working but only on Window form
i m using same code on panel but there is no results
any idea................!
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace what_it_is
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
rnd = new System.Random();
myPen = new Pen(Color.Blue);
}
private Bitmap DrawingArea;
private System.Random rnd;
private Pen myPen;
private void Form1_Load(object sender, EventArgs e)
{
DrawingArea = new Bitmap(
this.Size.Width,
this.Size.Height,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
InitializeDrawingArea();
}
 
private void btnLine_Click(object sender, EventArgs e)
{
Graphics oGraphics;
oGraphics = Graphics.FromImage(DrawingArea);
 
myPen.Color = Color.Blue;
 
for (int x = 1; x < 50; x++)
{
oGraphics.DrawLine(
myPen,
(int)rnd.Next(0, this.Width),
(int)rnd.Next(0, this.Height),
(int)rnd.Next(0, this.Width),
(int)rnd.Next(0, this.Height));
}
oGraphics.Dispose();
 
this.Invalidate();
}
 
private void btnCircle_Click(object sender, EventArgs e)
{
Graphics oGraphics;
oGraphics = Graphics.FromImage(DrawingArea);
 
// get a radius for circle - up to 1/2 the width of form
int radius = rnd.Next(0, (this.Width / 2));
 
for (int x = 1; x < 50; x++)
{
myPen.Color = Color.FromArgb(
(rnd.Next(0, 255)),
(rnd.Next(0, 255)),
(rnd.Next(0, 255)));
 
oGraphics.DrawEllipse(
myPen,
rnd.Next(0, this.Width),
rnd.Next(0, this.Height),
radius, radius);
}
oGraphics.Dispose();
 
this.Invalidate();
}
private void InitializeDrawingArea()
{
Graphics oGraphics;
oGraphics = Graphics.FromImage(DrawingArea);
 
myPen.Color = Color.AliceBlue;
 
for (int x = 0; x < this.Width; x++)
{
oGraphics.DrawLine(myPen, x, 0, x, this.Height);
}
oGraphics.Dispose();
 
this.Invalidate();
}
private void btnOK_Click(object sender, EventArgs e)
{

Application.Exit();
}
private void Form1_Closed(object sender, System.EventArgs e)
{
DrawingArea.Dispose();
}
 
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics oGraphics;
 
oGraphics = e.Graphics;
 
oGraphics.DrawImage(DrawingArea,
0, 0,
DrawingArea.Width,
DrawingArea.Height);
oGraphics.Dispose();
}
 
private void button1_Click(object sender, EventArgs e)
{
UserControl1 ctrl = new UserControl1();
this.Controls.Add(ctrl);
}
 

 
private void panel1_Paint_1(object sender, PaintEventArgs e)
{
 
}
}
}
Generalrunning slowmemberstjds7 Jan '07 - 12:57 
I was able to change the picture of control but when I added the new bmp file (which I saved as being very small) the control seems to take a long time. How was the included picture saved?
 
stjdsD'Oh! | :doh:
GeneralBetter resultmemberSaied Javadi8 Jul '06 - 3:58 
Hi,
Thanks for your goold control.
When i compare the results of your Water Effect with another on in http://www.durius.com/104.asp
i can see the better simulation in second program. one of differences is when i clicked on sample picture
it start with big wave instead small wave.
Thansk again.
QuestionWhy not a PictureBox?memberjeffreylreed19 May '04 - 5:49 
I am curious why you didn't use a PictureBox instead of a panel?
 
jr

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 30 Aug 2002
Article Copyright 2002 by Christian Tratz
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid