Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2007

Tip: Looking for answers? Try searching our database.

Setting PictureBox BackColor at runtime

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric - 12 Nov 2007 00:20 GMT
I have a PictureBox Control on  user control.  The image the picturebox
contains is transparent.  At design time I can set the BackColor property to
anything I want and it behaves exactly as expected and looks great .  When I
try to change the backColor property at runtime it does not change it
remains at whatever I set it to at design time.

Assistance appreciated.

TIA
Bob Powell [MVP] - 13 Dec 2007 14:40 GMT
It works just fine for me.
See the code after my signature...
Signature

Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
--------------------------------------

    public partial class Form1 : Form
    {
        Timer t;
        public Form1()
        {
            InitializeComponent();

            t = new Timer();
            t.Interval = 1000;
            t.Tick += new EventHandler(t_Tick);
            t.Enabled = true;
        }

        Random r = new Random();

        void t_Tick(object sender, EventArgs e)
        {
            this.pictureBox1.BackColor = Color.FromArgb(r.Next(255),
r.Next(255), r.Next(255));
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Bitmap
img=(Bitmap)Image.FromStream(this.GetType().Assembly.GetManifestResourceStream("pbbackcolor.Bitmap1.bmp"));
            img.MakeTransparent(Color.Magenta);

            this.pictureBox1.Image = img;

        }

> I have a PictureBox Control on  user control.  The image the picturebox
> contains is transparent.  At design time I can set the BackColor property to
[quoted text clipped - 5 lines]
>
> TIA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.