locked
how to give background color inside second textbox in specific text(new words) in c# RRS feed

  • Question

  • User-91993069 posted

    I am trying to give green color(background) on the new word(for application by website algorithm) in the second textbox

    3eGEi.png (1053×397)

    public static string NewWordFind(string x1, string x2)  
    {  
        string[] string1 = x1.Split(' ');  
        string[] string2 = x2.Split(' ');  
        string[] m = string1.ToArray();   
        string[] n = string2.ToArray();  
      
        int i = 0;  
      
        foreach (var word in m)  
        {  
            if (word == n[i] || word + "s" == n[i] || word + "es" == n[i] || word + "ies" == n[i] || word.Replace("oo", "ee") == n[i])  
            {  
                n[i] = "";  
                i++;  
            }  
        }  
      
        string Test;  
        Test = String.Join(" ", n);  
        return Test;  
      
    }  
      
    protected void btnCompare_Click(object sender, EventArgs e)  
    {  
        if (IsPostBack)  
        {  
                     
                     lblthird.Text = "New Word Is:<span style='color: green;'>" + NewWordFind(firsttextbox.Text, secondtextbox.Text) + "</span>";
                          
                     //what I am trying still(i use font color,forecolor,background color)
    
                     //string htmlCode = "<font style='color:green'>" + NewWordFind(firsttextbox.Text, secondtextbox.Text) + "</font><br/>";
                    //secondtextbox.Text = htmlCode;
                    //secondtextbox.ForeColor = System.Drawing.Color.Red;
    
                    //secondtextbox.Text = "<span style='color: green;'>" +NewWordFind(firsttextbox.Text, secondtextbox.Text) + "</span>";
    
                    //var label = "<span style = 'color: green;' > " + NewWordFind(firsttextbox.Text, secondtextbox.Text) + " </span> ";
    
                    // var hello = label;
    
                    //var newwordfinddata = NewWordFind(firsttextbox.Text, secondtextbox.Text) + System.Drawing.Color.Red;
                    //var ftextboxdata = firsttextbox.Text;
    
                    //secondtextbox.Text = ftextboxdata + newwordfinddata;
    
                    //for (int i = 0; i < secondtextbox.Text.Length; i++)
                    //{
    
                    //}
                    //secondtextbox.Text = Color.Red;
    
                    //secondtextbox.Text = 
        }  
      }

    .aspx

    <asp:TextBox ID="firsttextbox" runat="server" TextMode="MultiLine" Width="500px" Height="200px"></asp:TextBox>    
    <asp:TextBox ID="secondtextbox" runat="server" TextMode="MultiLine" Width="500px" Height="200px">    
     </asp:TextBox>    
    <asp:Label ID="lblthird" runat="server" Text=""></asp:Label><br />  

    already I find the new word and see lblthird(label)

    now I want to give green color inside the new word(for application by website algorithm) in the second textbox

    I am trying to give green color on a new word in the second textbox when compare to first textbox

    I am trying and trying but not get the success

    now question is it posible to give color in secondtextbox inside new word using javascript with jquery or <div>secondtextbox data</div>

    help

    Wednesday, October 28, 2020 12:43 PM

All replies

  • User-91993069 posted

    hello administrator

    now it is posibility to give color on second textbox new word?

    Wednesday, October 28, 2020 12:49 PM
  • User1535942433 posted

    Hi rahulpas,

    now question is it posible to give color in secondtextbox inside new word using javascript with jquery or <div>secondtextbox data</div>

    I suggest you could comparing in jquery and if it is the different word,it could set the font color.Just like this:

    <script src="Scripts/jquery-3.4.1.min.js"></script>
        <script>
            $(function () {
                $("#Button1").click(function () {
                    var t1 = $("#firsttextbox").val().split(" ");
                var t2 = $("#secondtextbox").val().split(" ");
                for (var i = t1.length - 1; i >= 0; i--) {
                    for (var j = 0; j < t2.length; j++) {
                        if (t1[i] === t2[j]) {
                            t2.splice(i, 1);
                        }
                    }
                }
                $("#secondtextbox").val(t2);
                $("#secondtextbox").css("color", "green");
                })
            })
        </script>
     <asp:TextBox ID="firsttextbox" runat="server" TextMode="MultiLine" Width="500px" Height="200px"></asp:TextBox>
            <asp:TextBox ID="secondtextbox" runat="server" TextMode="MultiLine" Width="500px" Height="200px">    
            </asp:TextBox>
            <asp:Label ID="lblthird" runat="server" Text=""></asp:Label><br />
            <asp:Button ID="Button1" runat="server" Text="Button" />

    Best regards,

    Yijing Sun

    Thursday, October 29, 2020 4:21 AM
  • User-91993069 posted

    hi yij sun

    when I run your code then output look like below:

    Thursday, October 29, 2020 4:40 AM
  • User-91993069 posted

    hello yij sun

    I am find a possibility to give a green color in second textbox new word

    textbox

    textarea

    div block - here I think possible to give a green color in second textbox new word?

    help

    Thursday, October 29, 2020 6:54 AM
  • User1535942433 posted

    Hi rahulpas,

    I couldn't see your image.You could press Insert/edit image to post your image.And you could post result image you want to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Thursday, October 29, 2020 7:41 AM
  • User-91993069 posted

    hello yij sun

    see this image

    can you help more

    now you can see my image 

    I am asking the community to it is possible to give green color on new word inside second textbox

    text area and textbox -  I think not possible to give green color on new word in second textbox?

    richtextbox and div block -I think possible to give green color on new word in second textbox?

    Thursday, October 29, 2020 8:22 AM
  • User-91993069 posted

    hello yij sun

    when I take the label I am not able to able copy and paste paregraph run time

    .aspx

    <style>
     #firstlabel{
                display: block;
                border: 1px solid #ccc;
                width:500px;
                height:500px;
    
            }
    </style>
    <body>
    <label id="firstlabel"></label>
    </body>

    need help

    which place I made mistake?

    Thursday, October 29, 2020 10:50 AM
  • User1535942433 posted

    Hi rahulpas,

    when I take the label I am not able to able copy and paste paregraph run time

    Isn't your problem to change textbox specific text?Why you need to copy and paste paragraph?

    Best regards,

    Yijing Sun

    Friday, October 30, 2020 9:14 AM
  • User-91993069 posted

    Hello yijsun

    I am taking a label because I want to give a color on new word that is reason I give the label

    can I give a color in second textbox  new word?

    it is possible with textbox?

    it is possible with textarea?

    it is possible with div block?

    help

    Friday, October 30, 2020 9:57 AM
  • User1535942433 posted

    Hi rahulpas,

    As far as I think,styling the value of the textbox is an all or nothing proposition. You can't style part of it independent of the rest.

    A workaround would be to avoid the use of the textbox element, and instead use a div to contain the suggested text. You can update the HTML inside the div using the .innerHTML property (or the .html() function in jQuery) including whatever span elements or inline styles you like.

    Best regards,

    Yijing Sun

    Thursday, November 5, 2020 6:58 AM