Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: New to c#

  1. #1
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts

    New to c#

    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:

    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.

  • #2
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts
    Code:
    obj.SelectionStart = 0;  
    obj.SelectionLength = obj.TextLength;

    try that


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •