我有一个问题,我想弄明白.
在Form1,我尝试运行一些方法Form2.
例:
表格1:
`Form2.SomeMethod(name);`
Run Code Online (Sandbox Code Playgroud)
表格2
这是一个我正在调用的方法,Form1在这个方法中我调用了其他应该做的事情的方法.
public static void SomeMethod(string name)
{
new Form2().method2(name);
}
Run Code Online (Sandbox Code Playgroud)
这种方法不能正常工作
public void method2(string naziv)
{
MessageBox.Show("test? "+naziv); //only for test. This works
Button x = new Button();
x.Margin = new Thickness(50, 20, 0, 0);
x.VerticalAlignment = VerticalAlignment.Top;
x.HorizontalAlignment = HorizontalAlignment.Left;
x.MinHeight = 50;
x.MinWidth = 100;
x.MaxWidth = 150;
x.FontSize = 20;
x.Content = naziv;
x.Name = "naziv";
gridmiza.Children.Add(x);
lbltest1.Content = "test? "+naziv; //only for test
MessageBox.Show("test2?"); …Run Code Online (Sandbox Code Playgroud)