Re: rtf problem - nonbreaking hyphen breaks + other problems (REVISED)

G

Guest

I'm using a read only rich text box to format some text. In the text is a
series of phone numbers separated by a comma and a space. I don't want the
phone numbers to be split.

Here's what I've done. I replace '-' with '\_'which is supposed to be the
non-breaking hyphen. If I look at the string before it is stored in the
rtf it looks like ';555\_201\_1234, 555\_201\_1111, '. In the rtf it looks
like '555-201-1234, 555-201-1111, '.

When the form is displayed at the normal size, the series of phone numbers
are displayed correctly except that the space after the comma is at the
beginning of the next line.

When the form is made larger the vertical scroll bar is removed (the rtf
box fits on the screen) and the series of phone numbers split on one of the
hyphens screwing up the format. If there enough phone numbers to keep the
vertical scroll bar, the data is displayed correctly, except that the lines
start with a space.

When the form is restored to it's original size, the vertical scroll bar is
missing if it wasn't required on the larger window. If you set the cursor in
the rtf box and move the cursor down the vertical scroll bar appears.

I see 3 problems:

1. The rtf control string for a nonbreaking hyphen doesn't work.
2. If a line is split on a space the space should be at the end of the line.
3. Vertical scroll bar is missing when required.
 
J

Jeffrey Tan[MSFT]

Hi tsiGeorge,

Thanks for your post.

I do not think I understand your scenario well.

First, how do you store ";555\_201\_1234, 555\_201\_1111, " string in the
rtf? This statement:
this.richTextBox1.Rtf=@";555\_201\_1234, 555\_201\_1111, ";
will generate an " Invalid file format." exception

Second, defaultly, I do not know how your vertical scrollbar appears? I
think there is only single text in the richtextbox, which should not cause
the vertical scrollbar to appear.

Currently, I suggest you attach a sample project for us to demonstrate this
issue. Then we can understand your problem better. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Jeffrey
(you may remember me from the MDI client problem)
Try this for the string
Dim I as integer
Dim S as string
For I = 0 to 25
S &= "555\_201\_1234, 555\_201\_1111, "
Next
S = S.Substring(0, S.Length-2)
RichTextBox1.rtf = "{\rtf1\ansi " & S & "}"

Create a MDI client form.
Set the rich text box width so that 3 phone numbers are displayed per line
and the height so the vertical scroll bar is active. Maximize the form and
then restore to the orignal size.
 
J

Jeffrey Tan[MSFT]

Hi George,

Thanks for your reproduce project.

With it, I can reproduce your #3 vertical scrollbar disappear issue.
Currently, I am not sure what internally cause out this problem, however,
we can workaround this issue with adding a refresh statement call after the
height changing. Like this:

Private Sub Form2_resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.SizeChanged
RichTextBox1.Size = New Drawing.Size(RichTextBox1.Size.Width, _
lblMsg.Location.Y - RichTextBox1.Location.Y - 8)
Me.RichTextBox1.Refresh()
End Sub

After adding this line of code, it should work well.

For #1 and #2, I think I still did not understand your point. When I run
the project, I can see certain phone number splitted on my machine like
this:
218-229-2908, 218-283-0932, 218-365-0064, 218-365-0843, 218-834-0781,
218-834-0783, 320-558-4021, 320-
558-4023, 320-692-4398, 320-692-4715, 320-983-2870, 320-983-6245,
507-423-1045, 651-257-2635, 651-462-
0649, 763-479-2503, 763-972-5894, 952-446-8167, 952-446-8169, 952-472-3782,
952-472-5089

For #2, can you show me you steps about how to force the line to splitted
by a space?

I will wait for your further feedback. Thanks
=====================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Jeffrey
The refresh workaround worked.

On the splitting problems.
When the windows is a maximum size look at
218-834-0783, 320-558-4021, 320-
558-4023, 320-692-4398, 320-692-4715, 320-983-2870, 320-983-6245,
Notice that the phone number 320-558-4023 was split on 2 lines. But the
hyphens are nonbreaking hyphens. In rtf code \_ was used.

When the window is at the minimum size notice that the phone numbers are
slightly to the right of all the other values in the right column. If you
look at the value of the S variable (i think it's S) you will see it starts
with a space so that when the string is split on a space the phone numbers
still line up. It is very obvious that when the string is split on a space
the space is at the beginning of the line when the initial space is removed.
Hope this makes sense to you. The phone numbers should always be displayed in
nice columns.
--
tsiGeorge


"Jeffrey Tan[MSFT]" said:
Hi George,

Thanks for your reproduce project.

With it, I can reproduce your #3 vertical scrollbar disappear issue.
Currently, I am not sure what internally cause out this problem, however,
we can workaround this issue with adding a refresh statement call after the
height changing. Like this:

Private Sub Form2_resize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.SizeChanged
RichTextBox1.Size = New Drawing.Size(RichTextBox1.Size.Width, _
lblMsg.Location.Y - RichTextBox1.Location.Y - 8)
Me.RichTextBox1.Refresh()
End Sub

After adding this line of code, it should work well.

For #1 and #2, I think I still did not understand your point. When I run
the project, I can see certain phone number splitted on my machine like
this:
218-229-2908, 218-283-0932, 218-365-0064, 218-365-0843, 218-834-0781,
218-834-0783, 320-558-4021, 320-
558-4023, 320-692-4398, 320-692-4715, 320-983-2870, 320-983-6245,
507-423-1045, 651-257-2635, 651-462-
0649, 763-479-2503, 763-972-5894, 952-446-8167, 952-446-8169, 952-472-3782,
952-472-5089

For #2, can you show me you steps about how to force the line to splitted
by a space?

I will wait for your further feedback. Thanks
=====================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi tsiGeorge,

Thanks for your feedback.

With your further feedback, I think I understand your problem.

First, nonbreaking hyphen is "\_" in RTF specification, not "\emdash", so I
have replaced all the "\emdash" with "\_" in your project. However, it
seems that this also does not work.

Second, I have also seen your space at the begining of each line problem.

For these 2 issues, I will spend a little more time into them, I will
update you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Jeffrey,
Sorry about that. I've tried \_, \endash, \emdash and none of them worked.
Your would think an \endash would work since it isn't a hyphen but once it
gets loaded into the rtf variable they all look alike.
 
J

Jeffrey Tan[MSFT]

Hi tsiGeorge,

Sorry for letting you wait for so long.

I have contacted our product team for this issue, and below is their
feedback:
"It looks like the Unicode character richedit supports as a nonbreaking
hyphen is 8209: try replacing
320\_558\_4021
with
320\u8209?558\u8209?4021"

So I suggest you try to replace "\_" with "\u8209?" to see if this helps.
Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Sine Nomine

I have contacted our product team for this issue, and below is their
feedback:
"It looks like the Unicode character richedit supports as a nonbreaking
hyphen is 8209: try replacing
320\_558\_4021
with
320\u8209?558\u8209?4021"

So I suggest you try to replace "\_" with "\u8209?" to see if this helps.

Non-breaking space also doesn't work - any ideas for that one?

Thanks.
 
J

Jeffrey Tan[MSFT]

Hi tsiGeorge,

Thanks for your feedback.

Yes, based on the further feedback from the Winform team, it seems that
this only works for certain font on his machine.

Currently, it seems that this issue is not Winform side, but the underlying
RichEdit control side. I have sent an email to the RichEdit team for help
on this issue. I will update you for any further feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi tsigeorge ,

I think you can use the below C# to VB.net converter to migrate the project
code into VB.net project:
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

However, if you still have difficult to do the convertion, please feel free
to tell me, I will take out some time to help you on this. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

tsigeorge

Jeffrey,
Thanks, that converter came up with a lot of errors but I hacked through
it and created the attached class. This works and cures the non-breaking
hyphen problem. It doesn't cure a break on a normal space occuring
before the space instead of after it (like in Notepad). More important,
I don't think I can use msftedit.dll since we support WIn9X and Win2000.
This would require that we distribute msftedit.dll and I don't know if
Microsoft allows distribution of the file. Also, installing the dll goes
against my .net brain. One thing we push with .net is that it will not
affect any other application. Let me know what your think.

Thanks

Hi tsigeorge ,

I think you can use the below C# to VB.net converter to migrate the project
code into VB.net project:
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

However, if you still have difficult to do the convertion, please feel free
to tell me, I will take out some time to help you on this. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Imports System.Runtime.InteropServices
Namespace rtftest
Public Class MyRichTextBox
Inherits System.Windows.Forms.RichTextBox

<DllImport("kernel32.dll")> _
Overloads Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
End Function

Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim lResult As IntPtr = LoadLibrary("msftedit.dll")
If IntPtr.op_Equality(lResult, IntPtr.Zero) Then
MessageBox.Show(Marshal.GetLastWin32Error().ToString())
End If
Dim cp As CreateParams = MyBase.CreateParams
cp.ClassName = "RICHEDIT50W"
Return cp
End Get
End Property
End Class
End Namespace
 
J

Jeffrey Tan[MSFT]

Hi tsigeorge,

Thanks for your feedback.

I used to contact our product team for such issue, the answer is No.
RichEdit4.1 is only included in above WindowsXP Sp1, and it can not be
redistributed in early version of Windows. Please see my another post:
http://groups.google.com/groups?hl=zh-CN&lr=&frame=right&th=ea93007fcd21255e
&seekm=E2716469-59A0-4E21-BB23-FDAB178F9EAF%40microsoft.com#link14

So I can not think of a workaround for your problem. Thanks for your
understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

tsigeorge

Jeffrey,

Sorry, BUT I DON'T UNDERSTAND. If I've got this right there is a known
bug and you've known about it since at least August 2004 and you want ME
to post a message on the MS wish list. I think you should have reported
this bug last year and maybe it would have been fixed by now. If there
is a workaround by MS providing a dll and allowing us to distribute it
with our app then they should do it!
 
J

Jeffrey Tan[MSFT]

Hi tsigeorge,

Thanks for your feedback.

I think you may have some misunderstanding of my last reply.

First, the link I provide in the last reply is another UndoBuffer issue
reported by another people, not the same issue as you. So I did not know
your issue till you reported in this post.

Also, for that issue, it is a confirmed bug. However for your issue, I do
not think it is a bug, it is just because RichEdit before version4.1 does
not implement this non-breaking hyphen function. While before WindowsXP,
the RichEdit has not version4.1

Additionally, in my last reply, I say: "I used to contact our product team
for such issue, the answer is No". In this statement, "such issue" means
that we can not redistribute RichEdit4.1 to ealier version of Windows, this
will cause license problem.

Hope this clarify my point. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

tsigeorge

Jeffrey,

Ok, instead of me trying to guess what RTF specification .Net is
designed to meet, could you please tell me. In 1997 Microsoft published
a specification titled "Rich Text Format (RTF) Version 1.5
Specification". This spec has "\_" and also \hyphpar. Neither work in
..Net. Also, version 1.4 (don't know the date) includes non-breaking
hyphen and that spec was for MS-DOS and Win95. Maybe, the RTF group
needs copies of the specification. When you don't meet your own spec, I
think it's called a BUG!
 
J

Jeffrey Tan[MSFT]

Hi tsigeorge,

Thanks for your feedback.

Yes, this issue is confirmed by our product team as a limitation of
RichEdit3.0, and only the version above RichEdit4.1 support this function.
However, RichEdit4.1 is only included in WinXP SP1, and can not be
redistributed in ealier OS.

So currently, I can not think of any solution for your scenario. If you
still have this is critical for you, I suggest you contact Microsoft PSS,
maybe they can submit a hotfix for you. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top