Home > Software design >  how to align some text left and some text right in label or in textbox TextMode="MultiLine"
how to align some text left and some text right in label or in textbox TextMode="MultiLine"

Time:08-30

I want to show some text left and some text right side in label or in textbox TextMode="MultiLine" and I have read I want to show output like this

Suggest me how to achieve this and where I did the mistake.

CodePudding user response:

It not clear you want colors. I would probably suggest aliteral control.

so, say like this:

     <style>
        .myshadow {box-shadow: 8px 8px 8px 0px gray}
        .myshadow {border-radius:10px}
        .myshadow {border:solid 1px;padding:4px;border-color:black}
        .myshadow {background-color:aliceblue;display:inline-block;margin-bottom:10px}
    </style>


    <div style="width:50%;height:400px;border:solid 1px black;overflow:auto;padding:8px">

        <asp:Literal ID="Literal1" runat="server">
        </asp:Literal>

    </div>

And now code like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            LoadText();
    }

    void LoadText()
    {
        string MyText = "";

        // add some red text to box

        MyText  = AddText("This is some red text", "red");

        MyText  = AddText("This is some Blue text", "blue","right");

        MyText  = AddText("The Matrix is watching you", "Green");
        MyText  = AddText("Knock knock....", "Green");
        MyText  = AddText("Follow the White Rabbit", "Green");
        MyText  = @"<br/>";   // skip (blank line)

        MyText  = AddText("This is some red text", "Red","left",false);
        MyText  = AddText(" and ", "Black","left",false);
        MyText  = AddText("Some blue text on the same line", "Blue");

        MyText  = AddText("left text on same line", "blue", "left", false);
        MyText  = AddText("right text on same line", "red", "right");

        Literal1.Text = MyText;
    }

    string AddText(string strText, string scolor, string LeftRight = "left", bool NewLine = true)
    {
        string sResult = "";
        sResult = 
            string.Format(@"<div style='font-size:large;color:{0};float:{1}' class='myshadow' >",
            scolor,LeftRight)   strText   @"</div>";

        // add new line???
        if (NewLine)
            sResult  = @"<div style='clear:both'></div>";

        return sResult;
    }

And we now get this:

enter image description here

  • Related