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 之<平板和觸控技術>一節中提供的 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 欄位之識別項的資料,並將資料識別項儲存至名為 cachedIds 的 ArrayList (英文) 中。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 以重繪快取中的手寫板畫筆資料。接著會修改 DataInterest 屬性以加入 DataInterestMask。CustomStylusDataAdded 方法會尋找具有 DynamicRendererCachedDataGuid 欄位之識別項的資料,並將資料識別項儲存至名為 cachedIds 的 ArrayList (英文) 中。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.ReleaseCachedData