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#.

Recommended Answers

All 11 Replies

What have you got so far for yourself?

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.

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

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.

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

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?

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.

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.

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

commented: thanks!! +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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.