【问题标题】:Label in Tab Panel Using C#使用 C# 在选项卡面板中添加标签
【发布时间】:2015-10-28 15:13:16
【问题描述】:

有谁知道如何将 C# 中生成的标签设置为位于选项卡面板的中心? (请看下图)

这是我想要实现的输出: 这是我的代码:

if(panel.Controls.Count<1)
                {
                    System.Web.UI.HtmlControls.HtmlGenericControl panelDIV = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
                    panelDIV.ID = "panelDIV";
                    panelDIV.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
                    panelDIV.Style.Add(HtmlTextWriterStyle.Width, "100%");
                    panelDIV.Style.Add(HtmlTextWriterStyle.Position, "center");
                    panelDIV.Style.Add(HtmlTextWriterStyle.FontStyle, "Arial");


                    System.Web.UI.WebControls.Label newTabel = new System.Web.UI.WebControls.Label();
                    newTabel.Text +=  "no chart to display";
                    newTabel.Font.Bold = true;
                    newTabel.Font.Size=16;
                    panelDIV.Controls.Add(newTabel);
                    panel.Controls.Add(panelDIV);
                }

问题:如何将C#生成的标签设置在标签面板的中心? 谢谢。

【问题讨论】:

    标签: c# html asp.net tabs label


    【解决方案1】:

    这是将标签放在页面中心的示例

    .aspx

    <asp:Button ID="btnPanel1" runat="server" Text="Panel 1" OnClick="btnPanel1_Click" />
    &nbsp;
    <asp:Button ID="btnPanel2" runat="server" Text="Panel 2" OnClick="btnPanel2_Click" />
    
    <br />
    <asp:Panel ID="pnl1" runat="server"></asp:Panel>
    <asp:Panel ID="pnl2" runat="server" Visible="false"></asp:Panel>
    

    .cs

    protected void btnPanel1_Click(object sender, EventArgs e)
    {
        if (!pnl1.HasControls())
        {
            pnl1.Attributes.Add("style", "width: 100%;");
    
            HtmlGenericControl pnlDiv = new HtmlGenericControl("div");
            pnlDiv.ID = "pnlDiv1";
            pnlDiv.Attributes.Add("style", "width: 100%; text-align:center;");
    
    
            Label lbl = new Label();
            lbl.ID = "lblSomething";
            lbl.Text = "Panel 1 Something";
            lbl.Font.Bold = true;
            lbl.Font.Size = 16;
            lbl.Attributes.Add("style", "position: absolute; top: 50%; bottom: 50%; left: 0; right: 0;");
            pnlDiv.Controls.Add(lbl);
            pnl1.Controls.Add(pnlDiv);
        }
        pnl1.Visible = true;
        pnl2.Visible = false;
    }
    
    protected void btnPanel2_Click(object sender, EventArgs e)
    {
        if (!pnl2.HasControls())
        {
            pnl2.Attributes.Add("style", "width: 100%;");
    
            HtmlGenericControl pnlDiv = new HtmlGenericControl("div");
            pnlDiv.ID = "pnlDiv2";
            pnlDiv.Attributes.Add("style", "width: 100%; text-align:center;");
    
    
            Label lbl = new Label();
            lbl.ID = "lblSomething2";
            lbl.Text = "Panel 2 Something";
            lbl.Font.Bold = true;
            lbl.Font.Size = 16;
            lbl.Attributes.Add("style", "position: absolute; top: 50%; bottom: 50%; left: 0; right: 0;");
            pnlDiv.Controls.Add(lbl);
            pnl2.Controls.Add(pnlDiv);
        }
    
        pnl1.Visible = false;
        pnl2.Visible = true;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多