HighTechTalks DotNet Forums  

Setting PictureBox BackColor at runtime

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss Setting PictureBox BackColor at runtime in the Dotnet Framework (WinForms Controls) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Eric
 
Posts: n/a

Default Setting PictureBox BackColor at runtime - 11-11-2007 , 07:20 PM






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



Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Setting PictureBox BackColor at runtime - 12-13-2007 , 09:40 AM






It works just fine for me.
See the code after my 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().Assemb ly.GetManifestResourceStream("pbbackcolor.Bitmap1. bmp"));
img.MakeTransparent(Color.Magenta);

this.pictureBox1.Image = img;


}





Eric wrote:
Quote:
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.