Solved

Watermark Picturebox

Posted on 2006-06-26
11
966 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:ramrocket
  • 6
  • 5
11 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16983868
Draw directly on the form in the Paint event handler. Instead of setting PictureBox.Image property, use Graphics.DrawImage method.
0
 

Author Comment

by:ramrocket
ID: 16983940
If I draw it directly to a location, the next time the form is resized will I have multiple overlapping image?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16984015
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:ramrocket
ID: 16984089
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 150 total points
ID: 16984181
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
 

Author Comment

by:ramrocket
ID: 16984189
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 16984244
Try last post.
0
 

Author Comment

by:ramrocket
ID: 16984265
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
 

Author Comment

by:ramrocket
ID: 16984303
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 16984325
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
 

Author Comment

by:ramrocket
ID: 16984369
thanks, I got it work.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How useful is the free version of Selenium? 3 35
Simple Injector with Web Service 4 41
SqlDataBase 7 48
application restarter  - for an exe that hangs 9 27
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question