Solved

Richedit Doublespace

Posted on 1998-11-06
12
429 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 104
drawing animated level bar based on numbers 3 88
Find and Replace Stream with 0s 8 56
Dynamically Created Query 3 50
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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

911 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

19 Experts available now in Live!

Get 1:1 Help Now