如何隐藏以编程方式创建的面板? C#

问题描述 投票:0回答:1

我通过单击 form1 上的组合框以编程方式创建了一个面板,我的 form2(带树视图)将出现在该面板中。从 form2 选择后,面板应隐藏/关闭。

enter image description here

这是我的组合框中的代码

        Panel p = new Panel();
        p.Size = new System.Drawing.Size(239, 196);
        p.Location = new Point(346, 3);
        p.Name = "pCatHierarchy";
        p.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        this.Controls.Add(p);
        pGeneral.Controls.Add(p);
        p.BringToFront();
        frmCatHierarchy ch = new frmCatHierarchy { TopLevel = false };
        ch.panel1.Visible = false;
        p.Controls.Clear();
        p.Controls.Add(ch);
        ch.BringToFront();
        ch.Show();

这是我隐藏 form2 的代码,同时使用 FormClosing 事件从 form2(treeview) 获取 id/代码

        frmModifyProd modifyProd = new frmModifyProd();
        foreach(Form f in Application.OpenForms)
        {
            if(f.Name == "frmModifyProd")
            {
                (f as frmModifyProd).cbCategoryCode.Text = Id.categoryCode;
                modifyProd.Controls.RemoveByKey("pCatHierarchy");
            }
        }
    

我尝试研究,但找不到任何有相同问题的论坛

c# panel programmatically-created
1个回答
0
投票

您可以使用

HttpClientHandler
类并将其
UseDefaultCredentials
属性设置为
true

var handler = new HttpClientHandler
{
    UseDefaultCredentials = true,
    // Optionally, you can also set other properties of HttpClientHandler here
};

var client = new HttpClient(handler);
var res = await client.GetAsync("https://localhost:44387/api/values/SetCookie");
© www.soinside.com 2019 - 2024. All rights reserved.