Home > Articles > Home & Office Computing > Entertainment/Gaming/Gadgets

  • Print
  • + Share This
Like this article? We recommend

Loading Ink

Loading Ink back into the InkCollector is a trivial matter. Once you have the saved bytes available, you call the InkCollector.Ink.Load() method. Listing 6 shows you how the sample application uses an Open File dialog box to retrieve existing byte array stored in a file using Ink Serialization Format and then attaches the retrieved byte array to an Ink object, which is then assigned to the InkCollector.Ink property.

Listing 6 Open menu item click event handler calls the application’s Open() method

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
 //Clear out any exisitng work using the custom Clear() method  
 this.Clear();
 //Call the custom Open method, passing in the InkCollector
 this.Open(inkCollector);
}
private void Open(InkCollector collector)
{
 //Get a file open dialog
 OpenFileDialog dlgOpen = new OpenFileDialog();
 //Filter for Ink Serialization Format
 dlgOpen.Filter = "ISF files (*.isf)|*.isf| All files (*.*)|*.*";
 if (dlgOpen.ShowDialog() == DialogResult.OK)
 {
  //Get the Ink Stream
  Stream stream = dlgOpen.OpenFile();
  if (stream != null && stream.Length > 0)
  {
   //Make a byte array the size of the stream
   byte[] bytes = new byte[stream.Length];
   //Read the stream into the byte array
   if (stream.Read(bytes, 0, bytes.Length) == stream.Length)
   {
    Ink ink = new Ink();
    //Load the bytes into the newly created Ink object
    ink.Load(bytes);
    //Disable the InkCollector so that you can add the local
    //Ink object that has the byte data
    collector.Enabled = false;
    //Assign the local Ink object to the InkCollector
    collector.Ink = ink;
    //Enable the InkCollector so that Ink can be added
    collector.Enabled = true;
   }
   //Close up shops
   stream.Close();
   }
 }
}
  • + Share This
  • 🔖 Save To Your Account