共用方式為


使用畫筆清除

如果您選擇在應用程式中實作清除,而不是使用 InkOverlay 物件,您可以使用下列兩種方法之一來執行此動作。

使用手寫筆的秘訣

平板電腦手寫筆的提示通常用於手寫和繪圖;不過,提示也可以用來清除筆跡。 若要這樣做,應用程式必須具有使用者可採用的清除模式。 在此模式中,使用點擊測試來判斷游標移動的筆跡。 您可以根據設計或功能考慮,將清除模式設定為只刪除游標所傳遞的筆跡或整個筆劃,這些筆劃會與游標路徑交集。

如需如何使用清除模式清除筆跡的範例,請參閱 筆跡清除範例

使用畫筆頂端

若要使用平板電腦手寫筆頂端實作清除,您的應用程式必須尋找游標中的變更。 若要尋找反轉的資料指標,請接聽 CursorInRange 事件,以判斷游標在應用程式的內容中。 當游標位於範圍內時,請在Cursor物件上尋找反轉屬性。 如果 Inverted 屬性 為 true,請執行點擊測試來判斷游標移動的筆跡。 根據設計或功能考慮,清除與游標路徑交集的筆墨或筆劃。

如需如何使用手寫筆頂端清除筆跡的範例,請參閱 筆跡清除範例

判斷是否已啟用畫筆頂端的清除

如果使用者的特定硬體允許,使用者可以使用手寫筆頂端來清除專為平板電腦設計的應用程式中的筆跡。 此功能是由 [平板電腦和手寫筆設定] 控制台對話方塊之 [手寫筆選項] 索引標籤上的 [手寫筆] 按鈕群組方塊中的核取方塊來存取。 若要偵測使用者是否已啟用手寫筆頂端的清除功能,請檢查下列登錄子機碼:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\WISP\PEN\SysEventParameters

EraseEnable此子機碼的專案類型為REG_DWORD。 此專案的值為 1 表示已啟用,或停用為 0。 保留其他值供以後使用。

如果您的應用程式允許筆頂端用於清除,您應該檢查並快取 EraseEnable 專案的值,

  • 您的應用程式隨即啟動。
  • 每當您的應用程式在失去焦點之後收到焦點時。

使用此快取值來適當地修改應用程式的行為。

下列 C# 範例會定義檢查 GetEraseEnabled 子機碼專案 SysEventParametersEraseEnable 的方法。 如果專案值為 1,則 GetEraseEnabled 方法會傳回 TRUE ;如果專案值為 0,則會傳回 FALSE ;如果專案的值不是 1 或 0,則會擲回 InvalidOperationException 例外狀況。 如果子機碼或專案不存在,此方法 GetEraseEnabled 會傳回預期的 TRUE 值。

private bool GetEraseEnabled()
{
    // 0 is disabled, 1 is enabled. The default is enabled
    const int Enabled = 1;
    const int Disabled = 0;
    const int DefaultValue = Enabled;

    // Constants for the registry subkey and the entry
    const string Subkey =
                @"SOFTWARE\Microsoft\WISP\PEN\SysEventParameters";
    const string KeyEntry = "EraseEnable";

    // Open the registry subkey.
    Microsoft.Win32.RegistryKey regKey =
        Microsoft.Win32.Registry.CurrentUser.OpenSubKey(Subkey);

    // Retrieve the value of the EraseEnable subkey entry. If either
    // the subkey or the entry does not exist, use the default value.
    object keyValue = (null == regKey) ? DefaultValue :
        regKey.GetValue(KeyEntry,DefaultValue);

    switch((int)keyValue)
    {
        case Enabled:
            // Return true if erasing on pen inversion is enabled. 
            return true;
        case Disabled:
            // Return false if erasing on pen inversion is disabled. 
            return false;
        default:
            // Otherwise, throw an exception. Do not assume this is
            // a Boolean value. Enabled and Disabled are the values
            // defined for this entry at this time. Other values are
            // reserved for future use.
            throw new InvalidOperationException(
                "Unexpected registry subkey value.");
    }
}