Rectangle mouse down preview : Rectangle « Windows Presentation Foundation « VB.Net Tutorial






<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication1.Window1"
    Title="Routed Events" Height="400" Width="800">
  
    <Grid Name="contentGrid" Background="Red">
        <Rectangle Name="clickMeRectangle" 
                   Height="70" 
                   Width="70" 
                   Stroke="Black" 
                   PreviewMouseDown="Generic_MouseDown" 
                   Fill="CadetBlue" />
        <Button Name="clickMeButton" 
                Height="23" 
                HorizontalAlignment="Right" 
                VerticalAlignment="Top" 
                Width="70" 
                Click="clickMeButton_Click">Click Me</Button>
        <TextBlock Name="outputText" />
    </Grid>
</Window>

//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes

Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Private Sub Generic_MouseDown(sender As Object, e As MouseButtonEventArgs)
      Console.WriteLine(outputText.Text)
      Console.WriteLine(e.RoutedEvent.Name)
      Console.WriteLine(sender.ToString())
      Console.WriteLine(DirectCast(e.Source, FrameworkElement).Name)
    End Sub

    Private Sub Window_MouseUp(sender As Object, e As MouseButtonEventArgs)
      outputText.Text = outputText.Text
    End Sub

    Private Sub clickMeButton_Click(sender As Object, e As RoutedEventArgs)
      outputText.Text = "Button clicked:" + outputText.Text
    End Sub
  End Class
End Namespace
WPF Rectangle Mouse Down Preview








16.67.Rectangle
16.67.1.Use Rectangle, TextBlock and Button as the VisualBrushUse Rectangle, TextBlock and Button as the VisualBrush
16.67.2.Set Stroke, StrokeThickness for RectangleSet Stroke, StrokeThickness for Rectangle
16.67.3.Fill Rectangles with static ImageBrush resourcesFill Rectangles with static ImageBrush resources
16.67.4.Fill Rectangle with BisqueFill Rectangle with Bisque
16.67.5.Rotating rectanglesRotating rectangles
16.67.6.Rounded rectangleRounded rectangle
16.67.7.Rectangle with explicit size and positionRectangle with explicit size and position
16.67.8.Rectangles with size and position controlled by parentRectangles with size and position controlled by parent
16.67.9.Using ImageBrush to fill a RectangleUsing ImageBrush to fill a Rectangle
16.67.10.Draws a 100 by 50 rectangle with a solid blue fillDraws a 100 by 50 rectangle with a solid blue fill
16.67.11.Draws a 100 by 50 rectangle with a solid blue fill, a black outline, and rounded cornersDraws a 100 by 50 rectangle with a solid blue fill, a black outline, and rounded corners
16.67.12.Rectangle StrokeThicknessRectangle StrokeThickness
16.67.13.Rectangle.StrokeRectangle.Stroke
16.67.14.Use Customized LinearGradientBrush to paint a RectangleUse Customized LinearGradientBrush to paint a Rectangle
16.67.15.Set RadiusX and RadiuxY for RectangleSet RadiusX and RadiuxY for Rectangle
16.67.16.Fill Rectangle with LinearGradientBrush static resourceFill Rectangle with LinearGradientBrush static resource
16.67.17.Using a DrawingBrush resource to draw RectangleUsing a DrawingBrush resource to draw Rectangle
16.67.18.A rectangle with a linear fillA rectangle with a linear fill
16.67.19.A large rectangle built using an image brushA large rectangle built using an image brush
16.67.20.Fill Rectangle with ResourceFill Rectangle with Resource
16.67.21.Add Rectangle.Triggers collection into a styleAdd Rectangle.Triggers collection into a style
16.67.22.DashArray StrokeDashArray Stroke
16.67.23.Dash patternsDash patterns
16.67.24.Put Rectangle into TextBlockPut Rectangle into TextBlock
16.67.25.Rectangle mouse down eventRectangle mouse down event
16.67.26.Rectangle mouse down previewRectangle mouse down preview
16.67.27.Change MaxHeightChange MaxHeight