更新:2007 年 11 月
命名空间:
System.Windows.Shapes 程序集:
PresentationFramework(在 PresentationFramework.dll 中)
用于 XAML 的 XMLNS:http://schemas.microsoft.com/winfx/xaml/presentation
Public NotInheritable Class Rectangle _
Inherits Shape
Dim instance As Rectangle
public sealed class Rectangle : Shape
public ref class Rectangle sealed : public Shape
public final class Rectangle extends Shape
public final class Rectangle extends Shape
下面的示例演示如何使用代码创建 Rectangle 元素并设置其属性。有关完整的示例,请参见 WPF 形状库示例。
'Add a Rectangle Element
Dim myRect As New Rectangle()
myRect.Stroke = Brushes.Black
myRect.Stroke = Brushes.Black
myRect.Fill = Brushes.SkyBlue
myRect.HorizontalAlignment = HorizontalAlignment.Left
myRect.VerticalAlignment = VerticalAlignment.Center
myRect.Height = 50
myRect.Width = 50
myGrid.Children.Add(myRect)
// Add a Rectangle Element
myRect = new System.Windows.Shapes.Rectangle();
myRect.Stroke = System.Windows.Media.Brushes.Black;
myRect.Fill = System.Windows.Media.Brushes.SkyBlue;
myRect.HorizontalAlignment = HorizontalAlignment.Left;
myRect.VerticalAlignment = VerticalAlignment.Center;
myRect.Height = 50;
myRect.Width = 50;
myGrid.Children.Add(myRect);
更多代码
| 如何:绘制矩形 | 下面的示例演示如何使用 Rectangle 元素来绘制矩形。 |
System..::.Object
System.Windows.Threading..::.DispatcherObject
System.Windows..::.DependencyObject
System.Windows.Media..::.Visual
System.Windows..::.UIElement
System.Windows..::.FrameworkElement
System.Windows.Shapes..::.Shape
System.Windows.Shapes..::.Rectangle
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
.NET Framework
受以下版本支持:3.5、3.0
参考
其他资源