Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

Richedit Doublespace

I wrote a texteditor and am fixing it up a bit and would like to give the user the option of doublespacing the lines.
Is it possible to make the richedit doublespace lines when the user hits 'Enter' key or when the cursor reaches the end of a line when in wordwrap mode.
I am using Delphi 3.
Thanks
Jim
0
JStan
Asked:
JStan
1 Solution
 
elkiorsCommented:
Have a look at the Lines.Add methods, that should give an idea of where to start and the amount of work involved.

The problem is flagging the 'toggle' event of turning off and on the doublespace option, You've not only got to 'Add' the extra blank lines but you've also got to 'Delete' the extra lines if the user wishes to revert to SingleSpace. However, that may be difficult, since you would also have to differentiate between the users own paragraph blank lines and your apps doublespace lines.

I suppose there may be a way of inheriting the richedit and doing you're own userdraw events for handling the doublespace, but don't ask me how to do it, 'cos re-writing components is well beyond my current abilities.

Good luck anyway

Darren
0
 
viktornetCommented:
You can add an empty line with spaces, but that's a very unelligant solution... YOu could use the WM_PAINT do your job there....

Viktor
0
 
BoRiSCommented:
JStan

Here is the code to get the richedit to display doublespace, this will do it for selected lines for the whole document use the RichEdit1.Selectall;

Place this on the keydown procedure for your enter key...

var
 format: TCharFormat;
begin
   if Key = VK_RETURN then                  
      FillChar( DblSpace, sizeof(DblSpace), 0);
        with format do begin
          cbSize:= Sizeof(DblSpace);
          dwMask:= CFM_OFFSET;
          yOffset:= 60;
        end;
      RichEdit1.SelText;
      RichEdit1.Perform( EM_SETCHARFORMAT, SCF_SELECTION,
                        LongInt(@DblSpace));
end;

You may need to modify it abit to get the line number and select the text at that line and then doublespace it...

Later
BoRiS
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JStanAuthor Commented:
Hey Boris,
Just got back to work and saw your response.
I am going to check it out at home tonite ( thats where my program is)
and I will get right back to you on it.
Thanks
JStan
0
 
BoRiSCommented:
JStan

Ok, thanx for the response...Sorry One little error there, replace the following

var
 format: TCharFormat;

with

var
 DblSpace: TCharFormat;

Sorry about that, yes to sorry to you to viktornet :-)

Later
BoRiS  
0
 
JStanAuthor Commented:
Hey Boris,
I must be really lost.
I can't get it to work.
It does offset the text in relation to the cursor but it does it for every line.
So the end result  is single spaced lines.
What am I missing???
Jim

0
 
BoRiSCommented:
jstan

show me the procdure you calling, and I'll take a look also if you used the RichEdit1.Selectall then it will select the whole richedit and doublespace it...after all double spacing is just an offset of the caret show that there is a bigger gap between the sentences...

if you select only a piece of the richedit text and then use Richedit1.Seltext it should just double space the selected text...or as I mentioned you could get the line number of the memo thay are on and seltext it there...

but send your code let's take a look see...

Later
BoRiS
0
 
JStanAuthor Commented:
Increasing points to 100 for your time spent .
As soon as I get home tonite I will post the code here.
Bummer when internet is at work but Delphi is at home.
Thanks again.
JStan
0
 
JStanAuthor Commented:
Hey Boris,
Sorry it so long to get back with you.
This is the code I am trying to use.
I just put a TRichEdit on a form and used this code in the Richedit's
'OnKeyDown' event.

//////procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
    DblSpace: TCharFormat;
   begin
      if Key = VK_RETURN then
         FillChar( DblSpace, sizeof(DblSpace), 0);
           with DblSpace do begin
             cbSize:= Sizeof(DblSpace);
             dwMask:= CFM_OFFSET;
             yOffset := 60;
           end;
         RichEdit1.Seltext;
         RichEdit1.Perform( EM_SETCHARFORMAT, SCF_SELECTION,
                           LongInt(@DblSpace));

   end;
///////////

The text I type in the richedit looks the same whether I use the code or not.
If I replace 'SelText' with 'SelectAll' , it completely erases the text in the richedit.

Like I said though, I am totally lost on this.
Thanks for your help.
JStan
0
 
BoRiSCommented:
JStan

The Richedit OnKeyDown event seems to have a bug in it, I'll check the buglist for this try it on the forms onKeyDown or it works perfectly from  menu click or button click...

Try it from a button click and see the effect...also if you use the seltext the text must be selected already...SelectAll will select all the text fist then Dblspace it...

Later
BoRiS
0
 
JStanAuthor Commented:
Boris,
I have tried everything. With a menu and a button.
The best I can get the code to do is that it seems
to doublespace but then the tops of every row
of text is cut off. I just can't figure it out.
I will try some more.
Jim
0
 
JStanAuthor Commented:
I never could get the code to work but it may be me so here are the points
and I will try to find the problem.
Thanks for the time
Jim
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now