Guest Posted December 29, 2008 Share Posted December 29, 2008 I just spent the last two hours trawling the internet trying to find out how to have images with a transparent background. Apparently when you set the background of a picturebox to transparent it only sets it to the colour of its parent control. This is what im trying to do... But this is what is happening... This website seems to do what I want but i cant implement it correctly. http://www.doogal.co.uk/transparent.php Any suggestions... Thanks Link to comment https://www.neowin.net/forum/topic/715010-c-transparent-images/ Share on other sites More sharing options...
0 James Rose Posted December 29, 2008 Share Posted December 29, 2008 The quick and dirty option that I can think of is to have the image on a seperate form and have that set to transparent as well. The image and the form's transparent color should be set to the same color and that should work out fine. (I believe... sorry, Im stuck on an XML issue and throught I'd offer a quick hand) Link to comment https://www.neowin.net/forum/topic/715010-c-transparent-images/#findComment-590333676 Share on other sites More sharing options...
0 Guest Posted December 29, 2008 Share Posted December 29, 2008 Cool, thanks for taking the time to reply... that works Now i just have to figure out how to move the overlaying form along with the main form. Any easier way of doing it though? If i remember correctly VB.Net allows control opacity and transparency straight off. Link to comment https://www.neowin.net/forum/topic/715010-c-transparent-images/#findComment-590334000 Share on other sites More sharing options...
0 Guest Posted December 30, 2008 Share Posted December 30, 2008 Ok, Im still working on the code but at least i have got the basics. Now that i have created this transparentImage class i can overlay a transparent picture in a separate form over the current form. I use the following code in the class in want to declare the transparent image on... transparentImage tImage= new transparentImage(this, 300, 20); tImage.Show(); This seems works well - it takes the current form, and places the image relative to the forms location. However... this does not show up in the class design view (allowing for direct manipulation)... When i go to place this code in the designer.cs file i get an error. I know that the this is the part that is screwing it up... but how would i remedy the situation? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MyProgram { public partial class transparentImage : Form { private int oldFormX = 0; private int oldFormY = 0; private int newFormX = 0; private int newFormY = 0; private int offsetX = 0; private int offsetY = 0; Form controllingForm = null; public transparentImage(Form controllingForm, int X, int Y) { InitializeComponent(); this.Location = new System.Drawing.Point(controllingForm.Location.X + X, controllingForm.Location.Y + Y); this.controllingForm = controllingForm; controllingForm.ResizeBegin += new System.EventHandler(ResizeBegin); controllingForm.ResizeEnd += new System.EventHandler(ResizeEnd); controllingForm.FormClosed += new FormClosedEventHandler(FormClosed); } private void ResizeBegin(object sender, EventArgs e) { // get the initial form size oldFormX = controllingForm.Location.X; oldFormY = controllingForm.Location.Y; this.Hide(); } private void ResizeEnd(object sender, EventArgs e) { newFormX = controllingForm.Location.X; newFormY = controllingForm.Location.Y; calculateFormOffset(); this.Location = new System.Drawing.Point(this.Location.X + offsetX, this.Location.Y + offsetY); this.Show(); } private void FormClosed(object sender, EventArgs e) { this.Close(); } private void calculateFormOffset() { // get the offset for the X axis if (newFormX > oldFormX) { offsetX = newFormX - oldFormX; } else if (newFormX < oldFormX) { MessageBox.Show("OLD" + oldFormX.ToString()); MessageBox.Show("NEW" + newFormX.ToString()); offsetX = newFormX - oldFormX; } else { offsetX = 0; } // get the offset for the Y axis if (newFormY > oldFormY) { offsetY = newFormY - oldFormY; } else if (newFormY < oldFormY) { offsetY = newFormY - oldFormY; } else { offsetY = 0; } } } } Thanks Link to comment https://www.neowin.net/forum/topic/715010-c-transparent-images/#findComment-590335432 Share on other sites More sharing options...
0 Guest Posted January 4, 2009 Share Posted January 4, 2009 Sorry to drag this up again... I completely scraped the code that i was working on above since i found the C# graphics class... The code below gives me the results i want. private void login_paint(object sender, PaintEventArgs e) { // Get Graphics Object Graphics g = e.Graphics; g.DrawImage((Image)Properties.Resources.oops, 290, 0); } All i need to know now is how to anchor one of these images to the form... Can anyone help? Link to comment https://www.neowin.net/forum/topic/715010-c-transparent-images/#findComment-590361378 Share on other sites More sharing options...
Question
Guest
I just spent the last two hours trawling the internet trying to find out how to have images with a transparent background.
Apparently when you set the background of a picturebox to transparent it only sets it to the colour of its parent control.
This is what im trying to do...
But this is what is happening...
This website seems to do what I want but i cant implement it correctly.
http://www.doogal.co.uk/transparent.php
Any suggestions... Thanks
Link to comment
https://www.neowin.net/forum/topic/715010-c-transparent-images/Share on other sites
4 answers to this question
Recommended Posts