Set cursor area : Cursor « 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 » CursorScreenshots 
Set cursor area
   

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="cursors" Height="450" Width="600" Loaded="OnLoaded">
  <Window.Resources>
    <Style TargetType="{x:Type RadioButton}">
      <Setter Property="Margin" Value="3" />
    </Style>
    <Style TargetType="{x:Type Label}">
      <Setter Property="FontSize" Value="14" />
      <Setter Property="HorizontalAlignment" Value="Center" />
    </Style>
    <Style TargetType="{x:Type Border}">
      <Setter Property="BorderBrush" Value="LightBlue" />
      <Setter Property="BorderThickness" Value="2" />
      <Setter Property="Margin" Value="10" />
    </Style>
  </Window.Resources>

  <StackPanel>
    <Border Width="300">
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <StackPanel Margin="10">
          <Label HorizontalAlignment="Left">Cursor Type</Label>
          <ComboBox Width="100" SelectionChanged="CursorTypeChanged" HorizontalAlignment="Left" Name="CursorSelector">
            <ComboBoxItem Content="AppStarting" />
            <ComboBoxItem Content="ArrowCD" />
          </ComboBox>
        </StackPanel>
        <StackPanel Margin="10">
          <Label HorizontalAlignment="Left">Scope of Cursor</Label>
          <StackPanel>
            <RadioButton Name="rbScopeElement" IsChecked="True" Checked="CursorScopeSelected">Display Area Only</RadioButton>
            <RadioButton Name="rbScopeApplication" Checked="CursorScopeSelected">Entire Appliation</RadioButton>
          </StackPanel>
        </StackPanel>
      </StackPanel>
    </Border>
    <Border Name="DisplayArea" Height="250" Width="400" Margin="20" Background="AliceBlue">
      <Label HorizontalAlignment="Center">
        Move Mouse Pointer Over This Area
      </Label>
    </Border>
  </StackPanel>
</Window>

//File:Window.xaml.vb

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Input
Imports System.IO
Imports System.Collections


Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Private CustomCursor As Cursor

    Public Sub New()
      CustomCursor = New Cursor(Directory.GetCurrentDirectory() & Path.DirectorySeparatorChar & "CustomCursor.cur")
    End Sub
    Public Sub CursorTypeChanged(sender As Object, e As SelectionChangedEventArgs)
      Dim source As ComboBox = TryCast(e.Source, ComboBox)

      If source IsNot Nothing Then
        Dim selectedCursor As ComboBoxItem = TryCast(source.SelectedItem, ComboBoxItem)

        Select Case selectedCursor.Content.ToString()
          Case "AppStarting"
            DisplayArea.Cursor = Cursors.AppStarting
            Exit Select
          Case "ArrowCD"
            DisplayArea.Cursor = Cursors.ArrowCD
            Exit Select
          Case Else
            Exit Select
        End Select

        If cursorScopeElementOnly = False Then
          Mouse.OverrideCursor = DisplayArea.Cursor
        End If
      End If
    End Sub
    Public Sub CursorScopeSelected(sender As Object, e As RoutedEventArgs)
      Dim source As RadioButton = TryCast(e.Source, RadioButton)

      If source IsNot Nothing Then
        If source.Name = "rbScopeElement" Then
          cursorScopeElementOnly = True
          Mouse.OverrideCursor = Nothing
        End If
        If source.Name = "rbScopeApplication" Then
          cursorScopeElementOnly = False
          Mouse.OverrideCursor = DisplayArea.Cursor
        End If
      End If
    End Sub
    Public Sub OnLoaded(sender As Object, e As RoutedEventArgs)
      DirectCast(CursorSelector.Items(0), ComboBoxItem).IsSelected = True
    End Sub
    Private cursorScopeElementOnly As Boolean = True
  End Class
End Namespace

   
    
    
  
Related examples in the same category
1.Set cursor for Line shapeSet cursor for Line shape
2.Changing the cursor of the Border control by setting the Cursor property
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.