CustomLineCap.Clone 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立這個 CustomLineCap的確切複本。
public:
virtual System::Object ^ Clone();
public object Clone ();
abstract member Clone : unit -> obj
override this.Clone : unit -> obj
Public Function Clone () As Object
傳回
這個方法 CustomLineCap 建立,並轉換成 物件。
實作
範例
下列範例的設計目的是要與 Windows Forms 搭配使用,而且需要 PaintEventArgse
Paint 事件物件。 程式代碼會執行下列動作:
使用 GraphicsPath 物件建立自定義行上限。
使用剛建立的 GraphicsPath 物件,建立 CustomLineCap 物件,
firstCap
。使用 Clone 方法建立
firstCap
的複本。設定 Pen 物件的 CustomStartCap 和 CustomEndCap 屬性,並使用該畫筆繪製線條和自定義大寫字母到螢幕。
Public Sub CloneExample(e As PaintEventArgs)
Dim points As Point() = New Point(- 5, - 5) New Point(0, 0) _
New Point(5, - 5)
Dim capPath As New GraphicsPath()
' Create a Path and add two lines to it,
' forming a custom line cap.
capPath.AddLines(points)
' Create a CustomLineCap object.
Dim firstCap As New CustomLineCap(Nothing, capPath)
' Create a copy of firstCap.
Dim secondCap As CustomLineCap = CType(firstCap.Clone(), _
CustomLineCap)
' Create a Pen object.
Dim pen As New Pen(Color.Black, 3F)
'Set up the line.
Dim point1 As New Point(20, 20)
Dim point2 As New Point(100, 100)
' Set up the caps.
pen.CustomStartCap = firstCap
pen.CustomEndCap = secondCap
' Draw the line and caps to the screen.
e.Graphics.DrawLine(pen, point1, point2)
End Sub
private void CloneExample(PaintEventArgs e)
{
// Create a Path and add two lines to it,
// forming a custom line cap.
Point[] points =
{
new Point(-5, -5),
new Point(0, 0),
new Point(5, -5)
};
GraphicsPath capPath = new GraphicsPath();
capPath.AddLines(points);
// Create a CustomLineCap object.
CustomLineCap firstCap = new CustomLineCap(null, capPath);
// Create a copy of firstCap.
CustomLineCap secondCap = (CustomLineCap)firstCap.Clone();
// Create a Pen object.
Pen pen = new Pen(Color.Black, 3.0f);
// Set up the line.
Point point1 = new Point(20, 20);
Point point2 = new Point(100, 100);
// Set up the caps.
pen.CustomStartCap = firstCap;
pen.CustomEndCap = secondCap;
// Draw the line and caps to the screen.
e.Graphics.DrawLine(pen, point1, point2);
}