使用 Real-Time 手寫筆範例的 Windows Touch Scratchpad (C#)

Windows Touch Scratchpad 範例 (MTScratchpadRTStylus) 示範如何使用 Windows Touch 訊息將觸控點的追蹤繪製到視窗。 第一個放在數位板上的主要手指追蹤會以黑色繪製。 次要手指會以六種其他色彩繪製:紅色、綠色、藍色、青色、magenta 和黃色。 下列螢幕擷取畫面顯示應用程式在執行時的外觀。

螢幕擷取畫面顯示幕幕快照:使用 c sharp 的即時手寫筆,在螢幕上顯示具有黑色和紅色波浪線的 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();
        }

多點觸控臨時板應用程式 (RTS/C#) 多點觸控臨時板應用程式 (RTS/C++) Windows Touch 範例