WPF繪圖

      在〈WPF繪圖〉中有 1 則留言

扇形

Polygon p = new Polygon();
p.Fill = new SolidColorBrush(Colors.Red);
p.Points.Add(new Point(100, 100));
for (int i = 135; i <225 ; i++)
{
    Point point = new Point()
    {
        X = 100 + Math.Sin(i * Math.PI / 180.0) * 100,
        Y = 100 + Math.Cos(i * Math.PI / 180.0) * 100,
    };
    p.Points.Add(point);
}
p.Points.Add(new Point(100, 100));
canvas.Children.Add(p);

sector

xaml寫法

<Grid>
    <Canvas x:Name="canvas">
        <Path Stroke="Blue" Fill="Yellow">
            <Path.Data>
                <GeometryGroup FillRule="Nonzero">
                    <PathGeometry>
                        <PathFigure StartPoint="100,0">
                            <ArcSegment Point="200,100" Size="100,100" SweepDirection="Clockwise"/>
                            <LineSegment Point="100,100"/>
                            <LineSegment Point="100,0"/>
                        </PathFigure>
                    </PathGeometry>
                </GeometryGroup>
            </Path.Data>
            <Path.RenderTransform>
                <TransformGroup>
                    <RotateTransform CenterX="100" CenterY="100" Angle="-45"/>
                    <ScaleTransform CenterX="100" CenterY="100" ScaleX="1"/>
                    <MatrixTransform Matrix="0,1,1,0,0,0"/>
                    <TranslateTransform X="100" Y="000"/>
                </TransformGroup>
            </Path.RenderTransform>
        </Path>
    </Canvas>
</Grid>

sector1

圓餅圖

<Button x:Name="btn3" Width="80" Height="80" Margin="5,0,5,5">
	<Canvas>
		<Path Fill="Yellow">
			<Path.Data>
				<PathGeometry>
					<PathFigure StartPoint="0, 35">
						<ArcSegment Point="35,0" Size="35,35" SweepDirection="Counterclockwise"/>
						<LineSegment Point="0,0"/>
						<LineSegment Point="0,35"/>
					</PathFigure>
				</PathGeometry>
			</Path.Data>
			<Path.RenderTransform>
				<TransformGroup>
					<RotateTransform CenterX="0" CenterY="0" Angle="35"/>
					<TranslateTransform X="0" Y="0"/>
				</TransformGroup>
			</Path.RenderTransform>
		</Path>
		<Path Fill="Green">
			<Path.Data>
				<PathGeometry>
					<PathFigure StartPoint="0, 35">
						<ArcSegment Point="35,0" Size="35,35" SweepDirection="Counterclockwise"/>
						<LineSegment Point="0,0"/>
						<LineSegment Point="0,35"/>
					</PathFigure>
				</PathGeometry>
			</Path.Data>
			<Path.RenderTransform>
				<TransformGroup>
					<RotateTransform CenterX="0" CenterY="0" Angle="125"/>
					<TranslateTransform X="0" Y="0"/>
				</TransformGroup>
			</Path.RenderTransform>
		</Path>
		<Path Fill="Red">
			<Path.Data>
				<PathGeometry>
					<PathFigure StartPoint="0, 35">
						<ArcSegment Point="35,0" Size="35,35" SweepDirection="Counterclockwise"/>
						<LineSegment Point="0,0"/>
						<LineSegment Point="0,35"/>
					</PathFigure>
				</PathGeometry>
			</Path.Data>
			<Path.RenderTransform>
				<TransformGroup>
					<RotateTransform CenterX="0" CenterY="0" Angle="215"/>
					<TranslateTransform X="0" Y="0"/>
				</TransformGroup>
			</Path.RenderTransform>
		</Path>
		<Path Fill="LightBlue">
			<Path.Data>
				<PathGeometry>
					<PathFigure StartPoint="0, 35">
						<ArcSegment Point="35,0" Size="35,35" SweepDirection="Counterclockwise"/>
						<LineSegment Point="0,0"/>
						<LineSegment Point="0,35"/>
					</PathFigure>
				</PathGeometry>
			</Path.Data>
			<Path.RenderTransform>
				<TransformGroup>
					<RotateTransform CenterX="0" CenterY="0" Angle="305"/>
					<TranslateTransform X="0" Y="0"/>
				</TransformGroup>
			</Path.RenderTransform>
		</Path>
	</Canvas>
</Button>

circle

立体球

<Button x:Name="btn4" Width="80" Height="80" Margin="0,0,0,5">
	<Ellipse Height="70"  Name="ellipse1" Stroke="Gray" Width="70" Cursor="Hand" ToolTip="A Ball">
		<Ellipse.Fill>
			<RadialGradientBrush GradientOrigin="0.2,0.8" RadiusX="0.75" RadiusY="0.75">
				<RadialGradientBrush.RelativeTransform>
					<TransformGroup>
						<RotateTransform Angle="90" CenterX="0.5" CenterY="0.5"></RotateTransform>
					</TransformGroup>
				</RadialGradientBrush.RelativeTransform>
				<GradientStop Color="#FFFFFFFF" Offset="0" />
				<GradientStop Color="#FF444444" Offset="0.66" />
				<GradientStop Color="#FF999999" Offset="1" />
			</RadialGradientBrush>
		</Ellipse.Fill>
	</Ellipse>
</Button>

ball

1 thought on “WPF繪圖

  1. Bonus d'inscription à Binance

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *