Prev: API-Guide
Next: Find Addin
From: Mike Williams on 5 Apr 2010 04:35 "Bee" <Bee(a)discussions.microsoft.com> wrote in message news:668E1CA5-6D2C-421D-A968-8B7564B86AF1(a)microsoft.com... > I copied a RTB from a different part of the app (on a different form) > over this the misbehaving form. Hoping that some parameter would > be the problem. The copied RTB was using plain text set to Lucida > Consols and it was wrapping correctly. After the copy and rename, > the copied form FAILED! just like the one taht I searched the code > source for any RTB settings and found nothing. I made sure I set the > Multiline and RightMargin=0 as was before. I'm still not sure what you are saying there, especially regarding "copy and rename". Somebody here told you to create a new and completely separate VB project containing just one Form with one RTB set to RightMargin zero and Multiline True and Scrollbar set to rtfVertical and load the "problem" .rtf file into it. Have you tried that? If so, what happens? > The wrap occurs several words past the right vertical scroll bar > not just into the vert scroll bar. The wrap changes location relative > to the width the RTB is resized. Well I noticed in one of your code examples you were setting the rightmargin to a percentage of the Width. Are you still doing that? > It must have something to do with the rich text > that theRTB is trying to display. That could well be, but you still need to check the simple basic stuff first. If you've checked all the basics, and specifically if you have tried what I said above (one RTB in a brand new otherwise completely empty project with the specific problem rtf file loaded into it), then you're probably right and the rtf probably does contain some fancy formatting information. In that case (AFTER you have tried what I said above) then you can try altering the paragraph formatting of the entire contents of the RTB, just to check what happens. To do that, start a completely new VB project with a Form containing one RTB and one Command Button. Leave the RTB at its default settings of RightMargin Zero and MultiLine True and set it to have a vertical scroll bar. Manually resize the RTB to a reasonably large size in the IDE. Then paste in the following code and change the hard coded path/file name in the Command1_Click event so that it loads the specific rtf file you are having problems with. Run the project and click the button. In this specific example you should end up with the rtf in the RichTextBox but all the paragraphs should be fully justified (straight edges at both the left and right sides of each paragraph) and there should be a 50 pixel blank left margin and a 50 pixel blank right margin. Is that what you get? Mike Option Explicit Private Declare Function SendMessage Lib "user32" Alias _ "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private Const MAX_TAB_STOPS As Long = 32 Private Type PARAFORMAT2 cbsize As Integer pad As Integer dwMask As Long wNumbering As Integer wReserved As Integer dxStartIndent As Long dxRightIndent As Long dxOffset As Long wAlignment As Integer cTabCount As Integer lTabstops(0 To MAX_TAB_STOPS - 1) As Long dySpaceBefore As Long dySpaceAfter As Long dyLineSpacing As Long sStyle As Integer bLineSpacingRule As Byte bOutlineLevel As Byte wShadingWeight As Integer wShadingStyle As Integer wNumberingStart As Integer wNumberingStyle As Integer wNumberingTab As Integer wBorderSpace As Integer wBorderWidth As Integer wBorders As Integer End Type Private Const WM_USER As Long = &H400 Private Const EM_SETTYPOGRAPHYOPTIONS As Long = (WM_USER + 202) Private Const EM_GETPARAFORMAT As Long = (WM_USER + 61) Private Const EM_SETPARAFORMAT As Long = (WM_USER + 71) Private Const TO_ADVANCEDTYPOGRAPHY As Long = &H1 Private Const PFM_ALIGNMENT As Long = &H8 Private Const PFM_OFFSET As Long = &H4 Private Const PFM_OFFSETINDENT As Long = &H80000000 Private Const PFM_RIGHTINDENT As Long = &H2 Private Const PFA_LEFT As Long = &H1 Private Const PFA_RIGHT As Long = &H2 Private Const PFA_CENTER As Long = &H3 Private Const PFA_JUSTIFY As Long = &H4 Private Sub SelFullyJustify(RTB1 As RichTextBox, _ Justification As Long, leftMargin As Long, _ rightMargin As Long) Dim PF2 As PARAFORMAT2, retVal As Long PF2.cbsize = Len(PF2) retVal = SendMessage(RTB1.hwnd, _ EM_SETTYPOGRAPHYOPTIONS, _ TO_ADVANCEDTYPOGRAPHY, _ ByVal TO_ADVANCEDTYPOGRAPHY) If retVal <> 0 Then SendMessage RTB1.hwnd, EM_GETPARAFORMAT, 0&, PF2 PF2.dwMask = PFM_ALIGNMENT Or PFM_OFFSET _ Or PFM_OFFSETINDENT Or PFM_RIGHTINDENT PF2.wAlignment = Justification PF2.dxStartIndent = leftMargin * Screen.TwipsPerPixelX PF2.dxRightIndent = rightMargin * Screen.TwipsPerPixelX PF2.dxOffset = 0 SendMessage RTB1.hwnd, EM_SETPARAFORMAT, 0&, PF2 End If End Sub Private Sub Command1_Click() RichTextBox1.LoadFile "c:\temp\const.rtf" RichTextBox1.SelStart = 0 RichTextBox1.SelLength = Len(RichTextBox1.Text) SelFullyJustify RichTextBox1, PFA_JUSTIFY, 50, 50 RichTextBox1.SelStart = 0 End Sub
From: Mike Williams on 5 Apr 2010 06:16 "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote in message news:%23P4u9rJ1KHA.224(a)TK2MSFTNGP06.phx.gbl... By the way, in the code I posted in my previous response I called the function: Private Sub SelFullyJustify(RTB1 As RichTextBox . . etc That was the name I originally gave it and, as you will see from the example, I have since modified it so that it will do whatever justification (left, right, centre, full) and whatever left and right margins you pass to it, so if it works for you and if you keep it in your code you might wish to change its name accordingly. Perhaps you could call it: Sub SetTheCurrentSelectionMarginsAndJustification (RTB1 . . etc I like long names ;-) Mike
From: Nobody on 5 Apr 2010 10:09 Ignored questions: "JPB" <jasonpeterbrown(a)gmail.com> wrote in message news:b2c5830f-cef1-44ef-855b-e3f615985119(a)10g2000yqq.googlegroups.com... > what OS are you using? What version of > richtx32.ocx do you have?
From: Bee on 5 Apr 2010 13:11 Wow!. Mike you did it again. Our posts must have crossed photons so ignore my previous last post. Your code example WORKS PERFECTLY! Many thanks. "Mike Williams" wrote: > "Mike Williams" <Mike(a)WhiskyAndCoke.com> wrote in message > news:%23P4u9rJ1KHA.224(a)TK2MSFTNGP06.phx.gbl... > > > By the way, in the code I posted in my previous response I called the > function: > > Private Sub SelFullyJustify(RTB1 As RichTextBox . . etc > > That was the name I originally gave it and, as you will see from the > example, I have since modified it so that it will do whatever justification > (left, right, centre, full) and whatever left and right margins you pass to > it, so if it works for you and if you keep it in your code you might wish to > change its name accordingly. Perhaps you could call it: > > Sub SetTheCurrentSelectionMarginsAndJustification (RTB1 . . etc > > I like long names ;-) > > Mike > > > > . >
From: Mike Williams on 5 Apr 2010 16:28
"Bee" <Bee(a)discussions.microsoft.com> wrote in message news:890253D9-9F9D-4F2F-946A-97672070B740(a)microsoft.com... > Your code example WORKS PERFECTLY! You're welcome. By the way, I used full justification in order that you could easily see the right edge of the text from any point in your document so that you could easily see whether your problem had been solved or not. You can of course change that to left justification or whatever else you wish. Also, and this is particularly important, I used a left and right paragraph indent of 50 pixels for all paragraphs in the document, again in order that you could easily see the results. Setting paragraph indents for the whole document in this way is not what you would normally want to do (there are other ways of setting "display" margins in the RTB if that is what you need to do). The reason I say that it is not normally wise to do it in the way I have done in the example is because if you save the document as rtf using RTB.SaveFile then those 50 pixel left and right indents (0.521 inches on a computer running at the standard 96 dpi setting) will be part of the rtf document itself (rather than merely an effect of the visible RTB display) and therefore when you load the saved document into a word processor then those left and right indents of 0.521 inches will effecively be "added to" the standard default left and right page margins of your word processor. In other words, if your copy of Micro$oft Word or whatever normally uses a 1 inch left and right margin (as is typical in the UK) then you will end up with apparent 1.521 inch left and right margins (0.521 inches of which are actually paragraph indents). This is fine if that is what you want, but it is not the normal requirement. Setting left and right paragraph indents in the way that I have done in the code I posted is normally what you would do to just one or two (or more) paragraphs of a document when you specifically want those paragraphs to be indented in at either side, differently from the rest of the paragraphs in the document. I just thought I would mention that point for completeness. Mike |