|
Hello everyone,
I'm developing an application that is similar to Windows Explorer. I'm using a ListView control to display files and folders along with their icons. Now, icons for files can be retrieved using standard shell functions ExtranctIcon and ExtractIconEx. But my question is that how can I get that translucent effect as used by Windows Explorer for hidden and system files.
I searched google and found the following code snippet:
public static Image SetImageOpacity(Image imagePic, float imageOpacity)
{
Bitmap bmpPic = new Bitmap(imagePic.Width, imagePic.Height);
Graphics gfxPic = Graphics.FromImage(bmpPic);
ColorMatrix cmxPic = new ColorMatrix();
cmxPic.Matrix33 = imageOpacity;
ImageAttributes iaPic = new ImageAttributes();
iaPic.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
gfxPic.DrawImage(imagePic, new Rectangle(0, 0, bmpPic.Width, bmpPic.Height), 0, 0, imagePic.Width, imagePic.Height, GraphicsUnit.Pixel, iaPic);
gfxPic.Dispose();
return bmpPic;
}
Now my code calls this method as follows:
lViewVFSBrowser.LargeImageList.Images.Add(imageKey, SetImageOpacity(iconL.ToBitmap(), (float)0.7));
but all I get in return is an icon with a bluish background as shown here:
http://www.geocities.com/ankit_incredible_2006/problem.JPG[^]
|
|
|
|
|
[Edit] It looks like the same source after rereading the code you posted! Could you let me have the link so I can make sure I give credit in the code.
I think you need to up your opacity value[/Edit]
[Edit2]Ok, found the original here[^][/Edit2]
I've looked through all the icons in every file in the System32 folder and the hidden style icons aren't there, so I guess that Windows uses some overlay and/or transparency trick to do it.
This should work - it's an altered version that I found on the web some time ago, can't remember the source.
Opacity = 0 to 255, works fine with .ico files.
public Image AdjustImage(Image image, float opacity)
{
Bitmap bitmap = new Bitmap(image.Width, image.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
ColorMatrix matrix = new ColorMatrix();
matrix.Matrix33 = opacity;
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(
image, new Rectangle(
0, 0, bitmap.Width, bitmap.Height),
0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
return bitmap;
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks Dave for you time, but this method is exactly the same as the one I posted. Still I tried it, and used higher values for opacity (0 ~ 255) but the result is still the same.
|
|
|
|
|
Yeah, I realized that after I posted it - hence the edits!
I think it's something to do with the way the ListView renders it as it works fine elsewhere. I'll keep playing, there has to be a solution.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Actually, it appears it's the ImageList that's causing the problem.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi Dave,
I got it working correctly after a few hours of . The information from Joe Pardue's articles on transparency and alpha blending got me on the right track. Really they are excellent articles. I'd recommend reading them to all those who want to get a grip on graphics processing concepts.
Transparency Tutorial with C# - Part 1[^]
Transparency Tutorial with C# - Part 2[^]
Transparency Tutorial with C# - Part 3[^]
All that was needed was this little modification:
public static Image SetImageOpacity(Image image, float opacity)
{
Bitmap bitmap = new Bitmap(image.Width, image.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.FillRegion(new SolidBrush(SystemColors.Window), new Region(new Rectangle(0, 0, image.Width, image.Height)));
ColorMatrix matrix = new ColorMatrix();
matrix.Matrix33 = opacity;
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
return bitmap;
}
Originally the method did the following:
1. Create a new Bitmap object.
2. Create a new ColorMatrix object and set the alpha element (3,3) to the desired value.
3. Construct a new ImageAttributes object, associate the ColorMatrix with it, and then use this whole information to draw the input Image over the new Bitmap object.
The problem, as far as I understand now (after reading Joe's articles), was that the method was trying to draw the source image over an empty bitmap (black colored bitmap). Thus, after applying the transformation, the image goes dark instead of fading into the background color.
Now the line which I added, paints the destination bitmap with the background color of the Window, before painting the source image, so that when it is blended with the source image, the source image appears blended into the background color.
That's it.
And here's the difference:
Before[^]
After[^]
|
|
|
|
|
Cool! It's wierd, as setting a form's BackgroundImage worked fine before if set from the function but not if set from the image list after filling it from the function
Anyway, nice to know it's sorted and thanks for posting the solution
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
That works only if the BackColor of the ListView is SystemColors.Window and you don't use the image on any other control with a different BackColor. Adding bitmap.MakeTransparent(SystemColors.Window); before returning fixes that.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Yeah, I noticed that. Thanks for pointing out.
|
|
|
|
|
I want to write a project in windows application with C#.net,
I have two forms , in Form1 i have a textbox, in form2 i need the textbox which is on Form1 , I want to know what should i do that form2 recognizes form1, how can i link these two forms??
|
|
|
|
|
It depends on the 'relationship' between the forms.
Scenario 1:
form1 instanciates form2
If form1 wants to send data to form2, you should write a public property with at least a setter (or a public method) in Form2. form1 can then set that property (or call that method) in the form2 instance.
If form2 wants to send data to form1, you should write an event (or raise a built in one) in Form2 and subscribe to it accordingly in Form1.
Scenario 2:
form1 and form2 are both instanciated elsewhere
Pretty much the same as above, except treat both forms like Form2s, and treat the object that did the instanciation like form1.
Reasoning:
The instanciating object already knows about any objects it's created (and can maintain a list of them if necessary). It therefore already has access to their properties, methods and events.
The created instances know nothing about the object that created them (and it should remain that way), so they should raise events that the creator can subscribe to, and if needed, the creator can cascade relevant data to other objects.
This applies to all objects, not just forms.
Note
Any event data should be passed through an instance of a class that you derive from EventArgs.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Well described 5'd
|
|
|
|
|
Well, you can do that but why you need to do that?
use mdi parent forms instead or use usercontrols like pages in your application.
I see no use of creating 2 form when you can do any of the methods above, but you are the boss...
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Even seperate user controls or MdiParent/MdiChidren should use the same method of communication. They are still seperate objects.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Timestamp: 1/24/2009 7:33:57 AM
Message: Exception in call me method : Thread was being aborted.
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at ANAX_Dashboard.AnaxDashFrm.Callme() in E:\ANAX Dashboard working folder\ANAX Desktop Reports\ANAX Desktop Reports\FrmAnaxDashboard.cs:line 95
Category: Error
----------
when thread is abort
|
|
|
|
|
Post some code so we can analyze it a bit.
|
|
|
|
|
I thing, ManualResentEvent or AutoResendEvent are used in ur application.
but u r not handle write.This is my assumption.
|
|
|
|
|
anishkannan wrote: I thing, ManualResentEvent or AutoResendEvent are used in ur application.
but u r not handle write.This is my assumption.
DO NOT USE TEXT-SPEAK. It's RUDE.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi
Anybody help me......
how can create table layout on the panel.
A one panel split in to row and coloum and each table have the
unique name. futherly we want to access that panel table name wise.
Thankyou
|
|
|
|
|
Timestamp: 1/24/2009 7:30:50 AM
Message: Exception in call me method : Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog.
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at ANAX_Dashboard.AnaxDashFrm.Callme() in E:\ANAX Dashboard working folder\ANAX Desktop Reports\ANAX Desktop Reports\FrmAnaxDashboard.cs:line 95
Category: Error
|
|
|
|
|
Happens for example if you call Show for a form and afterwards you try to call ShowDialog for the same instance. But without seeing the code, it's hard to say more.
|
|
|
|
|
Timestamp: 1/23/2009 11:56:54 AM
Message: Exception in call me method : Thread was being aborted.
at System.Drawing.SafeNativeMethods.Gdip.GdipImageSelectActiveFrame(HandleRef image, Guid& dimensionID, Int32 frameIndex)
at System.Drawing.Image.SelectActiveFrame(FrameDimension dimension, Int32 frameIndex)
at System.Drawing.ImageAnimator.ImageInfo.UpdateFrame()
at System.Drawing.ImageAnimator.UpdateFrames()
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at ANAX_Dashboard.AnaxDashFrm.Callme() in E:\ANAX Dashboard working folder\ANAX Desktop Reports\ANAX Desktop Reports\FrmAnaxDashboard.cs:line 94
Category: Error
|
|
|
|
|
Reply to what? You didn't put in a question.
|
|
|
|
|
|
|