Solved

Nutty Custom-Shaped WinForm BG

Posted on 2006-11-10
3
700 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

816 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

10 Experts available now in Live!

Get 1:1 Help Now