|
Argument Exception Unhandled at runtime:
Bitmap searchBitmap = new Bitmap("Search_16X16_32bpp.png");
Jer 29:11
|
|
|
|
|
I didn't want to implement such a large code, and I couldn't figure out what xlouk was talking about, so I found a different solution.
If you use the "standard" flat style and set the backColor to transparent, the xp-style background will show through. Then all you have to do is set the background image and you're done. I've tested it on a couple different theme settings and it looks great on all of them.
Hopefully this helps.
|
|
|
|
|
Hi,
this code is not any more needed when using .NET 2.0 Framework (VS2005). The control System.Windows.Forms.Button is now able to view an icon even with visual style enabled.
But if you nevertheless use the ImageButton class with .NET 2.0 framework or the latest 1.1 for XP Embedded, you may depending on the installed comctrl32.dll versions encounter a problem that icons loaded to an ImageList which is assigned to a ListView won't appear with enabled visual styles.
Reason is, that the call of
GetCommonControlDLLVersion(ref dllVersion);
in the ImageButton Code will force loading the default comctrl32.dll, which may be an old buggy one (V 5.82...) and don't view the icons loaded to the ImageList in a ListView control.
Regards,
xlouk
|
|
|
|
|
So what can I do with this information - how can I reference the correct, latest version - which I believe is version 6?
|
|
|
|
|
What you can do is, don't use the code of this project because it is obsolete in frameword >= V2.0 or don't call GetCommonControlDLLVersion(ref dllVersion) or load the latest version of the dll before calling this method or let .NET do this for you by loading a forms control before calling this method. .NET, when initiating a control, tries to use the latest version of the dll when not allready loaded. GetCommonControlDLLVersion(ref dllVersion) loads the default (probably buggy when installed as default, very likely) dll, when the correct dll is not allready loaded before the call.
When you update to framework 2.0, the buggy dll will not be replaced, it is still used as default dll beside the newer version which ist stored on an other place.
Regards,
xlouk
xlouk
|
|
|
|
|
Hi,
I'm having the same problem. My situation is a bit different however, since my product (written partly in C#/.NET and partly in C++/WTL) is a plugin to a host, written in C#/.NET. In the C++ part of my code is a list view that fails to display the images in its image list, since the host program calls EnableVisualStyles. When this call is removed the images show up nicely (but this is not a solution since the host program needs this call).
I believe my image list gets created by version 5.8 of comctrl32.dll, and my list view by version 6.0, which is causing the problem (see for example http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx). Does anyone have an idea on what I can do..? When I create my image list (currently using the WTL class CImageList) and my list view (WTL class CListViewCtrl), is there any way that I can control which version of comctrl32.dll that is used..? It would be nice if they were created by the same version of comctrl32.dll =)
Thanks in advance!
/David
|
|
|
|
|
But the issue is, even in .NET 2.0 VS 2005, when you set the FlatStyle to System, the control does not display the image assigned to the image property.
But you are saying this is fixed in .NET 2.0. Can you clarify on this please?
I think the issue is still there in .NET 2.0. Am i wrong?
Are you saying that the button control in .NET 2.0 can be made to display image even if its FlatStyle is set to System. Can you show how to make this work in .NET 2.0.
I tried this and it does not display the Image.
Also you say that .NET 2.0 button control can display Icon????
If i set an icon to the Image property, it does not display it properly - i.e. the shadow effects in the icon is lost and the control displays black spots where the shadow is supposed to be there.
-- modified at 13:20 Monday 13th August, 2007
|
|
|
|
|
Hi,
per default comctl32.dll is installed in c:\windows\system32 folder which version is <6.0 and is buggy. In addition search under C:\Windows\WinSxS\x86_Microsoft.Windows.Common-Controls... folders for an installed comctl32.dll with version >= 6.0. You need it for a correct working image button with flat style system.
Then there is an other "bug" you have to avoid. The call of GetCommonControlDLLVersion() in this project will load the default comctl32.dll which is most likely V 5.82... and buggy even if you have the good one installed under the WinSxS folder. This happens, when this call occurs first, before a control is loaded, which is in this project the case. Comment out this call and set the ComCtlMajorVersion for a test to 6.0 in the ImageButton constructer.
But I can't remember how I got the comctl32.dll with V > 6.0 on my computer. May be per SP2 of Windows or .Net Framework 2.0 or an other way.
Good luck
xlouk
|
|
|
|
|
When I clicked the DropdownButton in ur demo, the down-arrow disappeared:
1, Remove "ImageButtonTest.exe.manifest" file and run the ImageButtonTest.exe, that makes the app look like in Windows98.
2, PressDown the DropdownButton and then release but do not move mouse, now the down-arrow dispaapears.
3, move the mouse cursor, the down-arrow appears again.
PunCha
|
|
|
|
|
I loaded the project and run as debug, I could not get it to work due to errors like this below
Please advise what I done wrong?.
Thanks
C:\C#_Experiment_Code\ImageButtonTest\ImageButtonTest.cs(220): The variable 'SearchImageButton' is either undeclared or was never assigned.
C:\C#_Experiment_Code\ImageButtonTest\ImageButtonTest.cs(219): The variable 'GoImageButton' is either undeclared or was never assigned.
C:\C#_Experiment_Code\ImageButtonTest\ImageButtonTest.cs(218): The variable 'DisableButton' is either undeclared or was never assigned.
C:\C#_Experiment_Code\ImageButtonTest\ImageButtonTest.cs(217): The variable 'DropDownButton' is either undeclared or was never assigned.
C:\C#_Experiment_Code\ImageButtonTest\obj\Debug\CSC244.tmp Error generating Win32 resource: Error reading icon 'C:\C#_Experiment_Code\ImageButtonTest\App.ico' -- The system cannot find the file specified.
Could not find type 'OOGroup.Windows.Forms.ImageButton'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
Could not find type 'OOGroup.Windows.Forms.ImageButton'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
Could not find type 'OOGroup.Windows.Forms.ImageButton'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
Could not find type 'OOGroup.Windows.Forms.ImageButton'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
>It's not so much what you have to learn if you accept weird theories, it's what you have to unlearn. (Isaac Asimov)
>Life's journey is not to arrive at the grave safely in a well preserved body,but rather to skid in sideways, totally worn out, shouting "...holy sh*t...what a ride! [Riscy]
|
|
|
|
|
Riscy,
right-click App.ico in the Solution Explorer and "Exclude from Project", then hit F5.
--
Michael Ganss
O&O Services GmbH
|
|
|
|
|
hi,
thanks for your button, it's great! I needed dropdown buttons with images and xp style for an IE toolbar: In my toolbar, I show contextmenus right under buttons when the user (left) clicks them.
Just a question: do you know how to make those button look "pushed" when the contextmenu is displayed? I tried by setting them disabled, but it doesn't look nice.
Thank you very much!
|
|
|
|
|
Hi,
The only way to achieve this I can think of is to use a RadioButton with Appearance set to "Button". This looks like a regular Button, but changes to the pushed look when the radio button is selected. I don't know if it's easy to adapt the code.
HTH
--
Michael Ganss
O&O Services GmbH
|
|
|
|
|
Hi Michael,
Thanks for your answer, I came to a similar conclusion: in fact I'm deriving my control from a check box with button appearance. I'm working on it, it seems to work, I will post an article about it when I finish. I've slightly modified your logic, only used one image, added a dropdown menu feature, and not used the unsafe code as it crashes on my PC, but instead the code found in a comment posted here:
for (int row = 0; row < bm.Height; row++)<br />
{<br />
for (int col = 0; col < bm.Width; col++)<br />
{<br />
Marshal.WriteInt32( pDst, dstoff + col, Marshal.ReadInt32( pSrc, srcoff + col ) );<br />
}<br />
srcoff += (src.Stride >> 2);<br />
dstoff += (src.Stride >> 2);<br />
}
Anyway, thanks for your work, it helped me a lot!
|
|
|
|
|
Hi everybody,
I modified the code slightly and it resulted in a ImageCheckBox: a checkbox with an image and xp styles.
Here's my code.
The changes are:
-base class is CheckBox
-Property "ImageAlign" is overridden so that it can be set by designer (would be nice to have in "ImageButton", too) !
-Setting the image by property "ThemedImage": current "ImageAlign" value is honored.
-DropDown-Feature removed (makes no sense with a checkbox).
Enjoy it !
Wolfgang
=================================
///
/// A System.Windows.Forms.CheckBox that can have an image on systems that support visual styles.
/// Uses the BCM_SETIMAGE message that is provided by comctl32.dll, version 6.
/// On systems that have a lower version of comctl32.dll, i.e. earlier than Windows XP,
/// falls back to FlatStyle.Standard.
///
///
public class ImageCheckBox: CheckBox
{
///
/// Constructor.
///
public ImageCheckBox()
{
FlatStyle = FlatStyle.System;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
///
/// The alignment of an image within a button.
///
public enum Alignment { Left, Right, Top, Bottom, Center };
private const int BCM_SETIMAGELIST = 0x1600 + 2;
[StructLayout(LayoutKind.Sequential)]
private struct BUTTON_IMAGELIST
{
public IntPtr himl;
public RECT margin;
public int uAlign;
}
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref BUTTON_IMAGELIST lParam);
[StructLayout(LayoutKind.Sequential)]
private struct DLLVERSIONINFO
{
public int cbSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformID;
}
[DllImport("comctl32.dll", EntryPoint="DllGetVersion")]
private static extern int GetCommonControlDLLVersion(ref DLLVERSIONINFO dvi);
private int ComCtlMajorVersion = -1;
private Bitmap themedImage;
[Description("The image on the face of the button."), Category("Appearance"), DefaultValue(null)]
public Bitmap ThemedImage
{
get
{
return themedImage;
}
set
{
if (value != null)
{
SetImage(value);
}
themedImage = value;
}
}
///
/// Set the "ImageAlign" property.
///
/// If the property "ThemedImage" is already set the image is re-rendered.
///
[DefaultValue (ContentAlignment.MiddleCenter)]
[Description ("Ausrichtung des Bildes. Wandelt intern auf einen Wert der Enum \"Alignment\" um !")]
public new ContentAlignment ImageAlign
{
get
{
return base.ImageAlign;
}
set
{
Alignment alignment = GetAlignment(value);
base.ImageAlign = value;
//Ist das ThemedImage gesetzt ? Wenn ja, dann in die Checkbox packen !
if (this.themedImage != null)
{
this.SetImage (this.themedImage, alignment);
}
}
}
///
/// Convert a content alignment to a "Alignment".
///
/// <param name="_contentAlignment" />
/// <returns>
private static Alignment GetAlignment (ContentAlignment _contentAlignment)
{
Alignment alignment = Alignment.Center;
// public enum Alignment { Left, Right, Top, Bottom, Center };
if (_contentAlignment == ContentAlignment.MiddleLeft || _contentAlignment == ContentAlignment.TopLeft || _contentAlignment == ContentAlignment.BottomLeft)
alignment = Alignment.Left;
else if (_contentAlignment == ContentAlignment.MiddleRight || _contentAlignment == ContentAlignment.TopRight || _contentAlignment == ContentAlignment.BottomRight)
alignment = Alignment.Right;
else if (_contentAlignment == ContentAlignment.TopCenter)
alignment = Alignment.Top;
else if (_contentAlignment == ContentAlignment.BottomCenter)
alignment = Alignment.Bottom;
else if (_contentAlignment == ContentAlignment.MiddleCenter)
alignment = Alignment.Center;
return alignment;
}
///
/// Convert the Alignment to a content alignment.
///
/// <param name="_alignment" />
/// <returns>
private static ContentAlignment GetContentAlignment(Alignment _alignment)
{
ContentAlignment contentAlignment = ContentAlignment.MiddleCenter;
switch (_alignment)
{
case Alignment.Bottom:
contentAlignment = ContentAlignment.BottomCenter;
break;
case Alignment.Left:
contentAlignment = ContentAlignment.MiddleLeft;
break;
case Alignment.Right:
contentAlignment = ContentAlignment.MiddleRight;
break;
case Alignment.Top:
contentAlignment = ContentAlignment.TopCenter;
break;
case Alignment.Center:
contentAlignment = ContentAlignment.MiddleCenter;
break;
}
return contentAlignment;
}
///
/// Sets the image of the button to the specified value.
/// The image is aligned at the center with no margin.
/// All states of the button show the same image.
///
/// <param name="image" />The images for the button
public void SetImage(Bitmap image)
{
//Use the current "ImageAlign" value !
//SetImage(new Bitmap[] { image }, Alignment.Center, 0, 0, 0, 0);
SetImage(new Bitmap[] { image }, GetAlignment (this.ImageAlign), 0, 0, 0, 0);
}
///
/// Sets the image of the button to the specified value with the specified alignment.
/// All states of the button show the same image.
///
/// <param name="image" />The images for the button
/// <param name="align" />The alignment of the image
public void SetImage(Bitmap image, Alignment align)
{
SetImage(new Bitmap[] { image }, align, 0, 0, 0, 0);
}
///
/// Sets the image of the button to the specified value with the specified alignment and margins.
/// All states of the button show the same image.
///
/// <param name="image" />The images for the button
/// <param name="align" />The alignment of the image
/// <param name="leftMargin" />The left margin of the image in pixels
/// <param name="topMargin" />The top margin of the image in pixels
/// <param name="rightMargin" />The right margin of the image in pixels
/// <param name="bottomMargin" />The bottom margin of the image in pixels
public void SetImage(Bitmap image, Alignment align, int leftMargin, int topMargin, int rightMargin,
int bottomMargin)
{
SetImage(new Bitmap[] { image }, align, leftMargin, topMargin, rightMargin, bottomMargin);
}
///
/// Sets the images of the button to the specified values.
/// The images are aligned at the center with no margin.
///
/// <param name="image" />The images for the button
/// <param name="normalImage" />The normal state image for the button.
/// <param name="hoverImage" />The hover state image for the button.
/// <param name="pressedImage" />The pressed state image for the button.
/// <param name="disabledImage" />The disabled state image for the button.
/// <param name="focusedImage" />The focused state image for the button.
public void SetImage(Bitmap normalImage, Bitmap hoverImage, Bitmap pressedImage,
Bitmap disabledImage, Bitmap focusedImage)
{
SetImage(new Bitmap[] { normalImage, hoverImage, pressedImage,
disabledImage, focusedImage },
Alignment.Center, 0, 0, 0, 0);
}
///
/// Sets the images of the button to the specified values with the specified alignment.
///
/// <param name="image" />The images for the button
/// <param name="normalImage" />The normal state image for the button.
/// <param name="hoverImage" />The hover state image for the button.
/// <param name="pressedImage" />The pressed state image for the button.
/// <param name="disabledImage" />The disabled state image for the button.
/// <param name="focusedImage" />The focused state image for the button.
/// <param name="align" />The alignment of the image
public void SetImage(Bitmap normalImage, Bitmap hoverImage, Bitmap pressedImage,
Bitmap disabledImage, Bitmap focusedImage,
Alignment align)
{
SetImage(new Bitmap[] { normalImage, hoverImage, pressedImage,
disabledImage, focusedImage },
align, 0, 0, 0, 0);
}
///
/// Sets the images of the button to the specified values with the specified alignment and margins.
///
/// <param name="normalImage" />The normal state image for the button.
/// <param name="hoverImage" />The hover state image for the button.
/// <param name="pressedImage" />The pressed state image for the button.
/// <param name="disabledImage" />The disabled state image for the button.
/// <param name="focusedImage" />The focused state image for the button.
/// <param name="align" />The alignment of the image
/// <param name="leftMargin" />The left margin of the image in pixels
/// <param name="topMargin" />The top margin of the image in pixels
/// <param name="rightMargin" />The right margin of the image in pixels
/// <param name="bottomMargin" />The bottom margin of the image in pixels
public void SetImage(Bitmap normalImage, Bitmap hoverImage, Bitmap pressedImage,
Bitmap disabledImage, Bitmap focusedImage,
Alignment align, int leftMargin, int topMargin, int rightMargin,
int bottomMargin)
{
SetImage(new Bitmap[] { normalImage, hoverImage, pressedImage,
disabledImage, focusedImage },
align, leftMargin, topMargin, rightMargin, bottomMargin);
}
private bool generateDisabledImage = false;
[Description("Determines whether the image for the disabled state will be generated automatically from the normal one."), Category("Appearance"), DefaultValue(false)]
public bool GenerateDisabledImage
{
get
{
return generateDisabledImage;
}
set
{
generateDisabledImage = value;
}
}
[DllImport("UxTheme")]
private static extern bool IsThemeActive();
[DllImport("UxTheme")]
private static extern bool IsAppThemed();
private static bool IsVisualStylesEnabled
{
get
{
return OSFeature.Feature.IsPresent( OSFeature.Themes ) && IsAppThemed() && IsThemeActive();
}
}
///
/// Sets the images of the button to the specified value with the specified alignment and margins.
///
/// <param name="images" />The images for the button.
/// <param name="align" />The alignment of the image
/// <param name="leftMargin" />The left margin of the image in pixels
/// <param name="topMargin" />The top margin of the image in pixels
/// <param name="rightMargin" />The right margin of the image in pixels
/// <param name="bottomMargin" />The bottom margin of the image in pixels
public void SetImage(Bitmap[] images,
Alignment align, int leftMargin, int topMargin, int rightMargin,
int bottomMargin)
{
if (GenerateDisabledImage)
{
if (images.Length == 1)
{
Bitmap image = images[0];
images = new Bitmap[] { image, image, image, image, image };
}
images[3] = DrawImageDisabled(images[3]);
}
if (ComCtlMajorVersion < 0)
{
DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
GetCommonControlDLLVersion(ref dllVersion);
ComCtlMajorVersion = dllVersion.dwMajorVersion;
}
if (ComCtlMajorVersion >= 6 && FlatStyle == FlatStyle.System
&& IsVisualStylesEnabled)
{
RECT rect = new RECT();
rect.left = leftMargin;
rect.top = topMargin;
rect.right = rightMargin;
rect.bottom = bottomMargin;
BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST();
buttonImageList.margin = rect;
buttonImageList.uAlign = (int)align;
ImageList = GenerateImageList(images);
buttonImageList.himl = ImageList.Handle;
SendMessage(this.Handle, BCM_SETIMAGELIST, 0, ref buttonImageList);
}
else
{
FlatStyle = FlatStyle.Standard;
if (images.Length > 0)
{
Image = images[0];
}
switch (align)
{
//Don't modify value if it is already the correct one (would lead to stack overflows in settings the
//property "ImageAlign") !
case Alignment.Bottom:
if (this.ImageAlign != ContentAlignment.BottomCenter)
this.ImageAlign = ContentAlignment.BottomCenter;
break;
case Alignment.Left:
if (this.ImageAlign != ContentAlignment.MiddleLeft)
this.ImageAlign = ContentAlignment.MiddleLeft;
break;
case Alignment.Right:
if (this.ImageAlign != ContentAlignment.MiddleRight)
this.ImageAlign = ContentAlignment.MiddleRight;
break;
case Alignment.Top:
if (this.ImageAlign != ContentAlignment.TopCenter)
this.ImageAlign = ContentAlignment.TopCenter;
break;
case Alignment.Center:
if (this.ImageAlign != ContentAlignment.MiddleCenter)
this.ImageAlign = ContentAlignment.MiddleCenter;
break;
}
}
}
private System.Drawing.Bitmap DrawImageDisabled(System.Drawing.Image image)
{
System.Drawing.Bitmap active = new Bitmap(image);
System.Drawing.Bitmap disable = new Bitmap(active.Width, active.Height);
System.Drawing.Graphics g = Graphics.FromImage(disable);
g.DrawImage(active, 0, 0);
ControlPaint.DrawImageDisabled(g, active, 0, 0, Color.Empty);
g.Dispose();
return disable;
}
private ImageList GenerateImageList(Bitmap[] images)
{
ImageList il = new ImageList();
il.ColorDepth = ColorDepth.Depth32Bit;
if (images.Length > 0)
{
for (int i = 0; i < images.Length; i++)
{
int ReSizeHeight = this.Height;
int ReSizeWidth = this.Width;
if (ReSizeHeight > 256)
{
ReSizeHeight = 256;
}
if (ReSizeWidth > 256)
{
ReSizeWidth = 256;
}
if (images[i].Width > ReSizeWidth || images[i].Height > ReSizeHeight)
{
double Scaling;
double WidthScaling = ReSizeWidth / (double)images[i].Width;
double HeightScaling = ReSizeHeight / (double)images[i].Height;
if (WidthScaling < HeightScaling)
{
Scaling = WidthScaling;
}
else
{
Scaling = HeightScaling;
}
int newWidth = (int)(images[i].Width * Scaling);
int newHeight = (int)(images[i].Height * Scaling);
Bitmap bm = new Bitmap(newWidth, newHeight);
Graphics graphics = Graphics.FromImage(bm);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(images[i], 0, 0, newWidth, newHeight);
images[i] = bm;
}
}
il.ImageSize = new Size(images[0].Width, images[0].Height);
foreach (Bitmap image in images)
{
il.Images.Add(image);
Bitmap bm = (Bitmap)il.Images[il.Images.Count - 1];
// copy pixel data from original Bitmap into ImageList
// to work around a bug in ImageList:
// adding an image to an ImageList destroys the alpha channel
//WKnauf 25.02.2005: den Unsafe Code auskommentiert, den Safe Code reingenommen !
for (int x = 0; x < bm.Width; x++)
{
for (int y = 0; y < bm.Height; y++)
{
bm.SetPixel(x, y, image.GetPixel(x, y));
}
}
/*
// code below contributed by Richard Deeming
// requires /unsafe compiler flag
// does the same as the code above, albeit a lot faster
Rectangle rc = new Rectangle(new Point(0, 0), image.Size);
BitmapData src = image.LockBits(rc, ImageLockMode.ReadOnly, image.PixelFormat);
BitmapData dst = bm.LockBits(rc, ImageLockMode.WriteOnly, image.PixelFormat);
try
{
unsafe
{
int* pSrc = (int*)src.Scan0;
int* pDst = (int*)dst.Scan0;
for(int row=0; row < bm.Height; row++)
{
for(int col=0; col < bm.Width; col++)
{
pDst[col] = pSrc[col];
}
pSrc += src.Stride >> 2;
pDst += dst.Stride >> 2;
}
}
}
finally
{
bm.UnlockBits(dst);
image.UnlockBits(src);
}*/
}
}
return il;
}
}
|
|
|
|
|
I compiled and ran the demo project but the buttons had no xp style...just the standard style, although the property for FlatStyle is set to system
Any help is appreciated.
|
|
|
|
|
Greg,
you need to copy the provided .manifest file into the directory containing the .exe, i.e. typically bin\Debug.
--
Michael Ganss
O&O Services GmbH
|
|
|
|
|
Hi Michael,
I was trying out your ImageButton control in one of my C# windows app projects. After a day, I removed it from the project. But now, the tree view control in my C# windows app is not displaying the images (from an imagelist) that it used to display before I included the ImageButton control.
If I remove the Application.EnableVisualStyles() from the constructor of the form, then teh images appear.
Any ideas why?
Thanks,
Ragul
|
|
|
|
|
Ragul,
that sounds strange. If you removed the source file from your solution, there shouldn't be anything left that can cause this behavior.
Maybe it has something to do with the .manifest file.
Regards
--
Michael Ganss
O&O Services GmbH
|
|
|
|
|
Michael,
Yes, it seemed very strange to me too. I removed all .manifest from the project and still it does not get back the images in the treeview. The primary output (exe) from the project works perfectly fine in another XP box but would not have the images in the treeview in my box.
I do not know anything about coomctl32 but for what I learnt form ur article. I was wondering if it had something to do with the registry; as in, store the configurations of comctl32 in the registry or somthing like that??
Sholud I try reinstalling VS.Net?? Let me know if u find out something...
Thanks,
Ragul
|
|
|
|
|
Ragul,
AFAIK the registry is not involved at all regarding visual styles. The .manifest simply selects another version of the comctl32.dll, but that's not a permanent selection. As soon as you remove the .manifest, the .exe uses the old version again, and you don't get visual styles.
I wouldn't reinstall VS.NET just yet. Have you seen this blog entry:
http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx
There's a topic there that seems to describe the problem you are experiencing:
"Q I sometimes have weird problems with Application.EnableVisualStyles. Some controls don't seem to pick up theming; images that are assigned to TreeView nodes or ListView items sometimes don't render at all."
HTH
--
Michael Ganss
O&O Services GmbH
|
|
|
|
|
There's been a report bug with visual styles. If you add a Application.DoEvents() after your Application.EnableVisualStyles() your images should reappear
|
|
|
|
|
Hi !
First of all: really great button !
I encountered some strange crashes and exceptions in a complex dialog with a bunch of different components (from different vendors) and controls.
E.g:
System.NullReferenceException:
at System.Drawing.SafeNativeMethods.GdipCreateFont(HandleRef fontFamily, Single emSize, FontStyle style, GraphicsUnit unit, IntPtr& font)
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet)
at myDialog.InitializeComponent()
It happened nearly always (but in some rare occasions I could open the dialog and some clicks later it crashed). Not using the ImageButton helped also.
The solution was to comment the unsafe code in ImageButton.GenerateImageList and use the safe (but slower) code.
I hope I'm not the only one who had this problem and I hope I could help those.
Wolfgang
Wolfgang Knauf
|
|
|
|
|
Wolfgang,
see also the thread titled "alpha rendering bug" for a discussion regarding the visual appearance and different ways of adding an Image to an ImageList.
Regards
--
Michael Ganss
O&O Services GmbH
|
|
|
|
|
Heres an equivalent method that can replace the "unsafe" code. Its marked as safe, so it'll compile just fine, but it certainly isn't much safer.
int srcoff = 0;
int dstoff = 0;
IntPtr pSrc = src.Scan0;
IntPtr pDst = dst.Scan0;
for (int row = 0; row < bm.Height; row++)
{
for (int col = 0; col < bm.Width; col++)
{
Marshal.WriteInt32( pDst, dstoff + col, Marshal.ReadInt32( pSrc, srcoff + col ) );
}
srcoff += (src.Stride >> 2);
dstoff += (src.Stride >> 2);
}
--
Joel Lucsy
|
|
|
|
|