Alex
Alex

Reputation: 11137

problem with resources reading

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?

Upvotes: 0

Views: 220

Answers (1)

pinkfloydx33
pinkfloydx33

Reputation: 12739

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;
        }
    }

Upvotes: 1

Related Questions