(Post was originaly posted in an XBOX forum - No help.)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Xbox_Live_Bio_Template
{
    public partial class Form1 : Form
    {
        string a = "╋";
        string b = "━";
        string c = "┃";
        string d = "┏";
        string l = "┓";
        string f = "┗";
        string g = "┛";
        string h = "┣";
        string i = "┫";
        string j = "┳";
        string k = "┻";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = a.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = b.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = c.ToString();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            textBox1.Text = k.ToString();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            textBox1.Text = j.ToString();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text = i.ToString();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text = h.ToString();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text = g.ToString();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text = f.ToString();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = l.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text = d.ToString();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

That is my code. My bio creater so far :

[img]http://i15.photobucket.com/albums/a389/bullzeye10/lol.png[/img]

I have loads of text boxes (coloured blue) and some buttons. Right now if i click a button it only assigns the frame to textbox1. How do i make it assign to the box that my cursor is on (when i click the box)

I am currently working on a Xbox Live Bio Creator and i need help. I am not making one to compete with anyone, it is only for practice as i have always wanted to learn how to use C/C++/C#.

The program in the end will be released as a free program.

The reason that i am making a bio creator is that the one that i have now requires me to copy/paste each unicode character to a box while i want a button for ease of use.

Thanks.


(Post was originaly posted in an XBOX forum - No help.)

I have loads of text boxes (coloured blue) and some buttons. Right now if i click a button it only assigns the frame to textbox1. How do i make it assign to the box that my cursor is on (when i click the box)

If I read this correctly, what you want to do is to assign whatever text is in the first box into the second one as well, when you click the second box?

(Using Visual Studio C# Express Edition 2005...yeah I know I need to update) You can do this:

Go to design view. Right click on textBox2. Click Properties (if it isn't already showing). Look to the right, where the properties are displaying. Click on the lightning bolt (events). Scroll down to MouseClick. Double click on it, which should take you to the code & add the MouseClick code. Then just write inside it whatever you want to do when the user clicks the mouse.

private void textBox2_TextChanged_1(object sender, EventArgs e)
      {
   //         textBox2.Text = "Whenever you write something in the box and hit enter, this text will appear.";
          //the next part did not work until I commented this out
//but you had nothing there anyway so it shouldn't matter for your code
    }

        private void textBox2_MouseClick(object sender, MouseEventArgs e)
        {
            textBox2.Text = textBox1.Text; //this will make the text in the 1st box appear in the 2nd one when the user clicks this box
        }

If I read this correctly, what you want to do is to assign whatever text is in the first box into the second one as well, when you click the second box?

(Using Visual Studio C# Express Edition 2005...yeah I know I need to update) You can do this:

Go to design view. Right click on textBox2. Click Properties (if it isn't already showing). Look to the right, where the properties are displaying. Click on the lightning bolt (events). Scroll down to MouseClick. Double click on it, which should take you to the code & add the MouseClick code. Then just write inside it whatever you want to do when the user clicks the mouse.

private void textBox2_TextChanged_1(object sender, EventArgs e)
      {
   //         textBox2.Text = "Whenever you write something in the box and hit enter, this text will appear.";
          //the next part did not work until I commented this out
//but you had nothing there anyway so it shouldn't matter for your code
    }

        private void textBox2_MouseClick(object sender, MouseEventArgs e)
        {
            textBox2.Text = textBox1.Text; //this will make the text in the 1st box appear in the 2nd one when the user clicks this box
        }

No, i dont want it to do that.

I want it to do this:
1.If i want lets say horizontal line in textbox 17
2.I click text box 17
3.I click the horizontal line button
4.horizontal line is in text box 17

Here's a slimmed down example of what I think you're looking for. I've created a form, 5 textboxes, 5 buttons. For the purposes of this example, the 5 values of note are A, B, C, D, and E.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        List<Button> buttons = null;
        List<string> values = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            buttons = new List<Button>() { button1, button2, button3, button4, button5 };
            values = new List<string>() { "A", "B", "C", "D", "E" };

            // temp list of boxes
            List<TextBox> boxes = new List<TextBox>() { textBox1, textBox2, textBox3, textBox4, textBox5 };

            foreach (Button button in buttons)
            {
                button.Click += new EventHandler(button_Click);
            }

            foreach (TextBox textBox in boxes)
            {
                textBox.Click += new EventHandler(textBox_Click);
            }
        }

        void textBox_Click(object sender, EventArgs e)
        {
            this.ActiveTextBox = (TextBox)sender;
        }

        void button_Click(object sender, EventArgs e)
        {
            if (this.ActiveTextBox != null)
            {
                int index = buttons.IndexOf((Button)sender);
                string value = values[index];

                this.ActiveTextBox.Text = value;
            }
        }

        private TextBox ActiveTextBox { get; set; }
    }
}

If you make your 1st textbox invisible, you can assign the value of each button to that textbox (whenever you click a button, just as you have it now) and then when you click on any other textbox make it's value equal to the first one.

It's not the exact thing you want done: Click on a textbox then a button and assign that button's value to the textbox.

It is almost the same though: Click on a button and then a textbox and assign that button's value to the textbox.

Edit: apegram's answer is probably way better than mine, sorry!

@apegram, no offense, and I certainly do not mean to hijack someone's thread, but...

I cannot get your code to work. It gives me errors:

It doesn't like the commas on these lines, but also complains after I change them to ;s as it suggests.

buttons = new List<Button>() { button1, button2, button3, button4, button5 };
            values = new List<string>() { "A", "B", "C", "D", "E" };

            // temp list of boxes
            List<TextBox> boxes = new List<TextBox>() { textBox1, textBox2, textBox3, textBox4, textBox5 };

Here's the other error:
'WindowsApplication1.Form1.ActiveTextBox.set' must declare a body because it is not marked abstract or extern

@apegram, no offense, and I certainly do not mean to hijack someone's thread, but...

I cannot get your code to work. It gives me errors:

Upgrade from C# Express 2005!

The ability to initialize generic lists at the time of declaration was added with 2008. You could do that with arrays before.

As for ActiveTextBox { get; set; }, that's another new feature with C# 2008: auto-implemented properties.

Here's a 2005-friendly version.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        List<Button> buttons = null;
        List<string> values = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            buttons = new List<Button>();
            buttons.Add(button1);
            buttons.Add(button2);
            buttons.Add(button3);
            buttons.Add(button4);
            buttons.Add(button5);

            values = new List<string>();
            values.Add("A");
            values.Add("B");
            values.Add("C");
            values.Add("D");
            values.Add("E");

            // temp list of boxes
            List<TextBox> boxes = new List<TextBox>();
            boxes.Add(textBox1);
            boxes.Add(textBox2);
            boxes.Add(textBox3);
            boxes.Add(textBox4);
            boxes.Add(textBox5);

            foreach (Button button in buttons)
            {
                button.Click += new EventHandler(button_Click);
            }

            foreach (TextBox textBox in boxes)
            {
                textBox.Click += new EventHandler(textBox_Click);
            }
        }

        void textBox_Click(object sender, EventArgs e)
        {
            this.ActiveTextBox = (TextBox)sender;
        }

        void button_Click(object sender, EventArgs e)
        {
            if (this.ActiveTextBox != null)
            {
                int index = buttons.IndexOf((Button)sender);
                string value = values[index];

                this.ActiveTextBox.Text = value;
            }
        }

        private TextBox _activeTextBox = null;
        private TextBox ActiveTextBox
        {
            get { return _activeTextBox; }
            set { _activeTextBox = value; }
        }
    }
}
commented: Wow, very helpfull! +6
commented: Thank you! :) +1

Thanks ApeGram.

Now i have to figure out how to apply it to 160 more boxes !

Finaly ! Done.

-Now does anyone know how i can make it so that when i finish my ASCII art (using unicode characters) I can copy it (as in copy -> paste in a document?)

-Clear all the text in the program

-A button linked to XBOX.COM

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.