次の方法で共有


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 に設定することが役立つもう 1 つの状況は、ストロークを描画されたとおりに表示するが、ストロークを使用した後は長く保存する必要がない場合です。この場合は、データ識別子を CustomStylusDataAdded メソッドの data パラメータに格納し、キャッシュされたストロークが不要になった時点でデータを解放します。

このプロパティが true の場合は、インクの収集オブジェクトに格納されているストロークの ReleaseCachedData メソッドを呼び出す必要があります。false の場合は、ReleaseCachedData メソッドを呼び出す必要はありません。これを false に設定する欠点は、最初に動的にレンダリングされたが、他の何らかの操作によって無効にされたすべてのストローク データは、そのストローク データがインク収集オブジェクトに達してそこでレンダリングされるまでレンダリングされないことです。

このプロパティを false に設定すると、キャッシュされたデータはクリアされます。したがって、EnableDataCache プロパティが false に設定された後で、キューに保留中の DynamicRendererCachedData オブジェクトの ReleaseCachedData メソッドを呼び出すと、引数の例外が発生します。

このプロパティの詳細については、「Dynamic-Renderer Plug-ins」を参照してください。

この C# の例は、Windows SDK の「タブレットおよびタッチ テクノロジ」セクションで提供されている「RealTimeStylus Ink Collection Sample」を拡張したものです。DynamicRenderer、theDynamicRenderer を有効にした後、EnableDataCache プロパティを true に設定します。DataInterest プロパティは、DataInterestMask が追加されるように変更されます。CustomStylusDataAdded メソッドは、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 を呼び出して、キャッシュ内のタブレット ペン データを再描画します。DataInterest プロパティは、DataInterestMask が追加されるように変更されます。CustomStylusDataAdded メソッドは、DynamicRendererCachedDataGuid フィールドの識別子を使用してデータを検索し、そのデータ識別子を ArrayList の cachedIds に格納します。ClearStrokes メソッドは、cachedIds のすべての識別子に対して ReleaseCachedData を呼び出し、ControlRefresh を呼び出します。

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 を呼び出して、キャッシュ内のタブレット ペン データを再描画します。DataInterest プロパティは、DataInterestMask が追加されるように変更されます。CustomStylusDataAdded メソッドは、DynamicRendererCachedDataGuid フィールドの識別子を使用してデータを検索し、そのデータ識別子を ArrayList の cachedIds に格納します。ClearStrokes メソッドは、cachedIds のすべての識別子に対して ReleaseCachedData を呼び出し、ControlRefresh を呼び出します。

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