Tuesday 15 June 2010

c# - automatic capital letter at the beginning of a word when typing in textbox -



c# - automatic capital letter at the beginning of a word when typing in textbox -

i create function when typing in textbox origin of each sentence automatically becomes large.

i've been unsuccessfully trying create vb.net, when tried c # can not run properly.

i not know mistake, hope of can help improve c# code give thanks you.

my function in class c# (failed) :

class clstext { public int current_point = 0; public bool remove_handle = false; public string tulis(string text) { string[] validasi_char = new string[] { " ", ".", "(", ")", "!", "@", "$", "%", "&", "*", "/", "?", "+", "-", ",", ">", "<", "'", "~", "`" }; string str_temp = ""; foreach (string vchar in validasi_char) { string[] split_temp = text.split(validasi_char,stringsplitoptions.); str_temp = ""; foreach (string txt in split_temp) { str_temp = str_temp + txt.substring(0,0).toupper() + txt.substring(1, txt.length) + vchar; } text = str_temp.substring(0, str_temp.length - 1); } text = text.substring(0, 0).toupper() + text.substring(1, text.length); homecoming text; } }

my code in textbox c# (failed) :

clstext asd = new clstext(); if (asd.remove_handle == true) { asd.current_point = textedit1.selectionstart; asd.remove_handle = true; textedit1.text = asd.tulis(textedit1.text); } textedit1.select(asd.current_point, 2);

my function in vb.net (success) :

public current_point integer = 0 public remove_handle boolean = false public function tulis(byval text string) string dim validasi_char() string = {" ", ".", "(", ")", "!", "@", "$", "%", "&", "*", "/", "?", "+", "-", ",", ">", "<", """", "'", "~", "`"} dim str_temp string = "" each vchar in validasi_char dim split_temp() string = split(text, vchar) str_temp = "" each txt in split_temp str_temp = str_temp + mid(txt, 1, 1).toupper + mid(txt, 2, txt.length) + vchar next text = mid(str_temp, 1, str_temp.length - 1) next text = mid(text, 1, 1).toupper + mid(text, 2, text.length) homecoming text end function

my code in textbox vb.net (success) :

private sub textedit1_editvaluechanging(sender object, e devexpress.xtraeditors.controls.changingeventargs) handles textedit1.editvaluechanging if remove_handle = true goto docurrentpoint current_point = textedit1.selectionstart remove_handle = true textedit1.text = tulis(textedit1.text)

docurrentpoint: remove_handle = false textedit1.select(current_point, 0) end sub

i think understand looking for. want textbox automatically capitalize first letter of every sentence. have solution should work intended desire. first have create ontextboxchanged event:

private void ontextchanged(object sender, eventargs e) { textbox mytextarea = (sender textbox); if (mytextarea.text.length > 3) { char period = mytextarea.text.elementatordefault(mytextarea.text.length - 3); char space = mytextarea.text.elementatordefault(mytextarea.text.length - 2); char newestcharadded = mytextarea.text.last(); if(period == '.' && space == ' ' && char.isletter(newestcharadded)) { capitalizefunction(mytextarea, newestcharadded); } } else if (mytextarea.text.length == 1) { char newestcharadded = mytextarea.text.last(); if(char.isletter(newestcharadded)) { capitalizefunction(mytextarea, newestcharadded); } } }

this monitor characters entered within text box, , identify end of sentence period. easy plenty incorporate more characters punctuation. incorporated first character user come in consistency. here back upwards function:

private void capitalizefunction(textbox mytextarea, char newestcharadded) { // take out lowercase letter mytextarea.text = mytextarea.text.remove(mytextarea.text.lastindexof(newestcharadded), 1) + char.toupper(newestcharadded); // returns focus end of string mytextarea.selectionstart = mytextarea.text.length; mytextarea.selectionlength = 0; }

the part code can utilize richtextbox changing appropriate types. have event need tie desired textbox this:

mytextbox.textchanged += ontextchanged;

c# winforms vb.net-to-c#

No comments:

Post a Comment