Dynamic Clipping : Clip « Windows Presentation Foundation « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows Presentation Foundation » Clip 
16.85.1.Dynamic Clipping
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
  mc:Ignorable="d"
  x:Class="PaintDrawExamples.DynamicClipping" 
  Width="640" Height="480">

    <StackPanel.Resources>
        <Storyboard x:Key="OnLoaded"/>
    </StackPanel.Resources>
    <StackPanel.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard x:Name="OnLoaded_BeginStoryboard" Storyboard="{DynamicResource OnLoaded}"/>
        </EventTrigger>
    </StackPanel.Triggers>
    <Canvas Height="100" x:Name="Canvas" Width="436">
        <Canvas.Clip>
            <PathGeometry>
                <PathFigure StartPoint="1,5" IsClosed="True" IsFilled="True">
                    <BezierSegment IsSmoothJoin="True" Point1="2,2" Point2="26,1" Point3="24,127" IsStroked="True"/>
                    <BezierSegment IsSmoothJoin="True" Point1="1,1" Point2="14,9" Point3="19,5" IsStroked="True"/>
                    <BezierSegment IsSmoothJoin="True" Point1="14,11" Point2="18,-22.5" Point3="24,-2" IsStroked="True"/>
                    <BezierSegment IsSmoothJoin="True" Point1="26,-200" Point2="29,1" Point3="300,5" IsStroked="True"/>
                </PathFigure>
            </PathGeometry>
        </Canvas.Clip>
        <Rectangle d:LayoutOverrides="Height" Stroke="{x:Null}" Fill="Red" Width="436" Height="100" x:Name="Rectangle" Canvas.Left="0" Canvas.Top="0"/>
        <Label Background="Black" x:Name="Label" Content="This is my clipped space." Canvas.Left="46" Canvas.Top="26" d:IsHidden="True"/>
    </Canvas>
</StackPanel>
//File:Window.xaml.vb

Imports System
Imports System.IO
Imports System.Net
Imports System.Windows
Imports System.Windows.Input
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation

Namespace PaintDrawExamples
  Public Partial Class DynamicClipping
    Public Sub New()
      Me.InitializeComponent()
      Me.Canvas.VerticalAlignment = VerticalAlignment.Center
      Me.Canvas.HorizontalAlignment = HorizontalAlignment.Center

      AddHandler CompositionTarget.Rendering, AddressOf CompositionTarget_Rendering
    End Sub

    Private Sub CompositionTarget_Rendering(sender As Object, e As EventArgs)
      Dim mousePos As Point = Mouse.GetPosition(Me.Canvas)
      Dim clippingRegion As Geometry = Me.Canvas.Clip

      Dim newPos As New TranslateTransform()
      newPos.X = mousePos.X - (Me.Canvas.Width / 2)
      newPos.Y = mousePos.Y - (Me.Canvas.Height / 2)

      clippingRegion.Transform = newPos
    End Sub
  End Class
End Namespace
WPF Dynamic Clipping
16.85.Clip
16.85.1.Dynamic ClippingDynamic Clipping
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.