WPF Ellipse control in VB.NET
Learn how to create and configure an Ellipse control in WPF using XAML and VB.NET, including its basic properties.
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: WPF Ellipse control in VB.NET


Stephen PotterPosted Mar 21, 2012, 4:44 AM EDT
I have used the below code, but wish to make it just one button that gives me some sort of color palette option to change the color of the brush to draw on the canvas. Would you please be able to fix my code so that it does this ? namespace WPFDraw { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { bool paint; int toolSelected; public MainWindow() { InitializeComponent(); paint = false; toolSelected = 0; } private void canvas1_MouseDown(object sender, MouseButtonEventArgs e) { paint = true; } private void canvas1_MouseUp(object sender, MouseButtonEventArgs e) { paint = false; } private void canvas1_MouseMove(object sender, MouseEventArgs e) { Point p; p = e.GetPosition(canvas1); if (paint == true) { if (toolSelected == 0) { Ellipse myEllipse = new Ellipse(); myEllipse.Fill = Brushes.Chartreuse; myEllipse.Width = 30; myEllipse.Height = 55; myEllipse.Margin = new Thickness(p.X, p.Y, 0, 0); canvas1.Children.Add(myEllipse); } else if (toolSelected == 1) { Ellipse myEllipse = new Ellipse(); myEllipse.Fill = Brushes.Red; myEllipse.Width = 30; myEllipse.Height = 55; myEllipse.Margin = new Thickness(p.X, p.Y, 0, 0); canvas1.Children.Add(myEllipse); } } } private void buttonEllipse_Click(object sender, RoutedEventArgs e) { toolSelected = 0; } private void buttonEllipseRed_Click(object sender, RoutedEventArgs e) { toolSelected = 1; } } }