 |
|
 |
1) picture must be a PNG with transparency BG color. you can make such an image in Paint.NET or adobe photoshop 2) you have to set controls BackColor and TransparencyColor to the same value
and that's it...
C#, ASPX, SQL, novice to NHibernate
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Your method will not work. Just run the the compiled exe in another PC and you will know that it is not working. Moreove this method does not create true shaped Controls. Notice that your see through area are actaully part of the object. if you click or more mouse over those transparent areas the controls underneath them will not response since the see through area is actaully part of the object that is holind the bipmap.
To achive a true shaped Control or Form or object which will not have the transparent areas as it's part and coltrol underneath the transparent ares will react normally:
You must define the Region for the control that will host the bitmap for you. The Region will actaully define drawing areas where windows in allowed to draw while creating the control. Thus creating a shaped form or control.
To achieve this you must first go through the bitmap and find areas of interest and create a GraphicsPath which represent that border areas, once competle you just add create a new region using that Path and define that region as your Object.Region.
Here is an simle example: If your Bipmap's Transparent Color is 255,0,255 and the object or Form that will be showing the bitmap is PictureBAR
// You can read or load the bitmap anyway you want. Bitmap bitmap = new Bitmap(GetType(),@"images.YahooLoginBar2.bmp"); Color transparencyColor = Color.FromArgb(255,0,255);
int height = bitmap.Height; int width = bitmap.Width;
GraphicsPath path = new GraphicsPath();
for (int j=0; j for (int i=0; i { if (bitmap.GetPixel(i, j) == transparencyColor) // skipping transparent areas continue;
int x0 = i;
while ((i < width) && (bitmap.GetPixel(i, j) != transparencyColor)) i++;
path.AddRectangle(new Rectangle(x0, j, i-x0, 1)); // adding valid areas in Path } pictureBAR.Region = new Region(path); // Add this newly created region to our control
--- After this we actaully have created a TRUE shaped FORM or control. Remember we haven't drawn anything on the Object, we just have defined its shape. Thus anything outside of that shape is actaully not part of the object.
Now we can actaully draw the bitmap on the control. One way to achieve this would be to set a event handler for the Paint event of that Object. Here our object's name is PictureBAR. To have this you can simple do this:
this.pictureBAR.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBAR_Paint);
The Paint Code follows:
private void pictureBAR_Paint(object sender, System.Windows.Forms.PaintEventArgs pea) { Bitmap BackgroundBitmap = new Bitmap(GetType(),@"images.YahooLoginBar2.bmp"); pea.Graphics.DrawImage(BackgroundBitmap, 0,0, BackgroundBitmap.Width, BackgroundBitmap.Height);
return; }
You can DrawImage anywhere in your software after you have really setup the Region for the control or object. But it is always a good idea to have it in the Pain Event.
Rezaul Kabir shuvro@yahoo.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
First of all, thanks for this trick, I've tried it but it didn't work fine for me, I think that I've made some mismatch with the color values.
But it doesn't matter as I've tried a PNG file with a transparent background and it worked really well for me (on a Win 2003 server)
I didn't had to find the matching transparency color... Hope this helps and works not only for me
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
That was great comment i really appreciate that alot.......thanx for your help and time......
There is nothing ever you cannot do but there is some thing always you don’t know
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Be aware that whilst this method works fine on Win2k and WinXp; it will not work on Windows/NT based machines.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for your time sending your helpful comment ....... cuz i didnt try it on the NT4 .........and i dont know why it couldnt work on it...thanx again.
I Love programming
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
A long pause between replies but the reason it doens't work on NT4 is that NT4 doesn't support alpha colours or transparencies.
Ed
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This is straightforward and simple but it just doesnt work right for me, neither on a XP or nor on a w2k machine.
/Taz
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
i've got a dual monitor system (w2k sp4, GeForce4 MX 440 ) and on the main monitor it doesn't work whereas on the second one it does.
i could not find any differences in the settings of the graphics-driver for the two monitors.
greetings wb
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
What exactly happen?!!!! Does it show the green edges or the form doesn’t appear or it gives you an error??!!!! Till me what was the problem or the bug to know………thanx for your help.
I Love programming
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Neet, it works for mew but flickers on starting...
Matthew Hazlett Windows 2000/2003 MCSE Never got an MCSD, go figure...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The DotNet works with graohics by its way it makes a layer between the operating system and the user interface you can make sure of the is you used the zoomin tool which was in the visual studio 6 and focus on the form you will see nothing in the tool it makes the form a pear only across its platform so we have nothing to do with it .................thanx again for your time i hope we find much better way...
I Love programming
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Hi it doesn't work with me too , I even made a new background image so simple , but the background area which is colored by an illuminated color as Lime didn't work with me .. thanks .. give a hand please..
Kareem Shaker
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
Kimooooooooo i think the error was on the values of the color u choose, and as i said b4 , this trick works on some platforms and others not, try to make the image .png with trancparent BG and see if it works............thanx for your time and help.
There is nothing ever you cannot do but there is some thing always you don’t know
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Unfortunately this method is not reliable, it says as much in the MSDN documentation. It wont work on many laptops, or a wide range of machines with 'ob-board' graphics. If you also combine this with transparency, you can get some machines to blue screen! It is much more reliable to generate the region in code, and there are many samples of doing this on codeproject.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
i am not teaching how to make shaped forms with code and evry one know that any method to make any work without code will not be reliable but i gust like to introduce some thing i found ...........i hope you may use it at some specific situations.........thanx for your help and your time
There is nothing ever you cannot do but there is some thing always you don’t know
|
| Sign In·View Thread·PermaLink | 3.00/5 |
|
|
|
 |