WPF Polygon and MouseDown Event in VB.NET

In this article you will learn that how to draw Polygon Dynamically and how you can handle its MouseDown Event.
  • 4384


Here in this article I am explaining that how you can draw Polygon and handle its Mouse Down Event in WPF. WPF offers a lot of control in its different layers. In top layer it offers shape object. But sometimes we need to draw shapes and objects Dynamically. As in this example we are drawing Polygon and also showing the Polygons MouseDown Event. When you click the Polygon a MessageBox will display the message. The implementation only needs a StackPanel control and a series of namespaces related to graphics and shapes.

Getting Started

  • Simply Create a new WPF application
  • Drag a StackPanel and dynamically draw a Ploygon on MainWindow. Your window will look like below.

  • Your MainWindow.xaml page will look like below.

    <Window x:Class="MainWindow"
        Title="MainWindow" Height="275" Width
        <StackPanel Orientation="Horizontal" >
            <Polygon Fill="DeepSkyBlue"   Canvas.Left="100" Canvas.Top="30" Points=" 50 20 100 100 10 100"
    =" Polygon_MouseDown"/>
  • Then add the below code in code behind file.

    Private Sub Polygon_MouseDown(sender As Object, e As MouseButtonEventArgs)
            MessageBox.Show("polygon shape")
  • Now run your application.




In this article you learned that how you can draw Polygon and handle its MouseDown Event.


More Articles

© 2020 DotNetHeaven. All rights reserved.