3 Replies - 832 Views - Last Post: 23 March 2013 - 09:13 AM Rate Topic: -----

#1 fatihmert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 04-March 12

Selected Textbox text length to duplicate text

Posted 22 March 2013 - 09:42 PM

Hi guys, I am just developing myself. Couldn't get the result I want. I have tried codes;

Note: TextBox.KeyUp event, CTRL + 1 event click;

input text: my dreamincode user name fatihmert

int uzunluk = textBox1.SelectedText.Length;
textBox1.SelectedText = textBox1.Text.Insert(textBox1.Selectionstart,String.Format("{0}\r\n{1}\r\n",String.Format("*",uzunluk),textBox1.SelectedText));



output;

*
fatihmert
fatihmert



int uzunluk = textBox1.SelectedText.Length;
for (int i = 0; i < uzunluk; i++) {
    textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart, "*");
}
textBox1.SelectedText = textBox1.Text.Insert(textBox1.Selectionstart,String.Format("{0}\r\n{1}\r\n",String.Format("*",uzunluk),textBox1.SelectedText));
for (int i = 0; i < uzunluk; i++){
    textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart, "*");
}



output;
*********

*********fatihmert**********fatihmert



int uzunluk = textBox1.SelectedText.Length;
for (int i = 0; i < uzunluk; i++) {
    textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart, "*");
}
textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart,"\r\n");
textBox1.SelectedText += String.Format(textBox1.SelectedText);
for (int i = 0; i < uzunluk; i++){
    textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart, "*");
}



output;
*********
*********fatihmert




the nearest this code.
int uzunluk = textBox1.SelectedText.Length;
for (int i = 0; i < uzunluk; i++) {
    textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart, "*");
}
textBox1.Text = textBox1.Text.Insert(textBox1.Selectionstart, "\n");
textBox1.SelectedText += String.Format(textBox1.SelectedText);
for (int i = 0; i < uzunluk; i++){
    textBox1.Text += "*";
}



output;
*********fatihmert*********



I want my output;
*********
fatihmert
*********



Thank you guys for insterest..
Good works..

Is This A Good Question/Topic? 0
  • +

Replies To: Selected Textbox text length to duplicate text

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Selected Textbox text length to duplicate text

Posted 22 March 2013 - 11:22 PM

int uzunluk = textBox1.Text.Length;
textBox1.Text = "*".PadLeft(uzunluk, '*') + "\n" + textBox1.Text + "\n" + "*".PadLeft(uzunluk, '*');


One way to do it.
Was This Post Helpful? 2
  • +
  • -

#3 fatihmert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 04-March 12

Re: Selected Textbox text length to duplicate text

Posted 23 March 2013 - 07:20 AM

I want to this. Thank you..

int uzunluk = textBox1.SelectedText.Length;
textBox1.SelectedText = "*".PadLeft(uzunluk, '*') + "\r\n" + textBox1.SelectedText + "\r\n" + "*".PadRight(uzunluk,'*');


Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Selected Textbox text length to duplicate text

Posted 23 March 2013 - 09:13 AM

Slightly shorter, now that I'm awake :)
int uzunluk = textBox1.SelectedText.Length + 2;
textBox1.SelectedText = "\r\n".PadLeft(uzunluk, '*') + textBox1.SelectedText + "\r\n".PadRight(uzunluk,'*');

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1