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 窗体,它需要 PaintEventArgse
事件Paint对象。 此代码执行以下操作:
使用 GraphicsPath 对象创建自定义线帽。
使用GraphicsPath刚刚创建的 CustomLineCap 对象
firstCap
创建 对象。使用 Clone 方法创建 的
firstCap
克隆。设置 CustomStartCap 对象的 和 CustomEndCap 属性 Pen ,并使用该笔在屏幕上绘制线条和自定义帽。
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);
}
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈