Solved

Nutty Custom-Shaped WinForm BG

Posted on 2006-11-10
3
687 Views
Last Modified: 2010-05-18
I have a lovely WinForm that uses a custom shape.  The bitmap used in its BackgroundImage property has a transparent color, and the WinForm has that TransparencyKey property and I have all that set correctly.  Works great.

But what I really want my form to be able to do is to set its own BackgroundImage property dynamically, using an on-board ImageList control.

Problem is, when I dynamically have the form set its own background image, I lose that wonderful transparency.  Suddenly, the entire image that I use to create my custom-shaped form is visible, in all its ugliness.  The color that should be transparent (white) is suddenly opaque (black).  All because rather than setting my form's BackgroundImage property at design-time and compiling it in, I'm trying to dig it out of an ImageList.

Any ideas on how I can get dynamic background images to work here?  I don't want to load them from a subfolder on the fly or anything kooky like that.  The images need to be on-board.

Thanks.
0
Comment
Question by:bryker
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
cybercrew earned 250 total points
ID: 17920286
Have you tried embedding the images in a resource file?  One other thing you might try is calling this.Refresh() after changing the background.

1.  In your Solution Explorer expand the Properties folder.
2. Double click on  Resources.resx
3. In Resource Designer click on  Add Resource.
4. The select "Add Existing File"
5. Locate your image files and them.
6. For each image check the properties window to make sure they are embedded into the resource file and not linked.
7.  You can now access your images by typing <your project namespace>.Properties.Resources.<name of Image>

Example:  (Blue_Lace_16 and Feather_Texture are the names of image files embedded in my Resources.resx file)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ResourceFiles
{
    public partial class Form1 : Form
    {
        private bool toggle = false;
        public Form1()
        {
            InitializeComponent();
           
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.BackgroundImage = ResourceFiles.Properties.Resources.Blue_Lace_16;
           
        }


        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            if (toggle == false)
            {
                toggle = true;
                this.BackgroundImage = ResourceFiles.Properties.Resources.FeatherTexture;
            }
            else{
                toggle = false;
                this.BackgroundImage = ResourceFiles.Properties.Resources.Blue_Lace_16;}
            this.Refresh();
        }
    }
}
0
 

Author Comment

by:bryker
ID: 17961349
Sorry, Cyber.  I really am going to get to this in the next few days, then I'll be able to grade your suggestion.  Thanks for your patience.
0
 

Author Comment

by:bryker
ID: 18036946
Okay, Cyber, I haven't gotten around to testing this, but I can't leave you hanging any longer in good conscience.  I'm assuming it's going to work for me.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now