DynamicRenderer.EnableDataCache 属性

获取或设置一个值,该值指示是否为 DynamicRenderer 对象启用数据缓存。

命名空间:  Microsoft.StylusInput
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Property EnableDataCache As Boolean
用法
Dim instance As DynamicRenderer
Dim value As Boolean

value = instance.EnableDataCache

instance.EnableDataCache = value
public bool EnableDataCache { get; set; }
public:
property bool EnableDataCache {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_EnableDataCache()
/** @property */
public  void set_EnableDataCache(boolean value)
public function get EnableDataCache () : boolean
public function set EnableDataCache (value : boolean)

属性值

类型:System.Boolean
如果启用数据缓存,则为 true;否则为 false。

备注

将 EnableDataCache 属性设置为 true 可以处理缓慢进程阻塞输出队列的情况。如果有一段时间窗口在 DynamicRenderer 对象绘制了笔画之后失效,则可能在一段延迟之后才能重新绘制收集的笔画。通过将 DynamicRenderer 的笔画放入缓存中,可以通过调用 Refresh 方法重绘笔画。但是一旦收集了笔画,就应通过调用 ReleaseCachedData 方法将它们从缓存中释放。通常,释放在 CustomStylusDataAdded 方法中发生。

另一个适合将 EnableDataCache 属性设置为 true 的情况是:您希望在绘制笔画时显示笔画,但是一旦您对笔画进行了某些操作,您将不再需要存储这些笔画。在这种情况下,应将数据标识符存储在 CustomStylusDataAdded 方法的 data 参数中,然后当不再需要缓存的笔画时释放这些数据。

如果此属性为 true,则必须对已存储在墨迹回收对象中的笔画调用 ReleaseCachedData 方法。如果为 false,则无需调用 ReleaseCachedData 方法。将此属性设置为 false 的缺点是:如果有任何笔画数据在初始动态呈现之后因其他各种操作而失效,那么这些笔画数据直到在到达墨迹收集对象并在那里呈现时才会呈现出来。

将此属性设置为 false 会清除缓存的数据。因此,在将 EnableDataCache 属性设置为 false 之后,当代码对队列中任何挂起的 DynamicRendererCachedData 对象调用 ReleaseCachedData 方法时将引发参数异常。

有关此属性的更多信息,请参见Dynamic-Renderer Plug-ins

示例

此 C# 示例扩展了 Windows SDK 的“Tablet 和触摸技术”部分中提供的 RealTimeStylus Ink Collection Sample。在启用了 DynamicRenderer (theDynamicRenderer) 之后,将 EnableDataCache 属性设置为 true。对 DataInterest 属性进行了修改,从而添加了 DataInterestMaskCustomStylusDataAdded 方法查找具有 DynamicRendererCachedDataGuid 字段标识符的数据,然后通过使用数据的 CachedDataId 属性来释放数据。

// ...
private void InkCollection_Load(object sender, System.EventArgs e)
{
    // ...
    
    // Enable the real time stylus and the dynamic renderer
    myRealTimeStylus.Enabled = true;
    myDynamicRenderer.Enabled = true;  

    // Enable caching. If a refresh happens during inking, then
    // the stroke will still be displayed.  However, we have to 
    // release the cached data later.
    myDynamicRenderer.EnableDataCache = true;
    
    // ...
}
// ...
public DataInterestMask DataInterest
{
    get
    {
        return DataInterestMask.StylusDown |
               DataInterestMask.Packets |
               DataInterestMask.StylusUp |
               DataInterestMask.Error |
               DataInterestMask.CustomStylusDataAdded;
    }
}
public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data)
{
    // Release any cached data that's shown up.
    if (data.CustomDataId == DynamicRenderer.DynamicRendererCachedDataGuid)
    {
        DynamicRendererCachedData cachedData = (DynamicRendererCachedData) data.Data;
       cachedData.DynamicRenderer.ReleaseCachedData(cachedData.CachedDataId);
    }
}
// ...

此 C# 示例将 DynamicRenderer 对象中的数据放入缓存中。这样做可以确保窗口失效时不会擦除笔画。然后,此示例以编程方式清除笔画。在启用了 DynamicRenderer 对象 theDynamicRenderer 之后,将 EnableDataCache 属性设置为 true。在 Paint 事件处理程序中,示例调用 DynamicRenderer.Refresh 以重绘缓存中的 Tablet 笔数据。对 DataInterest 属性进行了修改,从而添加了 DataInterestMaskCustomStylusDataAdded 方法查找具有 DynamicRendererCachedDataGuid 字段标识符的数据,然后将数据标识符存储到 ArrayList (cachedIds) 中。ClearStrokes 方法对 cachedIds 中的所有标识符调用 ReleaseCachedData,然后对 Control 调用 Refresh

using Microsoft.StylusInput;
using Microsoft.StylusInput.PluginData;
// ...
public class InkCollection : Form, IStylusAsyncPlugin
{ 
    private RealTimeStylus theRealTimeStylus;
    private DynamicRenderer theDynamicRenderer;
    private ArrayList cachedIds = new ArrayList();
// ...
    private void TempInkCollection_Load(object sender, System.EventArgs e)
    {
        theDynamicRenderer = new DynamicRenderer(this);
        theRealTimeStylus = new RealTimeStylus(this, true);

        ' Add the dynamic renderer to the synchronous plugin notification chain.
        ' Synchronous notifications occur on the pen thread.
        theRealTimeStylus.SyncPluginCollection.Add(theDynamicRenderer)

        // Add the dynamic renderer to the synchronous plugin notification chain.
        // Synchronous notifications occur on the pen thread.
        myRealTimeStylus.SyncPluginCollection.Add(myDynamicRenderer);

        // Add the form to the asynchronous plugin notification chain.  This plugin
        // will be used to collect stylus data into an ink object.  Asynchronous
        // notifications occur on the UI thread.
        myRealTimeStylus.AsyncPluginCollection.Add(this);

        // Enable the real time stylus and the dynamic renderer
        myRealTimeStylus.Enabled = true;
        myDynamicRenderer.Enabled = true;  

        // Enable caching. If a refresh happens during inking, then
        // the stroke will still be displayed.  However, we have to 
        // release the cached data later.
        myDynamicRenderer.EnableDataCache = true;
    }
// ...
    private void InkCollection_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        // Refresh the dynamic renderer, since it's possible that a stroke is being
        // collected at the time Paint occurs.  In this case, the portion of the stroke
        // that has already been collected will need to be redrawn.
        theDynamicRenderer.ClipRectangle = e.ClipRectangle;
        theDynamicRenderer.Refresh();
    }
// ...
    public DataInterestMask DataInterest
    {
        get
        {
            return DataInterestMask.CustomStylusDataAdded;
        }
    }

    public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data)
    {
        // Release any cached data that's shown up.
        if (data.CustomDataId == DynamicRenderer.DynamicRendererCachedDataGuid)
        {
            DynamicRendererCachedData cachedData = (DynamicRendererCachedData) data.Data;
            cachedIds.Add(cachedData.CachedDataId);
        }
    }
// ...
    private void ClearStrokes()
    {
        // Release all data
        foreach int dataId in cachedIds
        {
            theDynamicRenderer.ReleaseCachedData(dataId);
        }
        // Clear our stored list of Ids
        cachedIds.Clear();
        // Refresh the window
        this.Refresh()
    }
}

此 Microsoft Visual Basic .NET 示例将 DynamicRenderer 对象中的数据放入缓存中。这样做可以确保窗口失效时不会擦除笔画。然后,此示例以编程方式清除笔画。在启用了 DynamicRenderer 对象 theDynamicRenderer 之后,将 EnableDataCache 属性设置为 true。在 Paint 事件处理程序中,示例调用 DynamicRenderer.Refresh 以重绘缓存中的 Tablet 笔数据。对 DataInterest 属性进行了修改,从而添加了 DataInterestMaskCustomStylusDataAdded 方法查找具有 DynamicRendererCachedDataGuid 字段标识符的数据,然后将数据标识符存储到 ArrayList (cachedIds) 中。ClearStrokes 方法对 cachedIds 中的所有标识符调用 ReleaseCachedData,然后对 Control 调用 Refresh

Imports Microsoft.StylusInput
Imports Microsoft.StylusInput.PluginData
' ...
Public Class TempInkCollector
    Inherits System.Windows.Forms.Form
    Implements Microsoft.StylusInput.IStylusAsyncPlugin

    Private theRealTimeStylus As RealTimeStylus
    Private theDynamicRenderer As DynamicRenderer
    Private cachedIds As ArrayList = New ArrayList()
' ...
    Private Sub TempInkCollector_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        theDynamicRenderer = New DynamicRenderer(Me)
        theRealTimeStylus = New RealTimeStylus(Me, True)

        ' Add the dynamic renderer to the synchronous plugin notification chain.
        ' Synchronous notifications occur on the pen thread.
        theRealTimeStylus.SyncPluginCollection.Add(theDynamicRenderer)

        ' Add the form to the asynchronous plugin notification chain.  This plugin
        ' will be used to collect stylus data into an ink object.  Asynchronous
        ' notifications occur on the UI thread.
        theRealTimeStylus.AsyncPluginCollection.Add(Me)

        ' Enable the real time stylus and the dynamic renderer
        theRealTimeStylus.Enabled = True
        theDynamicRenderer.Enabled = True
        theDynamicRenderer.EnableDataCache = True
    End Sub
' ...
    Private Sub InkCollector_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        ' Refresh the dynamic renderer, since it's possible that a stroke is being
        ' collected at the time Paint occurs.  In this case, the portion of the stroke
        ' that has already been collected will need to be redrawn.
        theDynamicRenderer.ClipRectangle = e.ClipRectangle
        theDynamicRenderer.Refresh()
    End Sub
'...
    Overridable Overloads ReadOnly Property DataInterest() As DataInterestMask Implements IStylusAsyncPlugin.DataInterest
        Get
            Return DataInterestMask.CustomStylusDataAdded
        End Get
    End Property
    Public Sub CustomStylusDataAdded(ByVal sender As Microsoft.StylusInput.RealTimeStylus, ByVal data As Microsoft.StylusInput.PluginData.CustomStylusData) Implements Microsoft.StylusInput.IStylusAsyncPlugin.CustomStylusDataAdded
        If data.CustomDataId.Equals(DynamicRenderer.DynamicRendererCachedDataGuid) Then
            ' Convert to DynamicRendererCachedData
            Dim cachedData As DynamicRendererCachedData = data.Data
            ' Add to list of ids.
            cachedIds.Add(cachedData.CachedDataId)
        End If
    End Sub
' ...
    Private Sub ClearStrokes()
        ' Release all data
        Dim dataId As Integer
        For Each dataId In cachedIds
            theDynamicRenderer.ReleaseCachedData(dataId)
        Next
        ' Clear our stored list of Ids
        cachedIds.Clear()
        ' Refresh the window
        Me.Refresh()
    End Sub
End Class

平台

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

DynamicRenderer 类

DynamicRenderer 成员

Microsoft.StylusInput 命名空间

DynamicRendererCachedData

DynamicRenderer.ReleaseCachedData

DynamicRenderer.Refresh

其他资源

Dynamic-Renderer Plug-ins