防止网格单元访问

时间:2019-02-17 18:19:06

标签: c#

我正在尝试编写一个时间表生成器,其中每个主题都随机放置在一个单元格中。但是,一旦将一个字符串放置在网格单元中,我就不希望将另一个字符串放置在同一网格单元中。

    private void InputButton_Click(object sender, RoutedEventArgs e)
    {
        string Subject = subject.Text;
        string Sub_Subject = subsubject.Text;
        string choice = ("\n" + Subject + " : " + Sub_Subject);
        Output.Text += choice;

        Random rnd = new Random();
        int row = rnd.Next(2, 6);
        int column = rnd.Next(1, 8);

        TextBlock Box = new TextBlock();
        Box.Text = choice;
        Box.HorizontalAlignment = HorizontalAlignment.Center;
        myGrid.Children.Add(Box);
        Grid.SetRow(Box, row);
        Grid.SetColumn(Box, column);



    }

0 个答案:

没有答案