Watermark Picturebox

I have a picture box that I want to use as a watermark on the form anchored to the bottom right hand corner of the form.  When I resize the form, the picturebox covers the other controls on the form.

How can I make the other controls on the form show transparently throught the picturebox???


thanks in advance
ramrocketAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
You can change drawing code according to your needs. For example:

       private void Form1_Load(object sender, EventArgs e)
        {
            bmp = new Bitmap("C:\\sample.bmp");

            this.SetStyle(
                ControlStyles.ResizeRedraw,
                true);

            this.UpdateStyles();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Rectangle rect = new Rectangle(this.ClientRectangle.Width - bmp.Width,
                this.ClientRectangle.Height - bmp.Height,
                bmp.Width, bmp.Height);

            e.Graphics.DrawImage(bmp, rect);
        }
0
 
AlexFMCommented:
Draw directly on the form in the Paint event handler. Instead of setting PictureBox.Image property, use Graphics.DrawImage method.
0
 
ramrocketAuthor Commented:
If I draw it directly to a location, the next time the form is resized will I have multiple overlapping image?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
AlexFMCommented:
If you want to draw background image, use the following code:

        Bitmap bmp;

        private void Form1_Load(object sender, EventArgs e)
        {
            bmp = new Bitmap("C:\\sample.bmp");        // replace this with your own bitmap

            this.SetStyle(
                ControlStyles.DoubleBuffer |
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.ResizeRedraw,
                true);

            this.UpdateStyles();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(bmp, this.ClientRectangle);
        }

When form is resized, image is redrawn completely covering all client area.
0
 
ramrocketAuthor Commented:
Alex, my image is only 200x200.  the clientrectangle parameter, is it possible for the image to be painted anchored to the bottom right hand corner?
0
 
ramrocketAuthor Commented:
I tried your code.  The image is stretched to the size of the form.  I need the image to remain in its original size but anchored to the bottom right hand corner
0
 
AlexFMCommented:
Try last post.
0
 
ramrocketAuthor Commented:
Alex, the image is now in the right place but the controls over the image still covers the image and does not show transparently.

I will increase the points.  thanks
0
 
ramrocketAuthor Commented:
The other controls are labels that I placed inside of a panel container.  This is the control I need to show through the watermark image.
0
 
AlexFMCommented:
What controls? I don't think that there is universal solution for all controls. For example, it is possible to make label transparent setting it's BackColor property to Transparent in the Form Designer of in the code:

this.label1.BackColor = System.Drawing.Color.Transparent;

Search information about every specific control type.
0
 
ramrocketAuthor Commented:
thanks, I got it work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.