Metodo DynamicRenderer.ReleaseCachedData
Aggiornamento: novembre 2007
Rilascia dati della penna del Tablet PC dalla cache dell'oggetto DynamicRenderer.
Spazio dei nomi: Microsoft.StylusInput
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Sintassi
'Dichiarazione
Public Sub ReleaseCachedData ( _
cachedDataId As Integer _
)
'Utilizzo
Dim instance As DynamicRenderer
Dim cachedDataId As Integer
instance.ReleaseCachedData(cachedDataId)
public void ReleaseCachedData(
int cachedDataId
)
public:
void ReleaseCachedData(
int cachedDataId
)
public void ReleaseCachedData(
int cachedDataId
)
public function ReleaseCachedData(
cachedDataId : int
)
Parametri
- cachedDataId
Tipo: System.Int32
Identificatore dei dati da rilasciare.
Note
Questo metodo viene utilizzato solo quando la proprietà EnableDataCache è impostata su true.
L'impostazione della proprietà EnableDataCache su true consente di gestire la situazione in cui processi lenti bloccano la coda di output. Se è presente un periodo in cui la finestra viene invalidata dopo il disegno dei tratti da parte dell'oggetto DynamicRenderer, si può verificare un ritardo prima che i tratti raccolti possano essere nuovamente disegnati. Posizionando i tratti di DynamicRenderer in una cache, è possibile ridisegnarli chiamando il metodo Refresh. Tuttavia, dopo avere raccolto i tratti, rilasciarli dalla cache chiamando il metodo ReleaseCachedData. Il rilascio si verifica in genere nel metodo CustomStylusDataAdded.
Un'altra situazione in cui è utile impostare la proprietà EnableDataCache su true è quando si desidera visualizzare i tratti mentre vengono disegnati, ma dopo avere svolto una qualsiasi operazione con essi, non è più necessario archiviarli. In questo caso, archiviare gli identificatori dei dati nel parametro data del metodo CustomStylusDataAdded, quindi rilasciare i dati quando i tratti memorizzati nella cache non sono più necessari.
Esempi
In questo esempio C# viene esteso l'esempio RealTimeStylus Ink Collection Sample fornito nella sezione Tecnologia Windows per Tablet PC in Windows SDK. Dopo l'abilitazione di DynamicRenderer, theDynamicRenderer, la proprietà EnableDataCache viene impostata su true. La proprietà DataInterest viene modificata in modo che venga aggiunto DataInterestMask. Il metodo CustomStylusDataAdded cerca i dati con l'identificatore del campo DynamicRendererCachedDataGuid e successivamente li rilascia tramite la proprietà CachedDataId dei dati.
// ...
private void InkCollection_Load(object sender, System.EventArgs e)
{
// ...
// Enable the real time stylus and the dynamic renderer
theRealTimeStylus.Enabled = true;
theDynamicRenderer.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.
theDynamicRenderer.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);
}
}
// ...
In questo esempio C# i dati di un oggetto DynamicRenderer vengono posizionati in una cache. In questo modo è possibile garantire che l'annullamento della convalida di una finestra non cancelli i tratti. Nell'esempio vengono quindi cancellati i tratti a livello di codice. Dopo l'abilitazione dell'oggetto DynamicRenderer, theDynamicRenderer, la proprietà EnableDataCache viene impostata su true. Nel gestore dell'evento Paint, nell'esempio viene chiamato DynamicRenderer.Refresh per aggiornare i dati della penna del Tablet PC nella cache. La proprietà DataInterest viene modificata in modo che venga aggiunto DataInterestMask. Il metodo CustomStylusDataAdded cerca i dati con l'identificatore del campo DynamicRendererCachedDataGuid e archivia l'identificatore dati in un oggetto ArrayList, cachedIds. Il metodo ClearStrokes chiama ReleaseCachedData su tutti gli identificatori in cachedIds, quindi chiama Refresh sull'oggetto Control.
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 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(this);
// Enable the real time stylus and the dynamic renderer
theRealTimeStylus.Enabled = true;
theDynamicRenderer.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.
theDynamicRenderer.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()
}
}
In questo esempio Microsoft Visual Basic .NET i dati di un oggetto DynamicRenderervengono inseriti in una cache. In questo modo è possibile garantire che l'annullamento della convalida di una finestra non cancelli i tratti. Nell'esempio vengono quindi cancellati i tratti a livello di codice. Dopo l'abilitazione dell'oggetto DynamicRenderer, theDynamicRenderer, la proprietà EnableDataCache viene impostata su true. Nel gestore dell'evento Paint, nell'esempio viene chiamato l'oggetto DynamicRenderer.Refresh per aggiornare i dati della penna del Tablet PC nella cache. La proprietà DataInterest viene modificata in modo che venga aggiunto DataInterestMask. Il metodo CustomStylusDataAdded cerca i dati con l'identificatore del campo DynamicRendererCachedDataGuid e archivia l'identificatore dati in un oggetto ArrayList, cachedIds. La subroutine ClearStrokes chiama ReleaseCachedData su tutti gli identificatori in cachedIds, quindi chiama Refresh sull'oggetto Control.
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
Piattaforme
Windows Vista, Windows XP SP2, Windows Server 2003
.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Informazioni sulla versione
.NET Framework
Supportato in: 3.0
Vedere anche
Riferimenti
Spazio dei nomi Microsoft.StylusInput
DynamicRenderer.EnableDataCache