Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#WPF Create函数,用于创建新输入_C# - Fatal编程技术网

C#WPF Create函数,用于创建新输入

C#WPF Create函数,用于创建新输入,c#,C#,我使用的是C#Wpf,我想创建一个函数,一旦你点击一个按钮,就会出现一个新的文本框。这是可能的,我想知道当创建一个新的文本框时,是否有可能增加表单的高度。这个问题不是很具体,但你可以在代码中创建新的UI元素。在WPF中,您可以将按钮放在窗口上,然后将“单击”事件添加到窗口中。然后在单击事件中,您可以编写如下代码 private void Button_Click(object sender, RoutedEventArgs e) { Button newButton = new Butt

我使用的是C#Wpf,我想创建一个函数,一旦你点击一个按钮,就会出现一个新的文本框。这是可能的,我想知道当创建一个新的文本框时,是否有可能增加表单的高度。这个问题不是很具体,但你可以在代码中创建新的UI元素。在WPF中,您可以将按钮放在窗口上,然后将“单击”事件添加到窗口中。然后在单击事件中,您可以编写如下代码

private void Button_Click(object sender, RoutedEventArgs e)
{
    Button newButton = new Button();    //Create a new button control and assign it to newButton
    newButton.Width = 35;   //Access fields like this (You can access any of the ones you access from the Xaml user interface)
    newButton.Height = 20;
    newButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
    newButton.VerticalAlignment = System.Windows.VerticalAlignment.Top;
    newButton.Content = "click me!";

    grMain.Children.Add(newButton); //Add it to the grid
}
grMain是我的网格的名称,请确保您命名并按名称调用它。您还可以调用其他元素,例如堆栈面板或任何您需要的元素。因此,对于您的情况,只需将其设置为文本框而不是按钮


哎呀,我没看到你问题的第二部分!要调整窗口大小,首先需要在XAML中为其添加一个名称(就像给网格或按钮命名一样,只需给窗口命名即可)。正如我们在我的示例中调用grMain一样,调用它并更改高度/宽度属性。

感谢您的帮助fivestart,我做了您所做的事情请检查我的答案,我希望您能帮助我again@arclite86最好是实际编辑您的原始帖子,而不是发布另一个答案来修改您的问题。但现在没关系。您看到如何将x:name添加到按钮中了吗?您也可以对网格和窗口执行此操作。很像。对于你的网格,你需要像这样的东西。好的,我终于明白了,我现在在stackpanel中创建了一个新按钮,但是如何在同一行中添加多个按钮和输入?