Use a VisualBrush to magnify a portion of the screen. : VisualBrush « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » VisualBrushScreenshots 
Use a VisualBrush to magnify a portion of the screen.
Use a VisualBrush to magnify a portion of the screen.
   

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  x:Class="Microsoft.Samples.Graphics.UsingVisualBrush.MagnifyingGlassExample"
  Background="White">
  <Page.Resources>
    <Style TargetType="{x:Type Paragraph}">
      <Setter Property="Margin" Value="10" />
    </Style>
    <DrawingBrush x:Key="MyGridBackgroundBrushResource"
      Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
      <DrawingBrush.Drawing>
        <DrawingGroup>
          <DrawingGroup.Children>
            <GeometryDrawing Brush="White">
              <GeometryDrawing.Geometry>
                <RectangleGeometry Rect="0,0,1,1" />
              </GeometryDrawing.Geometry>
            </GeometryDrawing>
            <GeometryDrawing Brush="#E6E8F6"
              Geometry="M 0,0 L 0,1 0.1,1 0.1,0.1 1,0.1 1,0 Z" />                      
          </DrawingGroup.Children>
        </DrawingGroup>
      </DrawingBrush.Drawing>
    </DrawingBrush>   
    
  </Page.Resources>

  <Grid>  
    <ScrollViewer>
      <StackPanel Name="magnifiedPanel" 
        VerticalAlignment="Stretch"
        MouseMove="updateMagnifyingGlass" 
        Background="{StaticResource MyGridBackgroundBrushResource}">
        
        <FlowDocumentScrollViewer>
        <FlowDocument>
<Paragraph><Button></Button></Paragraph>

<Paragraph><Border BorderBrush="Black" BorderThickness="1"><Image Source="c:\image.jpg" Stretch="None" /></Border></Paragraph>

<Paragraph>this is a test</Paragraph> 
        </FlowDocument>
        </FlowDocumentScrollViewer>
      </StackPanel>
    </ScrollViewer>
    <Canvas Name="magnifyingGlassCanvas">
      <Ellipse Name="magnifyingGlassEllipse" Width="100" Height="100" Stroke="Black">
        <Ellipse.Fill>
          <DrawingBrush>
            <DrawingBrush.Drawing>
              <DrawingGroup>
                <DrawingGroup.Children>
                   <GeometryDrawing Brush="White">
                    <GeometryDrawing.Geometry>
                      <RectangleGeometry Rect="0,0,1,1" />
                    </GeometryDrawing.Geometry>
                  </GeometryDrawing>
                   <GeometryDrawing>
                    <GeometryDrawing.Brush>
                       <VisualBrush x:Name="myVisualBrush" ViewboxUnits="Absolute"
                        Visual="{Binding ElementName=magnifiedPanel}"/>
                    </GeometryDrawing.Brush>
                    <GeometryDrawing.Geometry>
                      <RectangleGeometry Rect="0,0,1,1" />
                    </GeometryDrawing.Geometry>
                  </GeometryDrawing>
                </DrawingGroup.Children>
              </DrawingGroup>
            </DrawingBrush.Drawing>
          </DrawingBrush>
        </Ellipse.Fill>
      </Ellipse>
    </Canvas>
  </Grid>
</Page>

//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Windows.Media
Imports System.Windows.Input

Namespace Microsoft.Samples.Graphics.UsingVisualBrush
  Public Partial Class MagnifyingGlassExample
    Inherits Page
    Private Shared ReadOnly distanceFromMouse As Double = 5

    Public Sub New()
    End Sub
    Private Sub updateMagnifyingGlass(sender As Object, args As MouseEventArgs)
      Mouse.SetCursor(Cursors.Cross)
      Dim currentMousePosition As Point = args.GetPosition(Me)
      If Me.ActualWidth - currentMousePosition.X > magnifyingGlassEllipse.Width + distanceFromMouse Then
        Canvas.SetLeft(magnifyingGlassEllipse, currentMousePosition.X + distanceFromMouse)
      Else
        Canvas.SetLeft(magnifyingGlassEllipse, currentMousePosition.X - distanceFromMouse - magnifyingGlassEllipse.Width)
      End If

      If Me.ActualHeight - currentMousePosition.Y > magnifyingGlassEllipse.Height + distanceFromMouse Then
        Canvas.SetTop(magnifyingGlassEllipse, currentMousePosition.Y + distanceFromMouse)
      Else
        Canvas.SetTop(magnifyingGlassEllipse, currentMousePosition.Y - distanceFromMouse - magnifyingGlassEllipse.Height)
      End If
      myVisualBrush.Viewbox = New Rect(currentMousePosition.X - 10, currentMousePosition.Y - 102020)
    End Sub
  End Class
End Namespace

   
    
    
  
Related examples in the same category
1.Fill Ellipse with custom VisualBrushFill Ellipse with custom VisualBrush
2.VisualBrush.RelativeTransformVisualBrush.RelativeTransform
3.VisualBrush.VisualVisualBrush.Visual
4.VisualBrush Binding and RotateTransformVisualBrush Binding and RotateTransform
5.VisualBrush TileMode and ViewportVisualBrush TileMode and Viewport
6.RotateTransform and VisualBrushRotateTransform and VisualBrush
7.Reflection EffectReflection Effect
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.