469,627 Members | 1,092 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

picturebox transparency malfunction

EntryTeam
I'm writing turn based logic game, and transparency doesn't seen to work right:
screenshot

Person model is .GIF in picturebox, buildings are .GIF in pictureboxes, mainform background is .bmp file.

Model picbox and building picboxes both have
Expand|Select|Wrap|Line Numbers
  1. .BackColor = System.Drawing.Color.Transparent;
...set.

How do I get this working as it should be?
Oct 9 '09 #1
7 5048
tlhintoq
3,525 Expert 2GB
You don't. It is the nature of a picturebox backgroundcolor to show through to the background color of the control underneath it.

if you put a picturebox on a form whose background color is red, then your picturebox background color is red.

A Form's background color of transparent will work as you are expecting. So instead of making a bunch of pictureboxes on a form you can make a bunch of forms with no border and transparent background and a background image.

This is why it is good to do small-scale experiment to prove one's assumptions before doing the BIG part of the coding.
Oct 9 '09 #2
@tlhintoq
You mean real forms instead of pictureboxes? How's that?
Oct 9 '09 #3
Plater
7,872 Expert 4TB
@tlhintoq
Can you get away with using a panel instead of a Form?
Transparent forms has been a big mess (if you look through post history here in bytes, there's been a few long threads about getting it to work)
Oct 9 '09 #4
tlhintoq
3,525 Expert 2GB
A panel might work. I don't think I've tried for a purpose such as EntryTeam is doing.

Sounds like a good experiment.

EntryTeam: Give it a try. Instead of a bunch of picturebox controls, try it with a bunch of panel controls. They have nearly all the same properties such as 'Image', 'Backcolor', 'Location' etc. so it shouldn't be a huge issue.

If you are creating those pictureboxes programatically you just make a new panel instead of new picturebox
Expand|Select|Wrap|Line Numbers
  1.             PictureBox pbPlayer = new PictureBox();
  2.             // becomes
  3.             Panel pbPlayer = new Panel();
  4.  
If you built them at design time, you can go into the Form1.Designer.cs file and change their type.

Expand|Select|Wrap|Line Numbers
  1.         #region Windows Form Designer generated code
  2.  
  3.         /// <summary>
  4.         /// Required method for Designer support - do not modify
  5.         /// the contents of this method with the code editor.
  6.         /// </summary>
  7.         private void InitializeComponent()
  8.         {
  9.             this.button1 = new System.Windows.Forms.Button();
  10.             this.button2 = new System.Windows.Forms.Button();
  11.             this.pictureBox1 = new System.Windows.Forms.PictureBox();
  12.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  13.             this.SuspendLayout();
  14.  
  15.             // 
  16.             // button1
  17.             // 
  18.             this.button1.Location = new System.Drawing.Point(26, 13);
  19.             this.button1.Name = "button1";
  20.             this.button1.Size = new System.Drawing.Size(75, 23);
  21.             this.button1.TabIndex = 1;
  22.             this.button1.Text = "button1";
  23.             this.button1.UseVisualStyleBackColor = true;
  24.             this.button1.Click += new System.EventHandler(this.button1_Click);
  25.             // 
  26.             // button2
  27.             // 
  28.             this.button2.Location = new System.Drawing.Point(207, 12);
  29.             this.button2.Name = "button2";
  30.             this.button2.Size = new System.Drawing.Size(75, 23);
  31.             this.button2.TabIndex = 2;
  32.             this.button2.Text = "button2";
  33.             this.button2.UseVisualStyleBackColor = true;
  34.             this.button2.Click += new System.EventHandler(this.button2_Click);
  35.             // 
  36.             // pictureBox1
  37.             // 
  38.             this.pictureBox1.Location = new System.Drawing.Point(3, 3);
  39.             this.pictureBox1.Name = "pictureBox1";
  40.             this.pictureBox1.Size = new System.Drawing.Size(100, 50);
  41.             this.pictureBox1.TabIndex = 0;
  42.             this.pictureBox1.TabStop = false;
  43.             // 
  44.             // Form1
  45.             // 
  46.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  47.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  48.             this.ClientSize = new System.Drawing.Size(544, 497);
  49.             this.Controls.Add(this.button2);
  50.             this.Controls.Add(this.button1);
  51.             this.Name = "Form1";
  52.             this.Text = "Form1";
  53.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  54.             this.ResumeLayout(false);
  55.  
  56.         }
  57.  
  58.         #endregion
  59.  
  60.         private System.Windows.Forms.Button button1;
  61.         private System.Windows.Forms.Button button2;
  62.         private System.Windows.Forms.PictureBox pictureBox1;
  63.  
  64.     }
  65.  
This way you don't have to delete controls and make new ones, then attach event handles and so on - you just change the type of the existing control.
Oct 9 '09 #5
2 Plater
2 tlhintoq
I'll rewrite now picturebox code. It's good thing that I have all the controls dynamic.
Oct 9 '09 #6
No, panel doesn't work... The same problem.
Oct 9 '09 #7
Hiii friends i have same problem. If anybody have any idea then please reply me. it is very argent.


Thanks in advance
Mar 4 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

20 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by M West | last post: by
1 post views Thread by Andrew E Chapman | last post: by
1 post views Thread by bungle | last post: by
reply views Thread by =?Utf-8?B?RG9jdG9y?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.