StylusPoint.PressureFactor 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个介于 0 和 1 之间的值,以反映在创建 StylusPoint 时,触笔施加于数字化仪图面的压力大小。
public:
property float PressureFactor { float get(); void set(float value); };
public float PressureFactor { get; set; }
member this.PressureFactor : single with get, set
Public Property PressureFactor As Single
属性值
介于 0 和 1 之间的值,用于指示在创建 StylusPoint 时,触笔施加于数字化仪图面的压力大小。
例外
将 PressureFactor 属性设置为一个小于 0 或大于 1 的值。
示例
以下示例使用 PressureFactor 属性检索并显示名为 points
的 中StylusPointCollection每个 StylusPoint 的压力值。 此示例假定有一个名为 TextBlock 的 packetOutput
。
private void WriteStylusPointValues(StylusPointCollection points)
{
StylusPointDescription pointsDescription = points.Description;
ReadOnlyCollection<StylusPointPropertyInfo> properties =
pointsDescription.GetStylusPointProperties();
// Write the name and value of each property in
// every stylus point.
StringWriter packetWriter = new StringWriter();
packetWriter.WriteLine("{0} stylus points", points.Count.ToString());
foreach (StylusPoint stylusPoint in points)
{
packetWriter.WriteLine("Stylus Point info");
packetWriter.WriteLine("X: {0}", stylusPoint.X.ToString());
packetWriter.WriteLine("Y: {0}", stylusPoint.Y.ToString());
packetWriter.WriteLine("Pressure: {0}", stylusPoint.PressureFactor.ToString());
// Get the property name and value for each StylusPoint.
// Note that this loop reports the X, Y, and pressure values differantly than
// getting their values above.
for (int i = 0; i < pointsDescription.PropertyCount; ++i)
{
StylusPointProperty currentProperty = properties[i];
// GetStylusPointPropertyName is defined below and returns the
// name of the property.
packetWriter.Write("{0}: ", GetStylusPointPropertyName(currentProperty));
packetWriter.WriteLine(stylusPoint.GetPropertyValue(currentProperty).ToString());
}
packetWriter.WriteLine();
}
packetOutput.Text = packetWriter.ToString();
}
Private Sub WriteStylusPointValues(ByVal points As StylusPointCollection)
Dim pointsDescription As StylusPointDescription = points.Description
Dim properties As ReadOnlyCollection(Of StylusPointPropertyInfo) = _
pointsDescription.GetStylusPointProperties()
' Write the name and value of each property in
' every stylus point.
Dim packetWriter As New StringWriter()
packetWriter.WriteLine("{0} stylus points", points.Count.ToString())
For Each stylusPoint As StylusPoint In points
packetWriter.WriteLine("Stylus Point info")
packetWriter.WriteLine("X: {0}", stylusPoint.X.ToString())
packetWriter.WriteLine("Y: {0}", stylusPoint.Y.ToString())
packetWriter.WriteLine("Pressure: {0}", stylusPoint.PressureFactor.ToString())
' Get the property name and value for each StylusPoint.
' Note that this loop reports the X, Y, and pressure values differantly than
' getting their values above.
For i As Integer = 0 To pointsDescription.PropertyCount - 1
Dim currentProperty As StylusPointProperty = properties(i)
' GetStylusPointPropertyName is defined below and returns the
' name of the property.
packetWriter.Write("{0}: ", GetStylusPointPropertyName(currentProperty))
packetWriter.WriteLine(stylusPoint.GetPropertyValue(currentProperty).ToString())
Next i
packetWriter.WriteLine()
Next stylusPoint
packetOutput.Text = packetWriter.ToString()
End Sub
// Use reflection to get the name of currentProperty.
private string GetStylusPointPropertyName(StylusPointProperty currentProperty)
{
Guid guid = currentProperty.Id;
// Iterate through the StylusPointProperties to find the StylusPointProperty
// that matches currentProperty, then return the name.
foreach (FieldInfo theFieldInfo
in typeof(StylusPointProperties).GetFields())
{
StylusPointProperty property = (StylusPointProperty) theFieldInfo.GetValue(currentProperty);
if (property.Id == guid)
{
return theFieldInfo.Name;
}
}
return "Not found";
}
' Use reflection to get the name of currentProperty.
Private Function GetStylusPointPropertyName(ByVal currentProperty As StylusPointProperty) As String
Dim guid As Guid = currentProperty.Id
' Iterate through the StylusPointProperties to find the StylusPointProperty
' that matches currentProperty, then return the name.
Dim theFieldInfo As FieldInfo
For Each theFieldInfo In GetType(StylusPointProperties).GetFields()
Dim pointProperty As StylusPointProperty = _
CType(theFieldInfo.GetValue(currentProperty), StylusPointProperty)
If pointProperty.Id = guid Then
Return theFieldInfo.Name
End If
Next theFieldInfo
Return "Not found"
End Function 'GetStylusPointPropertyName
注解
属性的值 PressureFactor 表示为介于 0 和 1 之间的值。 值为 0 表示未施加压力,而值为 1 表示应用的最大压力量。 值为 0.5 表示应用最大压力的 50%,依此而过。