Solved

Richedit Doublespace

Posted on 1998-11-06
12
447 Views
Last Modified: 2013-11-22
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
Comment
Question by:JStan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 

Expert Comment

by:elkiors
ID: 1345895
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1345896
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
 
LVL 4

Accepted Solution

by:
BoRiS earned 100 total points
ID: 1345897
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
Independent Software Vendors: 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!

 

Author Comment

by:JStan
ID: 1345898
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1345899
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
 

Author Comment

by:JStan
ID: 1345900
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1345901
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
 

Author Comment

by:JStan
ID: 1345902
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
 

Author Comment

by:JStan
ID: 1345903
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
 
LVL 4

Expert Comment

by:BoRiS
ID: 1345904
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
 

Author Comment

by:JStan
ID: 1345905
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
 

Author Comment

by:JStan
ID: 1345906
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question