?
Solved

Nutty Custom-Shaped WinForm BG

Posted on 2006-11-10
3
Medium Priority
?
721 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
cybercrew earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-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!
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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