Пример #1
0
        // This function will load ISF into the ink object.
        // It will also pull the data stored in the object's extended properties and
        // repopulate the text boxes.
        private void LoadISF(Stream s)
        {
            Microsoft.Ink.Ink loadedInk = new Microsoft.Ink.Ink();
            byte[]            isfBytes  = new byte[s.Length];

            // read in the ISF
            s.Read(isfBytes, 0, (int)s.Length);

            // load the ink into a new ink object
            // once an ink object has been "dirtied" it can never load ink again
            loadedInk.Load(isfBytes);

            // temporarily disable the ink collector and swap ink objects
            // We checked the InkCollector.CollectingInk property to verify
            // the user has stopped inking. Otherwise, Enabled will throw
            // InvalidOperationException.
            ic.Enabled = false;

            ic.Ink     = loadedInk;
            ic.Enabled = true;

            // Repaint the inkable region
            Signature.Invalidate();

            ExtendedProperties inkProperties = ic.Ink.ExtendedProperties;

            // Get the raw data out of this stroke's extended
            // properties list, using our previously defined
            // Guid as a key to the extended property we want.
            // Since the save method stored the first and last
            // name information as extended properties, we can
            // remove this information now that the load is complete.
            if (inkProperties.DoesPropertyExist(FirstName))
            {
                FirstNameBox.Text = (String)inkProperties[FirstName].Data;
                inkProperties.Remove(FirstName);
            }
            else
            {
                FirstNameBox.Text = String.Empty;
            }

            if (inkProperties.DoesPropertyExist(LastName))
            {
                LastNameBox.Text = (String)inkProperties[LastName].Data;
                inkProperties.Remove(LastName);
            }
            else
            {
                LastNameBox.Text = String.Empty;
            }
        }
Пример #2
0
        // This function saves the form in ISF format.
        // It uses ExtendedProperties to preserve the first and last names.
        // ExtendedProperties are an easy way to store non-ink data within an
        // ink object. In this case, there is no outer format which contains the
        // ink, so the only place to store the names is within the ink object itself.
        private void SaveISF(Stream s)
        {
            byte[] isf;

            // This is the ink object which will be serialized
            ExtendedProperties inkProperties = ic.Ink.ExtendedProperties;

            // Store the name fields in the ink object
            // These fields will roundtrip through the ISF format
            // Ignore empty fields since strictly empty strings
            //       cannot be stored in ExtendedProperties.
            if (FirstNameBox.Text.Length > 0)
            {
                inkProperties.Add(FirstName, FirstNameBox.Text);
            }
            if (LastNameBox.Text.Length > 0)
            {
                inkProperties.Add(LastName, LastNameBox.Text);
            }

            // Perform the serialization
            isf = ic.Ink.Save(PersistenceFormat.InkSerializedFormat);

            // If the first and last names were added as extended
            // properties to the ink, remove them - these properties
            // are only used for the save and there is no need to
            // keep them around on the ink object.
            if (inkProperties.DoesPropertyExist(FirstName))
            {
                inkProperties.Remove(FirstName);
            }
            if (inkProperties.DoesPropertyExist(LastName))
            {
                inkProperties.Remove(LastName);
            }

            // Write the ISF to the stream
            s.Write(isf, 0, isf.Length);
        }