Solved

Richedit Doublespace

Posted on 1998-11-06
12
436 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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