tags:

views:

11

answers:

1

Hello !

i have a user-control designed as a button . The problem is that i can't display an image as the background.

public partial class inout_buton : UserControl
    {
        Bitmap bmp;
        public inout_buton()
        {

            InitializeComponent();

            try
            {
                Stream s = this.GetType().Assembly.GetManifestResourceStream("Network_Remote_Monitoring.but_verde.png");
                bmp = new Bitmap(s);
                s.Close();
            }
            catch
            {
                MessageBox.Show("it's bad");
            }


            this.BackgroundImage = bmp;
        }
    }

In this example, Network_Remote_Monitoring is my namespaceand but_verde.png is my desired background. The pop-up MessageBox always appears => not executing the try statements.

Can you find the problem?

+1  A: 
public partial class inout_buton : UserControl
    {
        Bitmap bmp;
        public inout_buton()
        {

            InitializeComponent();

            try
            {
                bmp = new Bitmap(Network_Remote_Monitoring.Properties.Resources.but_verde);
             }
            catch
            {
                MessageBox.Show("it's bad");
            }


            this.BackgroundImage = bmp;
        }
    }
pinkfloydx33
'System.Drawing.Bitmap' does not contain a definition for 'png' and no extension method 'png' accepting a first argument of type 'System.Drawing.Bitmap' could be found (are you missing a using directive or an assembly reference?) .
Badescu Alexandru
must i convert the image to .jpg?
Badescu Alexandru
nevermind, i removed the .png and it worked just fine ! Thanks
Badescu Alexandru
Ahh, sorry. I was assuming that the resource was named with the .png. (Not the file name, but the resource name itself)
pinkfloydx33