使用 Real-Time 触笔示例 (C#) 的 Windows 触控暂存板
Windows Touch Scratchpad 示例 (MTScratchpadRTStylus) 演示了如何使用 Windows 触控消息将触摸点的痕迹绘制到窗口。 第一个放在数字化器上的主手指的痕迹以黑色绘制。 辅助手指以其他六种颜色绘制:红色、绿色、蓝色、青色、洋红色和黄色。 以下屏幕截图显示了应用程序在运行时的外观。
对于此示例,将创建 Real-Time Stylus (RTS) 对象并启用对多个接触点的支持。 将 DynamicRenderer 插件添加到 RTS 以呈现内容。 实现插件 EventHandlerPlugIn,用于跟踪手指的数量并更改动态呈现器正在绘制的颜色。 在 RTS 插件堆栈中这两个插件中,Windows Touch Scratchpad 应用程序将以黑色呈现主触点,其余触点呈现各种颜色。
以下代码演示 EventHandlerPlugIn 如何递增和递减触点的计数并设置动态呈现器的颜色。
public void StylusDown(RealTimeStylus sender, StylusDownData data)
{
// Set new stroke color to the DrawingAttributes of the DynamicRenderer
// If there are no fingers down, this is a primary contact
dynamicRenderer.DrawingAttributes.Color = touchColor.GetColor(cntContacts == 0);
++cntContacts; // Increment finger-down counter
}
public void StylusUp(RealTimeStylus sender, StylusUpData data)
{
--cntContacts; // Decrement finger-down counter
}
以下代码演示如何创建具有多个联系点支持的 RTS。
private void OnLoadHandler(Object sender, EventArgs e)
{
// Create RealTimeStylus object and enable it for multi-touch
realTimeStylus = new RealTimeStylus(this);
realTimeStylus.MultiTouchEnabled = true;
// Create DynamicRenderer and event handler, and add them to the RTS object as synchronous plugins
dynamicRenderer = new DynamicRenderer(this);
eventHandler = new EventHandlerPlugIn(this.CreateGraphics(), dynamicRenderer);
realTimeStylus.SyncPluginCollection.Add(eventHandler);
realTimeStylus.SyncPluginCollection.Add(dynamicRenderer);
// Enable RTS and DynamicRenderer object, and enable auto-redraw of the DynamicRenderer
realTimeStylus.Enabled = true;
dynamicRenderer.Enabled = true;
dynamicRenderer.EnableDataCache = true;
}
在 DynamicRenderer 对象的颜色更改并绘制了笔划后,调用 DynamicRenderer::Refresh 将导致出现新的笔划。 以下代码演示如何在 OnPaintHandler 方法中执行此操作。
private void OnPaintHandler(object sender, PaintEventArgs e)
{
// Erase the background
Brush brush = new SolidBrush(SystemColors.Window);
e.Graphics.FillRectangle(brush, ClientRectangle);
// Ask DynamicRenderer to redraw itself
dynamicRenderer.Refresh();
}
相关主题
多点触控 Scratchpad 应用程序 (RTS/C#) 、 多点触控 Scratchpad 应用程序 (RTS/C++) 、 Windows 触控示例