Hi sankar,
I apologize for misunderstanding your problem.
Thanks for the detail description, I had never noticed this behavior before.
After some research, it seems this is a known issue in Cursor class.
To workaround this issue, we need save a copy of the .Cur file. serialize
the content of this file instead . We may write a CursorWrapper class to
help us do this.
I found a sample code for you, you need change it to fit your needs.
You need load .cur file into CursorWrapper class instead then access the
Cursor property instead.
If the workaround does not solve your problem, you may contact Phone
service for further help.
Thanks!
<code>
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using System.Globalization;
using System.Runtime.Serialization;
namespace MyCursor
{
[Serializable]
[TypeConverterAttribute(typeof(CursorWrapperConverter))]
public class CursorWrapper : ISerializable
{
Cursor _cursor;
byte[] _originalFile;
internal CursorWrapper(SerializationInfo info, StreamingContext context)
{
SerializationInfoEnumerator sie = info.GetEnumerator();
if (sie == null)
{
return;
}
for (; sie.MoveNext()
{
if (String.Compare(sie.Name, "CursorData", true,
CultureInfo.InvariantCulture) == 0)
{
byte[] dat = (byte[])sie.Value;
try
{
if (dat != null)
{
_originalFile = dat;
CursorConverter cc = new CursorConverter();
_cursor = (Cursor)cc.ConvertFrom(OriginalFile);
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
}
public CursorWrapper(Stream stream)
{
_originalFile = new byte[stream.Length];
stream.Read(_originalFile, 0, _originalFile.Length);
CursorConverter cc = new CursorConverter();
_cursor = (Cursor) cc.ConvertFrom(_originalFile);
}
public Cursor Cursor
{
get { return _cursor; }
}
internal byte[] OriginalFile
{
get { return _originalFile; }
}
void ISerializable.GetObjectData(SerializationInfo si, StreamingContext
context)
{
si.AddValue("CursorData", OriginalFile, typeof(byte[]));
}
}
public class CursorWrapperConverter : TypeConverter {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
if (sourceType == typeof(byte[]))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type
destinationType)
{
if (destinationType == typeof(byte[]))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is byte[])
{
MemoryStream ms = new MemoryStream((byte[])value);
return new Cursor(ms);
}
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(byte[]))
{
if (value != null)
{
return ((CursorWrapper)value).OriginalFile;
}
else
return new byte[0];
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
</code>
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.