Solved

Richedit Doublespace

Posted on 1998-11-06
12
423 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
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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now