0

Hello
I need to program two radio buttons for directions [up down] for my simple textbox search. Any help would be appreciated. Im new to c#.

3
Contributors
11
Replies
12
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
Featured Replies
  • LOL... I got the code in my 1st attempt. No repairing it. Damn Im good :) Here it is: [CODE] //form1: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 f2 = new Form2(this); f2.Show(); } public void SelectingText(string … Read More

0

What have you got so far for yourself?

Well, I've got some forms, I'm in Vstudio for the first time now, its a bit confusing so. Anyways, so I've got a main form that holds the main textbox and a search form that holds a find textbox, find button and direction up-down radios. This is the search part :

if((pos= tBox.Text.IndexOf(searchText)) != -1) 
{
                tBox.Select(pos, searchText.Length);
                tBox.ScrollToCaret();
	  tBox.Focus();         	  
	  return true;	  
	  }

So when I enter some text in the textbox in the search form, it gets marked in the main textbox if found of course. Ive got that part to work. But the directions trouble me. Im not familiar with c# syntax and I dont know how to move around in the container.

Edited by Joey_Brown: n/a

0

What do you mean with radion buttons direstions?
YOu have only one "main textBox" so how will you be using these 2 radionbuttons? What would be the difference in selecting one or the other?

Mitja

0

What do you mean with radion buttons direstions?
YOu have only one "main textBox" so how will you be using these 2 radionbuttons? What would be the difference in selecting one or the other?

Mitja

Well, when you would select the up radio and position the carret in the middle of the text; the find click event would search the occuring substring from that position to the beginning of the text. And the down radio would do the opposite towards the end of the text. Its kind of like find next and find previous.

Edited by Joey_Brown: n/a

0

Do you mean if you have more equal words, the search will go forward (from let to right) when up radioButton will be selected?

0

Ups.
So when will select UP:
will select the searching word and the rest of the letter to the right

When you will select DOWN:
will select the searching word and the rest of the letters to the left.

Am I right?

0

Do you mean if you have more equal words, the search will go forward (from let to right) when up radioButton will be selected?

No, that should occur when down radio is selected. When the up radio is selected; the search would go backwards.

0

Ups.
So when will select UP:
will select the searching word and the rest of the letter to the right

When you will select DOWN:
will select the searching word and the rest of the letters to the left.

Am I right?

Yes, thats it. The radioButton.Checked is a boolean value, right?
So how could I get myself around that text.

1

LOL... I got the code in my 1st attempt. No repairing it. Damn Im good :)

Here it is:

//form1:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Show();
        }

        public void SelectingText(string searchText, bool bSelectUp)
        {
           
            int position = textBox1.Text.IndexOf(searchText);
            if (position > 0)
            {
                if (bSelectUp)
                    textBox1.Select(position, (textBox1.Text.Length - position));
                else
                    textBox1.Select(0, (position + searchText.Length));
                textBox1.ScrollToCaret();
                textBox1.Focus();
            }
            else
                textBox1.DeselectAll();
        }
    }

//form2:
    public partial class Form2 : Form
    {
        Form1 f1;
        public Form2(Form1 _f1)
        {
            InitializeComponent();
            this.f1 = _f1;
            //select by defualt the up radio button (so one will always  be selected):
            radioButton1.Checked = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {            
            string value = textBox1.Text;
            bool bSelectUp = (radioButton1.Checked) ? true : false;
            f1.SelectingText(value, bSelectUp);
        }
    }

Hope it helps,
Mitja

Comments
thanks!!
0

LOL... I got the code in my 1st attempt. No repairing it. Damn Im good :)

Here it is:

//form1:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Show();
        }

        public void SelectingText(string searchText, bool bSelectUp)
        {
           
            int position = textBox1.Text.IndexOf(searchText);
            if (position > 0)
            {
                if (bSelectUp)
                    textBox1.Select(position, (textBox1.Text.Length - position));
                else
                    textBox1.Select(0, (position + searchText.Length));
                textBox1.ScrollToCaret();
                textBox1.Focus();
            }
            else
                textBox1.DeselectAll();
        }
    }

//form2:
    public partial class Form2 : Form
    {
        Form1 f1;
        public Form2(Form1 _f1)
        {
            InitializeComponent();
            this.f1 = _f1;
            //select by defualt the up radio button (so one will always  be selected):
            radioButton1.Checked = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {            
            string value = textBox1.Text;
            bool bSelectUp = (radioButton1.Checked) ? true : false;
            f1.SelectingText(value, bSelectUp);
        }
    }

Hope it helps,
Mitja

Thank you mr.Mitja. I shall do my best to try and study it. :muchrespect:
Cheers!
Joey

0

Anytime. Iam in the mood to do coding atm, this doesnt accur often :) but its time for bed.
best regards,
Mitja

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.