我将数量的省略号写入txtBox,然后点击在画布上添加它们。
我想写一些应该通过线连接的省略号。但是如何添加这条线的坐标?我认为它应该是椭圆的中心,但如何知道它的坐标?
XAML:
<Window x:Class="draw.ellipse"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="draw" Height="768" Width="1024" WindowStartupLocation="CenterScreen" Name="Create" Closed="Create_Closed">
<Canvas Name="can" Background="White" MouseDown="can_MouseDown">
<TextBox Name="txbNumber" Height="34" Canvas.Left="797" TextWrapping="Wrap" Text="5" Canvas.Top="76" Width="209" FontSize="18"/>
<Button Name="btnCreate" Content="create" Canvas.Left="797" Canvas.Top="138" Width="209" Height="66" FontSize="18" Click="btnCreate_Click"/>
<TextBox Name="txb1" Height="34" Canvas.Left="797" TextWrapping="Wrap" Text="3" Canvas.Top="222" Width="78" FontSize="18"/>
<Button Name="btnCreateEdge" Content="create edge" Canvas.Left="797" Canvas.Top="276" Width="209" Height="66" FontSize="18" Click="btnCreateEdge_Click"/>
<TextBox Name="txb2" Height="34" Canvas.Left="928" TextWrapping="Wrap" Text="4" Canvas.Top="222" Width="78" FontSize="18"/>
<Label Name='lbl' Content="Label" Canvas.Left="797" Canvas.Top="374" Height="54" Width="169" FontSize="20"/>
</Canvas>
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Graduate
{
/// <summary>
/// Логика взаимодействия для Create.xaml
/// </summary>
public partial class draw: Window
{
public draw()
{
InitializeComponent();
}
int n, i, k, k2, j, j2, f;
Ellipse[] v;
private void btnCreate_Click(object sender, RoutedEventArgs e)
{
n = Convert.ToInt16(txbNumber.Text);
f = n;
v = new Ellipse[n];
var elipsy = can.Children.OfType<Ellipse>().ToList();
foreach (var ellipses in elipsy)
{
can.Children.Remove(ellipses);
}
}
private void Create_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
private void can_MouseDown(object sender, MouseButtonEventArgs e)
{
Ellipse myEllipse = new Ellipse();
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Colors.Transparent;
for (i = 0; i < n; i++)
{
v[i] = new Ellipse();
v[i].Fill = mySolidColorBrush;
v[i].StrokeThickness = 2;
v[i].Stroke = Brushes.Black;
v[i].Width = 75;
v[i].Height = 75;
v[i].Margin = new Thickness(e.GetPosition(can).X, e.GetPosition(can).Y, 0, 0);
can.Children.Add(v[i]);
}
if (n <= 0)
return;
n--;
}
private void btnCreateEdge_Click(object sender, RoutedEventArgs e)
{
k2 = Convert.ToInt16(txb1.Text);
j2 = Convert.ToInt16(txb2.Text);
k = f - k2;
j = f - j2;
Line line = new Line();
//line.X1 = v[k].;
can.Children.Add(line);
}
}
}
答案 0 :(得分:0)
当调用处理程序时,您的省略号位于彼此的顶部,因此,即使您找到了在其中放置Line的方法,您也可能看不到它。
回答你的问题:
通过Canvas.Top和Canvas.Left查找椭圆的位置。利用这些信息及其宽度或高度,您可以获得椭圆的中心。
您可以使用#1的信息作为线路的X1,X2和Y1,Y2来连接省略号。