Autor Beitrag
dragon_77
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Do 11.01.07 23:35 
Hi,

ich möchte gerne folgendes Realisieren:
Ich habe ein ganz normales Memo. Jetzt möchte ich einen Roten Strich der vertikal über das Memo geht. Mit der Maus
soll dieser "Slider" auch nach links und rechts verschoben werden können. Im Prinzip möchte ich soetwas in in Photoshop die Hilfslinien.

Der Sinn dahinter ist das ich ein Progrämmchen schreiben möchte speziell um Songtexte zu verfassen.
Der "Slider" dient zum einhalten und markieren der Zeilenlänge. (Kann je nach Song und Musikstil sehr wichtig sein)

Kann mir jemand einen Tipp geben wie ich am besten soetwas realisiere?

Gruss
d77
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Fr 12.01.07 14:04 
Memo hat keinen Canvas. Aber Du könntest z.B. eine PaintBox drauflegen und dort die bewegliche vertikale Linie malen. Falls Du Interesse hast, kann ich Dir mal ein bisschen Code posten. Hab das mal in einer anderen Applikation geschrieben - läuft sehr schnell (XOR-Methode des Pen).
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Fr 12.01.07 14:10 
Gibt es keine Alternative um das Problem mit nur einer Komponente zu lösen?

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Fr 12.01.07 14:29 
Ich kenne keine (was nicht heißen muss, dass es keine gibt). Aber ich schreibe lieber ein paar Zeilen Code, als mir die IDE mit jeder Menge Komponenten zuzumüllen. Ist natürlich Ansichtssache. :)
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Fr 12.01.07 15:01 
Naja, wenn mans denn häufiger braucht ^^ son memo mit canvas is doch was nettes :)

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: Fr 12.01.07 15:16 
Also, damit Ihr mal anfangen könnt, poste ich einfach mal die paar Zeilen. Die kernroutinen sind zusammen gerade mal ein gutes Dutzend Zeilen. Hab's nicht ganz von meinem Müll befreit, aber ein bisschen könnt Ihr ja auch tun... :mrgreen:
Muss jetzt nämlich weg.
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
//..
 xa: Integer;  //Position of Hairline
//..
procedure SetPaintBoxBounds;  // Define Size and Position of PaintBox
begin
  with Form1.Paintbox1 do begin
   // Top :=PBTop;  //#### Das hier musst Du eben anpassen (Memo-Größe?) ####
   // Left :=PBLeft;
   // Height :=PBHeight;
   // Width :=PBWidth;
    Cursor :=crNone; xa:=0;  //Init Cursor and pos. for Hairline in Paintbox
  end;
end;

//----  Show moving Hairline when Mouse is within Paintbox -----
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var xf: Single;          //xf is floating point equivalent to xa
begin
  //Panel19.Visible :=true;      //------ Display hairline result field
  with Form1.PaintBox1.Canvas do begin
    Pen.Mode :=pmNotXor;
    Pen.Color :=clRed;                      //Hairline with red colour
    MoveTo(xa,0);  LineTo(xa,Height);       //First, erase line..
    MoveTo(x,0);   LineTo(x,Height);        //then, draw new line at new pos.
    xa :=x;                                 //save current position (now "old")
   // Pen.Mode :=pmCopy; Pen.Color :=clBlack; //Redraw Black Frame (Change 32_12a)
   // Brush.Style :=bsClear;                  //(to avoid erasing grid lines!)
   // Rectangle(0,0,Width,Height);
  end;
//-------- Now get the readings of the hairline position ----------
  begin
    xf :=x; //...#### hier muss halt Deine Auswertung der Position rein ####
    //...
   end;
end;
//---- Back to normal (Mouse arrow) when Mouse moves out of PB bounds -----
procedure TForm1.Panel9MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer); //##### Hier entsprechend anpassen (statt Panel9) #####
begin
  //...
  with Form1.Paintbox1 do begin
    if (x<Left) or (x>(Left + Width)) or    //Out of PaintBox bounds??
       (y<Top) or (y>(Top + Height))
    then  with Canvas do begin
      Pen.Mode:=pmNotXor;
      Pen.Color:=clRed;
      MoveTo(xa,0);  LineTo(xa,Height);     //Erase line at last position
      xa :=-1;                              //set position outside paintbox
      //...
    end;
  end;
end;

Das Ganze lag auf einem größeren Panel (Panel9). Die zweite MouseMove proc muss dann eben die benachbarte Komponente (z.B. die Form selbst) adressieren.

Edit: :oops: :oops: grrrr... Mist, PaintBox geht nicht auf einem Memo :evil:
aim65
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 312

Win 9x, Win XP
Delphi 3pro, 7PE
BeitragVerfasst: So 14.01.07 17:07 
Da bin ich nochmal.
Wenn Du statt des Memos eine ListBox nehmen kannst 8hat 'nen Canvas), geht es einwandfrei damit:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  with ListBox1.Canvas do begin
    Pen.Mode := pmNotXor;
    Pen.Color :=clRed;                      //Hairline with red colour
    MoveTo(xa,0);  LineTo(xa,Height);       //First, erase line..
    MoveTo(x,0);   LineTo(x,Height);        //then, draw new line at new pos.
    xa :=x;
  end;
  // ..... X-Position auswerten....
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  with Listbox1 do begin
    if (x<Left) or (x>(Left + Width)) or   //Out of ListBox bounds??
       (y<Top) or (y>(Top + Height))
    then with Canvas do begin
      Pen.Mode:= pmNotXor;
      Pen.Color:= clRed;
      MoveTo(xa,0);  LineTo(xa,Height);    //Erase line at last position
      xa :=-1;                             //set position outside listbox
    end;
  end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  xa:=-1;  //#### sonst rote Linie in der LBx beim Start
end;
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 14.01.07 17:35 
Du könntest versuchen, ein TControlCanvas zu erzeugen. Ich weiß jetzt nicht ob das dann geht, aber einen Versuch ists Wert...

EDIT: habs getestet, es geht :D

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
  private
    { Private-Deklarationen }
    Last_X:integer;

....

procedure TForm1.FormCreate(Sender: TObject);
begin
  Last_X:= -1;
end;

procedure TForm1.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var c:TControlCanvas;
begin
  c:= TControlCanvas.Create;
  try
    c.Control:= Memo1;
    c.Pen.Mode:= pmNotXor;

    c.MoveTo(Last_X,0);
    c.lineto(Last_X,memo1.height);

    c.MoveTo(X,0);
    c.lineto(X,memo1.height);
    Last_X:= X;
  finally
    c.Free;
  end;
end;

Eventuell musst du noch im OnChange und anderen Ereignissen neu zeichnen, aber sonst gehts...

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Andidreas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 114

Windows XP Pro
BDS 2006
BeitragVerfasst: So 14.01.07 19:23 
Warum nimmst Du nicht SynEdit dafür? Dort ist dieser Streifen (RightEdge) schon vorhanden. Und er läßt sich auf einfache Art und Weise verschieben. Bei dem SynEdittestprogramm ist ein sehr einfacher Zeilenumbruch, der noch verfeinert werden muß.

Download Synedit: sourceforge.net/projects/synedit

Wenn man die Abfrage für den Umbruch in OnKeyPress unterbringt, statt in OnKeyUp klappt es besser.
Einloggen, um Attachments anzusehen!