By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Crazy Rich Text box

P: 36
Hi,

I have problem with rich text box, sometimes when form open and rich text have Text ... All text was Align to left and let white space (Click Her to show false ImageShack - Image Hosting :: trueqd2.jpg )
But when I click at the rich text box nothing of this problem happen?? (Click here to show true ImageShack - Image Hosting :: falseig1.jpg )


Thanx in advance .... :)
Dec 21 '08 #1
Share this Question
Share on Google+
16 Replies


P: 36
I mean that All text was Indent to left .

Any Help please ?
Dec 21 '08 #2

tlhintoq
Expert 2.5K+
P: 3,525
Can you provide the code you are using to create the TextBox, along with the code for putting the text into the box?

While I don't read the language in the images I can see that each line starts exactly the same in both photos. That seems odd because of this was just a case of the text being indented the text should have wrapped, making the following lines start at different places in the text.

I also notice that the second box appears as if the text is "slipping under" the vertical slider. Is that slider really part of the TextBox or is it separate control you have tied to the textbox?

Of course if the problem only happens with the RichTextBox isn't clicked on (doesn't have focus) then you could assign focus to the RIchTextBox when the form is done loading. That isn't really a fix for the cause, its just a bandage for the symptom.
Dec 22 '08 #3

P: 36
Can you provide the code you are using to create the Textbox ?

There is no Specific code using to create Rich Textbox just drag and drop from toolbox.

Code for putting the text into the box?
Expand|Select|Wrap|Line Numbers
  1.  
  2.   Rchtxt_Motons.Text += "\n"+"الــمـتـن:" + "\t\t" + "\n";
  3.             Rchtxt_Motons.SelectionStart = 0;
  4.             Rchtxt_Motons.SelectionLength = 13;
  5.             Rchtxt_Motons.SelectionColor = Color.Maroon;
  6.             //***
  7.             if (Bite == string.Empty)
  8.             {
  9.                 Rchtxt_Motons.Text = Rchtxt_Motons.Text + "********:"+ "\n";
  10.             }
  11.             else
  12.             {
  13.                 Rchtxt_Motons.Text +=  Bite + "\n";
  14.             }
  15.             Bite = Rchtxt_Motons.Text;
  16.             //*********Colred Motons Text
  17.             Rchtxt_Motons.SelectionStart = 13;
  18.             Rchtxt_Motons.SelectionLength = Bite.Length;
  19.             Rchtxt_Motons.SelectionColor = Color.Black;
  20.             #endregion
  21.  
  22.             #region Description
  23.             //**Add Description           
  24.             string desctxt = "\n";
  25.             if (FlageBook == 'E')
  26.                 desctxt += "********:";
  27.             if (FlageBook == 'R')
  28.                 desctxt +="********:";
  29.             if (FlageBook == 'S')
  30.                 desctxt +="********:";
  31.             if (FlageBook == 'W')
  32.                 desctxt +="********:";
  33.             desctxt = desctxt + "\t\t" + "\n";
  34.             if (MatnDesc == string.Empty)
  35.                 MatnDesc += "********:";
  36.             Rchtxt_Motons.AppendText(desctxt + "\t\t" + "\n" + MatnDesc);//**Description
  37.             MatnDesc = desctxt + "\t\t" + "\n" + MatnDesc;
  38.             Rchtxt_Motons.SelectionStart =Bite.Length+desctxt.Length;
  39.             Rchtxt_Motons.SelectionLength = MatnDesc.Length;
  40.             Rchtxt_Motons.SelectionColor = Color.Black;
  41.              #endregion
  42.             return Rchtxt_Motons;
  43.  

this is the same code used to fill rich text box but not at loading form and problem doesn't happen .

Problem as you Say Text was indented

Is that slider really part of the TextBox or is it separate control you have tied to the textbox?

yes it is, i think it is not related to solve problem .

i try to set Focus , but problem still exist .
Dec 22 '08 #4

tlhintoq
Expert 2.5K+
P: 3,525
Looks like you are adding two tabs at the end of every line. That would be the white space to the right of your text.

\t is a tab
\n is a new line

So line 36 for example builds a line of text then appends 'desctext' plus two tabs plus a newline.
Dec 22 '08 #5

P: 36
No this is not the problem, because i say that this is the same code to fill richtextbox but not at loading form and problem doesn't happen.

How it would be the problem while it was disappear when i click enter rich textbox ؟

To be sure i try to delete \t and problem still exist,
Dec 22 '08 #6

tlhintoq
Expert 2.5K+
P: 3,525
In the RichTextBox, after you have gotten an indented block of text...
Select an entire line including the indented white space, and choose 'Copy'
Then paste that selected text into a text editor or MSWord and see what the whitespace characters really are.

I am a little lost in understanding the two different conditions; one that produces a problem and one that doesn't. Please tell me if I am understanding you correctly.

You have a form with a richtext box.
The form and the richtextbox are built at design time, not being added programmatically.

If you create the form and add text to the richtext box BEFORE showing the form it breaks.
If you create the form, show the form, then add the text it does not break.

Does that sound right?

Could you show the two blocks of code that do this?
One block where it breaks and one block where it doesn't?
Dec 22 '08 #7

P: 36
I try to select all text and paste it at text editor and there is no whitespace characters appear.

Does that sound right? Yes it does

And the point is code of two cases was the same .which I was post it before.
Dec 23 '08 #8

tlhintoq
Expert 2.5K+
P: 3,525
@MarwaAlSagheer
If you can't select the white space then perhaps the problem is a little different than you first thought. Maybe the textbox LOCATION isn't where you are expecting it to be. Maybe the text is moved to the left because the textbox itself is moved to the left for some reason.
Dec 23 '08 #9

P: 36
No, textbox LOCATION doesn't change.

This white space disappears after mouce click at richtextbox.
in the case of add text to the rich text box BEFORE showing the form .

But in the case of show the form, then add the text it does not break there is no white space at rich textbox.
Dec 24 '08 #10

tlhintoq
Expert 2.5K+
P: 3,525
@MarwaAlSagheer
Wait... Maybe I missed this before.

Are you saying that you have the Form on-screen, text in the RichTextBox is shifted to the left... but when you click on the RickTextBox suddenly all of the text jumps to the right? Is that what you mean by "The white space dissappears"?
Dec 24 '08 #11

P: 36
yeeeeeeeeeeeeees , yes Mr.tlhintoq

This what I was say it from first :)

Do you have solution for this crazy richtextbox
Dec 25 '08 #12

tlhintoq
Expert 2.5K+
P: 3,525
Do you have a method attached to the .Focus, or .Click events?
Dec 25 '08 #13

P: 36
No there is no method attached to the .Focus or click , and i was trying raise mouse click event , mouse down , click and other events before showing form and none of them solve problem .
Dec 26 '08 #14

tlhintoq
Expert 2.5K+
P: 3,525
At this point I'm stumped. I can't duplicate the problem in my attempts. I can only guess it is some odd behavior that is maybe caused by how the control handles right-justified languages. Maybe the control only works out spacing and justification for such languages after display?

Have you tried your project on an OS/language/configuration where "right to left" text was off, English, left justified?

What if you .Show() the form, but keep the RichTextBox as .Visible=False until the text is complete then change the control's visible state to true?
Dec 26 '08 #15

100+
P: 344
Firstly, trying to deal with right-to-left languages may cause practical problems, You've to check if this problem happens even if you typed all code file and contents of textBox in left-to-right ! according to drag and drop, did you change the textBox's TextAlign property from left-to-right to right-to-left ?
the standard break point/new line character is to '\r\n' not '\n' when you deal with text, using '\n' wont appears new lines with copy/past.
Only suggestion, line 2
reposition the double \t to be before the Arabic literal.
I think that typing right-to-left in code file will turn the typed-line around in Visual Studio Editor, I tried it before.
Dec 27 '08 #16

P: 36
Ohhhhhhhhhhhhhhh My God
Finally it solve

As you Say Mr.tlhintoq
Keep the RichTextBox as .Visible=False until the text is complete then change the control's visible state to true .

Thannnnnnnnnnnnx Aloooooooooooooot Mr.tlhintoq

Really thank you.
I am very pleased.

But do have any logic interpretation for this problem and its solution .
Dec 28 '08 #17

Post your reply

Sign in to post your reply or Sign up for a free account.