none
visual studio randomize number RRS feed

  • Question

  • hey guys I need your help ASAP

    I am trying to select 2 different numbers from list of randomize number by pressing a button.

    I want those two different number to be highlighted with two different colours.

    The randomize numbers are in textbox.

    Hope all of you will look forward to help me please.

    you will be  looked after for long.

    Thank you.

    Thursday, May 22, 2014 3:33 AM

Answers

  • Hello jpsmoney,

    Your question is interesting in my mind but a little hard to solve it if you want to show them at one time.

    You know that at design time select the text can be done with the solution here:

    http://msdn.microsoft.com/en-us/library/aa983718(v=vs.71).aspx

    Code in C#:

    private void textBox1_Enter(object sender, System.EventArgs e){
       textBox1.SelectionStart = 0;
       textBox1.SelectionLength = textBox1.Text.Length;
    }
    

    However, to highlight the selected text, you may need to follow this instruction:

    (Optional) Access the selected text through the SelectedText property

    Obviously, design time technology use  SelectedText property can not highlight your 2 different numbers at once. I just find an article about how can we "Multi-select of textboxes in C# windows form" which is very helpful for this issue. That is because it actually select and draw rectangle for more than once. Please check Zhi-Xin's code for some details.

    So do you mind to design like Zhi-Xin's code, you will not handle mouse related event. You will need to select the different number two times and draw highlight rectangle using the position.

    Hope what I think make sense for you.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 26, 2014 9:55 AM
    Moderator
  • Hi,

    Use richtext for display the numbers. Then you can use following code to highlight the text.

      richTextBox1.SelectionStart = 0;
                richTextBox1.SelectionLength = 4;
                richTextBox1.SelectionBackColor = Color.LightBlue;
    
                richTextBox1.SelectionStart = 5;
                richTextBox1.SelectionLength = 9;
                richTextBox1.SelectionBackColor = Color.BlueViolet;

    Thank You,

    Sammani

    http://sammanipalansuriya.blogspot.com/

    Tuesday, May 27, 2014 4:48 AM

All replies

  • Moving to more appropriate forum.

    Esther Fan | Visual Studio | If a post answers your question, please mark it as the answer. Thanks!

    Friday, May 23, 2014 5:14 PM
  • Hello jpsmoney,

    Your question is interesting in my mind but a little hard to solve it if you want to show them at one time.

    You know that at design time select the text can be done with the solution here:

    http://msdn.microsoft.com/en-us/library/aa983718(v=vs.71).aspx

    Code in C#:

    private void textBox1_Enter(object sender, System.EventArgs e){
       textBox1.SelectionStart = 0;
       textBox1.SelectionLength = textBox1.Text.Length;
    }
    

    However, to highlight the selected text, you may need to follow this instruction:

    (Optional) Access the selected text through the SelectedText property

    Obviously, design time technology use  SelectedText property can not highlight your 2 different numbers at once. I just find an article about how can we "Multi-select of textboxes in C# windows form" which is very helpful for this issue. That is because it actually select and draw rectangle for more than once. Please check Zhi-Xin's code for some details.

    So do you mind to design like Zhi-Xin's code, you will not handle mouse related event. You will need to select the different number two times and draw highlight rectangle using the position.

    Hope what I think make sense for you.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 26, 2014 9:55 AM
    Moderator
  • Hi,

    Use richtext for display the numbers. Then you can use following code to highlight the text.

      richTextBox1.SelectionStart = 0;
                richTextBox1.SelectionLength = 4;
                richTextBox1.SelectionBackColor = Color.LightBlue;
    
                richTextBox1.SelectionStart = 5;
                richTextBox1.SelectionLength = 9;
                richTextBox1.SelectionBackColor = Color.BlueViolet;

    Thank You,

    Sammani

    http://sammanipalansuriya.blogspot.com/

    Tuesday, May 27, 2014 4:48 AM