Changing the cursor of the Border control by setting the Cursor property : Cursor « 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 » Cursor 
16.61.3.Changing the cursor of the Border control by setting the Cursor property
<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">
          <Label HorizontalAlignment="Left">Cursor Type</Label>
          <ComboBox Width="100" SelectionChanged="CursorTypeChanged" HorizontalAlignment="Left" Name="CursorSelector">
            <ComboBoxItem Content="AppStarting" />
            <ComboBoxItem Content="ArrowCD" />
            <ComboBoxItem Content="Arrow" />
            <ComboBoxItem Content="Cross" />
            <ComboBoxItem Content="HandCursor" />
            <ComboBoxItem Content="Help" />
            <ComboBoxItem Content="IBeam" />
            <ComboBoxItem Content="No" />
            <ComboBoxItem Content="None" />
            <ComboBoxItem Content="Pen" />
            <ComboBoxItem Content="ScrollSE" />
            <ComboBoxItem Content="ScrollWE" />
            <ComboBoxItem Content="SizeAll" />
            <ComboBoxItem Content="SizeNESW" />
            <ComboBoxItem Content="SizeNS" />
            <ComboBoxItem Content="SizeNWSE" />
            <ComboBoxItem Content="SizeWE" />
            <ComboBoxItem Content="UpArrow" />
            <ComboBoxItem Content="WaitCursor" />
            <ComboBoxItem Content="Custom" />
          </ComboBox>
      </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 "Arrow"
            DisplayArea.Cursor = Cursors.Arrow
            Exit Select
          Case "Cross"
            DisplayArea.Cursor = Cursors.Cross
            Exit Select
          Case "HandCursor"
            DisplayArea.Cursor = Cursors.Hand
            Exit Select
          Case "Help"
            DisplayArea.Cursor = Cursors.Help
            Exit Select
          Case "IBeam"
            DisplayArea.Cursor = Cursors.IBeam
            Exit Select
          Case "No"
            DisplayArea.Cursor = Cursors.No
            Exit Select
          Case "None"
            DisplayArea.Cursor = Cursors.None
            Exit Select
          Case "Pen"
            DisplayArea.Cursor = Cursors.Pen
            Exit Select
          Case "ScrollSE"
            DisplayArea.Cursor = Cursors.ScrollSE
            Exit Select
          Case "ScrollWE"
            DisplayArea.Cursor = Cursors.ScrollWE
            Exit Select
          Case "SizeAll"
            DisplayArea.Cursor = Cursors.SizeAll
            Exit Select
          Case "SizeNESW"
            DisplayArea.Cursor = Cursors.SizeNESW
            Exit Select
          Case "SizeNS"
            DisplayArea.Cursor = Cursors.SizeNS
            Exit Select
          Case "SizeNWSE"
            DisplayArea.Cursor = Cursors.SizeNWSE
            Exit Select
          Case "SizeWE"
            DisplayArea.Cursor = Cursors.SizeWE
            Exit Select
          Case "UpArrow"
            DisplayArea.Cursor = Cursors.UpArrow
            Exit Select
          Case "WaitCursor"
            DisplayArea.Cursor = Cursors.Wait
            Exit Select
          Case "Custom"
            DisplayArea.Cursor = CustomCursor
            Exit Select
          Case Else
            Exit Select
        End Select
      End If
    End Sub
    Public Sub OnLoaded(sender As Object, e As RoutedEventArgs)
      DirectCast(CursorSelector.Items(0), ComboBoxItem).IsSelected = True
    End Sub
  End Class
End Namespace
16.61.Cursor
16.61.1.Set cursor for Line shapeSet cursor for Line shape
16.61.2.Set cursor areaSet cursor area
16.61.3.Changing the cursor of the Border control by setting the Cursor propertyChanging 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.