Elfoc
Elfoc

Reputation: 3689

Getting Char From Position in C# textbox

I'm trying to get 3 character from textbox -> for example: "test" and get 3 from this text.

I'm trying something like that where printer1_logo.text is another textbox where i'd like to have 4 character from textbox RefrenceNumber.

Printer1_Logo.Text=RefrenceNumber.GetCharFromPosition(4);

Errors:

Argument 1: cannot convert from 'int' to 'System.Drawing.Point' (CS1503) - D:\App\MainForm.cs:249,66

The best overloaded method match for 'System.Windows.Forms.TextBoxBase.GetCharFromPosition(System.Drawing.Point)' has some invalid arguments (CS1502) - D:\App\MainForm.cs:249,31

Upvotes: 1

Views: 17715

Answers (3)

KMC
KMC

Reputation: 20046

You can simply use SubString to cut out from a string:

string subString1 = textbox1.Text.Substring(0,3)

Upvotes: 1

Ales Ruzicka
Ales Ruzicka

Reputation: 2790

In C# textBox1.Text = textBox2.Text[2].ToString()

In VB textBox1.Text = textBox2.Text(2).ToString

If you need more than 1 char

textBox1.Text = textBox2.Text.SubString(2,2)

Upvotes: 5

GetCharFomPosition (Position means Coordinates. isn't char index) you can also use string as a char array for example :

Char  theChar = Printer1_Logo.Text[2]; // index is start at 0

Upvotes: 4

Related Questions