設定要在 InkOverlay 物件內重新繪製筆墨的矩形。
命名空間: Microsoft.Ink
組件: Microsoft.Ink (在 Microsoft.Ink.dll 中)
語法
'宣告
Public Sub Draw ( _
rDrawRect As Rectangle _
)
'用途
Dim instance As InkOverlay
Dim rDrawRect As Rectangle
instance.Draw(rDrawRect)
public void Draw(
Rectangle rDrawRect
)
public:
void Draw(
Rectangle rDrawRect
)
public void Draw(
Rectangle rDrawRect
)
public function Draw(
rDrawRect : Rectangle
)
參數
- rDrawRect
型別:System.Drawing.Rectangle
要在像素座標中重新繪製筆墨的矩形。
備註
當 rDrawRect 參數為 nullNull 參照 (即 Visual Basic 中的 Nothing) (在 Microsoft Visual Basic .NET 中為 Nothing),會重繪整個視窗。
對已利用程式設計方式變更的筆劃進行重繪是這個方法的標準用法。您也可以呼叫 Control.Invalidate (英文) 方法,但這會導致無法重繪所有 InkOverlay 物件的筆劃。您還可以呼叫 Renderer.Draw 方法來達到這個目的,但是 Renderer 物件無法繪製任何選取的筆劃,因為並不了解哪些筆劃是在 Selection 集合內。
注意事項: |
|---|
若要進行繪製,必須將 AutoRedraw 屬性設定為 true。 |
範例
這個 C# 範例是一個變更 Strokes 集合內所有筆劃色彩的方法,而此集合屬於與 InkOverlay 物件 (變數名稱為 theInkOverlay) 關聯的 Ink 物件。變更 Stroke 物件的 DrawingAttributes 屬性並不會自動且立即可見。您可以在與 theInkOverlay 關聯的控制項上呼叫 Invalidate (英文) 或 Refresh (英文) 方法,但這會導致重繪 theInkOverlay 中的所有 Stroke 物件。為了達到最佳效能,應該在 Strokes 集合的周框方塊上使用 Draw 方法。請注意,這意味著將周框方塊從筆墨空間座標轉換為像素座標。
private void ChangeColor(Strokes theStrokes, Color newColor)
{
// Change the color of theStrokes
foreach (Stroke stroke in theStrokes)
{
stroke.DrawingAttributes.Color = newColor;
}
// Convert bounding box to pixel coordinates
Graphics g = CreateGraphics();
Rectangle strokesBounds = theStrokes.GetBoundingBox();
Point topLeft = strokesBounds.Location;
Point bottomRight = strokesBounds.Location + strokesBounds.Size;
theInkOverlay.Renderer.InkSpaceToPixel(g, ref topLeft);
theInkOverlay.Renderer.InkSpaceToPixel(g, ref bottomRight);
g.Dispose()
strokesBounds = new Rectangle(topLeft,
new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));
// Redraw the strokes
theInkOverlay.Draw(strokesBounds);
}
這個 Visual Basic .NET 範例是一個變更 Strokes 集合內所有筆劃色彩的方法,而此集合屬於與 InkOverlay 物件 (變數名稱為 theInkOverlay) 關聯的 Ink 物件。變更 Stroke 物件的 DrawingAttributes 屬性並不會自動且立即可見。您可以在與 theInkOverlay 關聯的控制項上呼叫 Invalidate (英文) 或 Refresh (英文) 方法,但這會導致重繪 theInkOverlay 中的所有 Stroke 物件。為了達到最佳效能,應該在 Strokes 集合的周框方塊上使用 Draw 方法。請注意,這意味著將周框方塊從筆墨空間座標轉換為像素座標。
Private Sub ChangeColor(ByVal theStrokes As Strokes, ByVal newColor As Color)
' Change the color of theStrokes
Dim theStroke As Stroke
For Each theStroke In theStrokes
theStroke.DrawingAttributes.Color = newColor
Next
'Convert bounding box to pixel coordinates
Dim g As Graphics = CreateGraphics()
Dim strokesBounds As Rectangle = theStrokes.GetBoundingBox()
Dim topLeft As Point = strokesBounds.Location
Dim bottomRight As Point = New Point(strokesBounds.Right, strokesBounds.Bottom)
theInkOverlay.Renderer.InkSpaceToPixel(g, topLeft)
theInkOverlay.Renderer.InkSpaceToPixel(g, bottomRight)
g.Dispose()
strokesBounds = New Rectangle(topLeft, _
New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y))
'Redraw the strokes
theInkOverlay.Draw(strokesBounds)
End Sub
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Framework
支援版本:3.0
注意事項: