BarrMan
10-24-2007, 11:26 PM
Hi,
I've made a program that converts a string to ascii and presents it in a new form.
My problem is that I can't get the click event to do what I want.
I want, when you click on the texbox that it will select the text inside it but every attemp I do to accomplish this somehow doesn't work.
Please take a look at my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Form newForm = new Form();
public Form1()
{
InitializeComponent();
}
private void btnConvert_Click(object sender, EventArgs e)
{
TextBox textbox;
string text = txtValue.Text;
for (int i = 0; i < text.Length; i++)
{
textbox = new TextBox();
textbox.Text = Convert.ToInt16(text[i]).ToString();
textbox.Location = new Point(0, i * 20);
textbox.Name = "textbox" + i;
textbox.Click += new System.EventHandler(selectThis(this));
newForm.Controls.Add(textbox);
newForm.Show();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void selectThis(object obj)
{
obj.Select();
}
}
}
Thanks.
I've made a program that converts a string to ascii and presents it in a new form.
My problem is that I can't get the click event to do what I want.
I want, when you click on the texbox that it will select the text inside it but every attemp I do to accomplish this somehow doesn't work.
Please take a look at my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Form newForm = new Form();
public Form1()
{
InitializeComponent();
}
private void btnConvert_Click(object sender, EventArgs e)
{
TextBox textbox;
string text = txtValue.Text;
for (int i = 0; i < text.Length; i++)
{
textbox = new TextBox();
textbox.Text = Convert.ToInt16(text[i]).ToString();
textbox.Location = new Point(0, i * 20);
textbox.Name = "textbox" + i;
textbox.Click += new System.EventHandler(selectThis(this));
newForm.Controls.Add(textbox);
newForm.Show();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void selectThis(object obj)
{
obj.Select();
}
}
}
Thanks.