473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Transparent mask on picturebox.

I am working on album designing s/w. I have 2 overlapped pictureboxs. My problem is how to make white portion of mask as fully transparent and black portion semi transparent. I will put this type of mask on 1 picturebox.
Mar 4 '10 #1
11 4639
tlhintoq
3,525 Expert 2GB
Are you thinking that by masking the images, your overlapping picturebox controls will become transparent and allow you to see through one picturebox to the one below it? They don't work that way. If the image is transparent it will allow you to see through... to the background color of the picturebox but no further.
Mar 4 '10 #2
Have u seen Karizma s/w for album designing? In karizma there is 2 overlapped pictureboxs, mask which is transparent on 1 picturebox and photo is on another. It shows the back side picturebox, which contains photo. In my s/w ,when i overlap the two picturebox, i can't see the back side picturebox even the front picturebox contains transparent image. It shows background image of panel on which i have added this pictureboxes. How it is possible in c#.net?
Mar 5 '10 #3
tlhintoq
3,525 Expert 2GB
Have u seen Karizma s/w for album designing?
No. And every google for it takes me to some FreeSoftwareTopShareDownload kind of site. Since I'm not a fan of viruses I'm not going to download it.

From what you describe they are not using a basic Windows.Forms.Controls.PictureBox control. They created a custom control for their needs.

There is also no LEDnumber or DashSpeedometerGuage in the basic Framework. But you can make them.
Mar 5 '10 #4
But how to make this type of custom control?

pls give me some idea.
Mar 5 '10 #5
tlhintoq
3,525 Expert 2GB
Custom controls are far from a novice subject.
They generally involve
  • overriding the OnPaint method and writting your own drawing routine.
  • Creating custom events. In the same way a button has a .Click event, your control needs its own events in most cases.
  • Creating custom properties. In the same way a button as a .Width property, your custom control will need properties specific to it's purpose.

There are a couple tutorials here that will get you started. Once you have mastered making custom controls based on pre-existing components then you can move on to custom drawing.

Custom events - A practical guide
Buiding an application - Part 1
Mar 5 '10 #6
Thanks for reply.I will try it.
Mar 5 '10 #7
I have tryed my level best. But result is zero. Because when i add this control it always takes background color of parent control even if it contains transparent image.

If u have any idea then pls tell me.
Mar 6 '10 #8
tlhintoq
3,525 Expert 2GB
Let's see the code from your custom control and maybe together we can figure out what the problem is
Mar 6 '10 #9
Expand|Select|Wrap|Line Numbers
  1. public event PaintEventHandler ent;
  2.  
  3.  
  4.         private Image Img;
  5.  
  6.         public Image imgData
  7.         {
  8.             get
  9.             {
  10.                 return Img;
  11.             }
  12.             set
  13.             {
  14.                 Img = value;
  15.             }
  16.         }
  17.  
  18.  
  19.         private Image BackImage;
  20.  
  21.         public Image BackImg
  22.         {
  23.             get
  24.             {
  25.                 return BackImage;
  26.             }
  27.             set
  28.             {
  29.                 BackImage = value;
  30.             }
  31.         }
  32.         private PictureBox px;
  33.         public PictureBox pk
  34.         {
  35.             get
  36.             {
  37.                 return px;
  38.             }
  39.             set
  40.             {
  41.                 px = value;
  42.             }
  43.         }
  44.         protected override void OnPaint(PaintEventArgs pe)
  45.         {
  46.             // Calling the base class OnPaint
  47.           base.OnPaint(pe);
  48.             if (imgData != null)
  49.             {
  50.                 ent += new PaintEventHandler(CustomControl1_ent);
  51.                 px.Paint += new PaintEventHandler(px_Paint);
  52.                 pe.Graphics.DrawImage(Img, 0, 0);
  53.                 if (BackImage != null)
  54.                 {
  55.                     PaintEventHandler handele = ent;
  56.  
  57.                     if (handele != null)
  58.                     {
  59.                         Graphics g = px.CreateGraphics();
  60.                         px_Paint(px, pe);
  61.                     }
  62.                     //  pe.Graphics.DrawImage(BackImage, new Rectangle(0, 0, px.Width, px.Height), 0, 0, BackImage.Width, BackImage.Height, GraphicsUnit.Pixel);
  63.                 }
  64.             }
  65.         }
  66.  
  67.  
  68.  
  69.         void px_Paint(object sender, PaintEventArgs e)
  70.         {
  71.             if (BackImage != null)
  72.             {
  73.                 e.Graphics.DrawImage(BackImage, new Rectangle(0, 0, px.Width, px.Height), 0, 0, BackImage.Width, BackImage.Height, GraphicsUnit.Pixel);
  74.             }
  75.         }
  76.  
  77.  void CustomControl1_ent(object sender, PaintEventArgs e)
  78.         {
  79.             //if (BackImage != null)
  80.             //{
  81.             //    e.Graphics.DrawImage(BackImage, new Rectangle(0, 0, px.Width, px.Height), 0, 0, BackImage.Width, BackImage.Height, GraphicsUnit.Pixel);
  82.             //}
  83.         }
This is coding of Custom Control. After that i add this user control in Panel.

Expand|Select|Wrap|Line Numbers
  1. CustomControl1 cs = new CustomControl1;
  2. Panel1.Controls.Add(cs);
  3. and pass Image value to control.
I don't know it is a better way or not. But i have tried in such way.
Mar 8 '10 #10
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 8 '10 #11
tlhintoq
3,525 Expert 2GB
From what I can tell your custom control is still based on a picturebox and as such, inherits all of it's limitations which you are trying to get away from.

I give you big marks for a great start and an attempt to do your own coding. This is head and shoulders above what most new posters do.

But what you are going to have to do is create a new control, not inherited from a picturebox, and do all of your own drawing. Not just calling the base.OnPaint method.

Like I said, it is no small matter. To be honest, it isn't the type of thing one figures out by wacking around with code. Apress publishing makes a 1,000+ page book on making custom controls in C#
ISBN 1-59059-439-8
"Pro .NET 2.0 Windows Forms and Custom Controls in C#"
US$ 49.99

I think this is your next best step
Mar 8 '10 #12

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

Similar topics

2
by: Fearless Freep | last post by:
I know there's a PIL mailing list but I thought I would try the question here as well. I'm using PIL on Python 1.5.2 (stop laughing, it's what the ISP has for CGI and I don't have a choice) ...
1
by: Richard Saville | last post by:
I am trying to make a transparent pictureBox. MSDN says to use this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); for the form and this.pictureBox1.BackColor = Color.Transparent; for...
5
by: bat21 | last post by:
How create transparent background in "UserControl" ( Opacity regulated ) ? thanks for all bat21
2
by: Alex Gray | last post by:
Hi, I'm trying to make my PictureBox transparent to the BackgroundImage of the Form, not the BackColor of the form. Here's what i have: ---------------------------------------------------...
7
by: Peter Oliphant | last post by:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to transparent. But, it looks to me like all it does it set these pixels to the color BackColor of the Control it's attached...
9
by: SStory | last post by:
I have a picturebox in my About form. would like to have a link to my company website. Wanted the links background to be transparent. It seems that no one knows how to do this. Have asked...
2
by: thi | last post by:
Hi Experts, I am new to C# moving from VB 6.0. Basic i want to know how do i make the label transparent with the control color it currently on. For example I have a picturebox control...
8
by: MikeB | last post by:
Hi, I created a picturebox with a map as an image. I want to make certain areas on the map clickable hotspots and the way I'm trying to do this is to create a transparent label with a different...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
3
by: sin | last post by:
Hello, I have small problem, here's the situation: There are a windows form - Form1; And two picturebox'es - pictureBox1 and pictureBox2; Those two pictures are transparent in some areas; I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.