• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Space between letters

In edit box char is #.
How can I add more empty space
between characters that appear
like : # # # # instead of ####?
0
Bosanac
Asked:
Bosanac
  • 3
  • 2
  • 2
  • +3
1 Solution
 
BlackDeathCommented:
while typing?
0
 
haehnenCommented:
for count := 0 to length(str) do begin
count := count + 1; //+2
insert(' ', str, count);
end;

maybe some problems .. not testet .. :-))

bye
0
 
BosanacAuthor Commented:
while typing?
>>No,on LoadFromFile...
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
raidosCommented:
Drop it into a temp string instead of editbox..then

For loop := 1 to Length(tempStr) do
  Editbox.text := TempStr[Loop]+' ';

That should do it

I think..
0
 
raidosCommented:
Sorry Didn't think...
0
 
CalvinDayCommented:
You use a fixed pitch font or yoou can derive your own component that overrides the default painting. In the case, you can use the windows api function ExtTextOut like in the following component. It gets a little hairy if you want to do this while typing in it.

unit spaceedit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,mask,dbctrls;

type
  TSpaceEdit = class(TCustomEdit)
  private
    FCanvas: TControlCanvas;
    FSpacing: integer;
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  protected
    procedure Change; override;
  published
    property Text;
    property OnChange;
    property Spacing:integer read FSpacing write FSpacing;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TSpaceEdit]);
end;

procedure TSpaceEdit.Change;
begin
  inherited Changed;
  Repaint;
end;

procedure TSpaceEdit.WMPaint(var Message: TWMPaint);
var
  Left,i: Integer;
  R: TRect;
  DC: HDC;
  PS: TPaintStruct;
  S: string;
  ExStyle: DWORD;
  d: array [0..255] of integer;
begin
  if FSpacing=0 then
    FSpacing:=1;
  for i:=0 to 255 do
    d[i]:=FSpacing;
  if FCanvas = nil then
  begin
    FCanvas := TControlCanvas.Create;
    FCanvas.Control := Self;
  end;
  DC := Message.DC;
  if DC = 0 then DC := BeginPaint(Handle, PS);
  FCanvas.Handle := DC;
  try
    FCanvas.Font := Font;
    with FCanvas do
    begin
      R := ClientRect;
      if not (NewStyleControls and Ctl3D) and (BorderStyle = bsSingle) then
      begin
        Brush.Color := clWindowFrame;
        FrameRect(R);
        InflateRect(R, -1, -1);
      end;
      Brush.Color := Color;
      if not Enabled then
        Font.Color := clGrayText;
      S := Text;
      if PasswordChar <> #0 then FillChar(S[1], Length(S), PasswordChar);
      Left :=1;
      ExtTextOut(FCanvas.Handle,Left,0,ETO_CLIPPED,@R,Pointer(S),length(s),@d);
    end;
  finally
    FCanvas.Handle := 0;
    if Message.DC = 0 then EndPaint(Handle, PS);
  end;
end;
end.
0
 
srbenavrbeCommented:
Wow!
0
 
CalvinDayCommented:
>Wow!

I stole most of this from TDBEDIT and changed TextRect(R, Left, Margins.Y, S); to ExtTextOut(FCanvas.Handle, Left, 0, ETO_CLIPPED, @R, Pointer(S), length(s), @d).

I was really surprised it worked the first time. It only took about 10 minutes. I thought, what the heck, might as well post it.

What's really funny is the letters will actually overwrite each other with small spacing values.


   
0
 
BosanacAuthor Commented:
Points to Calvin!
0
 
CalvinDayCommented:
Thanks.
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.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now