Search code examples
c#.netwinformsnamespacesuser-controls

C# Winforms: can't create window using system.windows


This question is quite the same as this one, but I can't find a suitable answer anywhere. Basically, I'm trying to make a new window to show a user control but it doesn't work, it displays an error saying that the type or namespace "Window" could not be found. I have implemented using System.Windows;. The code looks like this:

private void settB_Click(object sender, EventArgs e)
    {
        Window window = new Window
        {
            Title = "My User Control Dialog",
            Content = new qlSetting(),
            ResizeMode = ResizeMode.NoResize
        };
        window.ShowDialog();
    }

Solution

  • private void settB_Click(object sender, EventArgs e)
    {
        using (Form window = new Form())
        {
            qlSetting ql = new qlSetting();
            ql.Dock = DockStyle.Fill;
            window.Controls.Add(ql);
            window.ShowDialog();
        }
    }