I want to make an application: the user clicks and clicks the mouse, and when he releases it, the Button is drawn where the upper left corner is the click coordinates ( MouseDown event), and the lower right one is the coordinates of the place where the user released the mouse button ( MouseUp event). Here is the code for MouseDown :
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e) { StartPoint = e.GetPosition(this); //Свойство StartPoint объявляется сверху таким образом //private System.Windows.Point StartPoint { get; set; } } Here is the code for MouseUp :
private void MainWindow_MouseUp(object sender, MouseButtonEventArgs e) { EndPoint = e.GetPosition(this); //Свойство EndPoint объявляется сверху таким образом //private System.Windows.Point EndPoint { get; set; } Button temp = new Button(); temp.Margin = new Thickness(StartPoint.X, StartPoint.Y, EndPoint.X, EndPoint.Y); temp.Background = new SolidColorBrush(Colors.Blue); temp.Content = "Do not click me!"; mainGrid.Children.Add(temp); } This does not work, the buttons are drawn too large or not drawn at all. What am I doing wrong and how to make it work?
VerticalAlighnmentasTopandHorizontalAlighnmentasLeft. Also set the desired button size. Width - width, Height - height (in pixels). - D .Stark