467,915 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Problem serializing property on custom UserControl

I have a series of simple controls that I created to make some aspects of
Tablet PC programming a little easier. The "Tablet PC" aspects of the
controls are irrelevant to the problem I'm having, but I feel compelled to
mention it because it can be hard for someone to imagine my challenge when I
talk in hypotheticals.

Anyway, these controls each have an Ink property. For non-Tablet
developers, Ink is a class defined in the Tablet PC SDK (1.0+). I've
created a custom UI Editor for my Ink property and it works well at design
time, but as soon as I run the program the changes are gone. I can't seem
to figure out how to make the IDE (Visual Studio EA 2003) recognize the
change to the property and serialize the data.

I'm attaching my project code to this post because I can't really slim it
down and still have it do what I'm trying to do. Those of you who might be
able to help should be able to get past the extra nonsense pretty easily.
This is my first UI Editor so I'm sure the solution is pretty simple.

Here's how I created the editor:

1. First, I have the control (scratchLabel). If that doesn't go without
saying, please stop reading now - you can't help me. ;-)

2. I have a class called InkEditor which inherits from
System.Drawing.Design.UITypeEditor.

3. In the InkEditor class I have overidden the EditValue method to
display a form which captures the ink. This form works on non-Tablet PC
machines as well. Here is the code for that method:

public override object
EditValue(System.ComponentModel.ITypeDescriptorCon text context,
IServiceProvider provider, object value)

{

InkEditorDialog inkedit = new InkEditorDialog();

if (value != null)

{

inkedit.Ink = (Ink)value;

}

else

{

inkedit.Ink = new Ink();

}

IWindowsFormsEditorService winFormEditorService =
(IWindowsFormsEditorService)provider.GetService(ty peof(IWindowsFormsEditorService));

if (DialogResult.OK == winFormEditorService.ShowDialog(inkedit))

{

value = inkedit.Ink;

}

return value;

}

4. In the scratchLabel class (my control), I've put the following
attribute on my Ink property.

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible),System.ComponentModel.Edito r
(typeof(InkEditor),typeof(System.Drawing.Design.UI TypeEditor))]

5. I probably should have mentioned it earlier, but my scratchLabel
class is tagged with the [Serializable()] attribute and implements the
ISerializable interface.

6. The following serialization code is included, but it doesn't seem to
ever get called.

public scratchLabel (SerializationInfo info, StreamingContext context)

{

InitializeComponent();

try

{

//deserialize class

this.Ink = (Ink)info.GetValue ("Ink",typeof(Microsoft.Ink.Ink));

}

catch (Exception ex)

{

throw ex;

}

}

//serializes class

void ISerializable.GetObjectData(SerializationInfo info, StreamingContext
context)

{

info.AddValue ("Ink",this.Ink);

}

So the million dollar question is, what am I missing? There must be
something really simple that I need to include to let the IDE know to save
the data.

Thanks for your help.

Rhy Mednick

P.S. The source code for the group of controls in development, for those
interested, is at http://chickenscratch.sourceforge.net and
http://inkmenu.sourceforge.net.


Nov 16 '05 #1
  • viewed: 3114
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chris Ericoli | last post: by
5 posts views Thread by amatuer | last post: by
9 posts views Thread by norvinl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.