Autor Beitrag
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 31.07.06 16:18 
Hallo!
Hätte folgende Frage:
Ich habe in meinem TRichEdit die Property WantReturns auf false gesetzt, da ich es als Eingabefeld in einem Chatprogramm missbraucht habe. Nun ist es in dem Programm möglich entweder Nachrichten mit der Kombination Enter oder Strg+Enter zu versenden.

Nimmt man die Option Strg+Enter, so soll mit Enter ein Zeilenumbruch eingefügt werden, also das ganz normale Verhalten. Die Property WantReturns will ich aber auf false belassen, da ich sonst beim Versenden der Nachricht in Schwierigkeiten gerate (würde hier zu weit führen).

Ich möchte nun manuell die Entertaste per Code simulieren, bzw. deren Wirkung als Zeilenumbruch.
Einfache Codestellen wie
ausblenden Delphi-Quelltext
1:
RichEdit.Lines.Add('');					

tauegen an dieser Stelle nicht, weil was wäre, wenn der Cursor nicht am Ende des Textes ist?

Ich tippe ganz stark darauf, dass ich das RichEdit ganz einfach mit einer Message bombardieren muss (via RichEdit.Perform), allerdings hab ich bisher noch nix gefunden, wie ich das realisieren könnte. Man beachte, dass ein einfaches Enter-drücken-lassen nicht genügt, da dadurch kein Zeilenumbruch erstellt wird.

Vielen Dank
Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN


Zuletzt bearbeitet von alias5000 am Mo 31.07.06 20:07, insgesamt 1-mal bearbeitet
Arno Nym
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131



BeitragVerfasst: Mo 31.07.06 17:41 
Hi!
wenn ich es richtig verstanden habe, willst du einfach irgendwo im Richedit einen Zeilenumbruch einfügen. Das geht in dem du an der Stelle einfach in den Text das Ascii-Zeichen für den Carriage Return einfügst. Also z.B. am Ende des Textes: Richedit1.Text := Richedit1.Text + CHR(13);
MFG, Arno Nym
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 31.07.06 18:46 
Hallo,

im OnKeyDown-Event des RichEdit:
ausblenden Delphi-Quelltext
1:
2:
  if Key = VK_RETURN then
    RichEdit1.SelText := #13#10;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 31.07.06 20:05 
:autsch:
also das hätte mir auch selber auffallen können :evil:
Vielen Dank Arno Nym und Lannes!

Aber ich hab noch eine ähnliche Frage:

Ich habe ja WantReturns auf false. Das bedeutet, dass das RichEdit dann automatisch mit der Tastenkombination Strg+Enter eine Neue Zeile einfügt. In diesem Fall will ich diese Zeile da aber nicht mehr haben.

Ich hab schon Spielereien, wie mit RichEdit.lines.Delete([letzte Zeile]); versucht, die letzte Zeile wegzulöschen, ging aber nicht. Mit RichEdit.Text := copy(RichEdit.Text, 0, length(RichEdit.Text)-2); bekomme ich zwar den letzten Zeilenumbruch weg, allerdings gehen mit dem neuen Zuweisen von RichEdit.Text sämtliche Formatierungen verloren, was ich wiederum nicht will. Jetzt gehts also drum, zu verhindern, dass mit Strg+Enter ein Zeilenumbruch kommt.
Ich hab in OnKeyDown/Press/Up auch schon die entsprechenden Key-Variablen manipuliertm aber irgendwie tut ers net.

BTW: irgendwie wunderts mich, dass die Sache mit dem lines.delete keine Auswirkung zeigt :eyes:

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Flocke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win 2000, Win XP, Win 2003, Linux
Delphi 2006 Prof.
BeitragVerfasst: Mo 31.07.06 20:51 
user profile iconalias5000 hat folgendes geschrieben:
Mit RichEdit.Text := copy(RichEdit.Text, 0, length(RichEdit.Text)-2); bekomme ich zwar den letzten Zeilenumbruch weg, allerdings gehen mit dem neuen Zuweisen von RichEdit.Text sämtliche Formatierungen verloren, was ich wiederum nicht will.

Versuche es so:
ausblenden Delphi-Quelltext
1:
2:
3:
RichEdit.SelStart := RichEdit.GetTextLen - 2;
RichEdit.SelLength := 2;
RichEdit.SelText := '';
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 31.07.06 21:02 
Cool, danke Flocke, du bist klasse :flehan:
Inzwischen hatte ich so viele Möglichkeiten durch, weiß inzwischen glaub auch, warum das delete nich geht, aber die Sache mit dem SelText hab ich irgendwie übersehen. Bei diesem Thread hab ich so richtig den Eindruck, als sähe ich den Wald vor lauter Bäumen nicht :-S

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 31.07.06 22:26 
Hallo,
user profile iconalias5000 hat folgendes geschrieben:
...Ich habe ja WantReturns auf false. Das bedeutet, dass das RichEdit dann automatisch mit der Tastenkombination Strg+Enter eine Neue Zeile einfügt. In diesem Fall will ich diese Zeile da aber nicht mehr haben....

versuch mal das im OnKeyPress-Event:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
 if Key = #10 then
    Key := #0
    else
      if Key = #13 then
        RichEdit1.SelText := #13#10;
end;

Strg + C, Strg + V ... bleiben Dir erhalten,
aber frag nicht warum das so ist, ich weis es nicht :roll:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 31.07.06 22:30 
danke werd ich tun, wenn ich wieder dran abreite so spät abends lass ichs dann doch lieber mal, gibt einfach zu viele Bugs :wink:

_________________
Programmers never die, they just GOSUB without RETURN
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 31.07.06 22:38 
Hallo,

stimmt,ist spät, hab gerade festgestellt das mit Shift + Enter dann immer noch ein Zeilenumbruch erzeugt werden kann.
Wenn mich nicht alles täuscht ist es so richtig:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
 if Key = #10 then
    Key := #0
    else
      if (Key = #13) and (not HiWord(DWord(GetKeyState(VK_SHIFT))) <> 0) then
        RichEdit1.SelText := #13#10;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Mo 31.07.06 22:45 
Iss das dann net der Virtual Key-code für Strg? (--> VK_SHIFT bei dir) :wink:

_________________
Programmers never die, they just GOSUB without RETURN
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 01.08.06 12:41 
Hallo,

user profile iconLannes hat folgendes geschrieben:
...aber frag nicht warum das so ist, ich weis es nicht...
war einfach zu spät :wink:
ausblenden Delphi-Quelltext
1:
if Key = #10 then					
#10 (Hex 0A) wird durch die Tastenkombination Strg+Enter erzeugt.

user profile iconLannes hat folgendes geschrieben:
stimmt,ist spät, hab gerade festgestellt das mit Shift + Enter dann immer noch ein Zeilenumbruch erzeugt werden kann....
das mit dem Shift war Quatsch, der Umbruch wird durch Enter erzeugt, vergess das(und den letzten Code) mal :oops:

zu den Virtual Keycodes:
ausblenden Quelltext
1:
2:
3:
4:
Strg+Enter = #10 = Hex 0A = nicht definiert
Enter      = #13 = Hex 0D = VK_RETURN
Shift      = #16 = Hex 10 = VK_SHIFT
Strg       = #17 = Hex 11 = VK_CONTROL

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Di 01.08.06 16:14 
Vielen Dank, Lannes, diese Lösung ist ein bisschen sauberer, da die zusätzliche Zeile erst gar nicht erstellt wird :wink:

_________________
Programmers never die, they just GOSUB without RETURN