![]() |
|
|||||||
| Newsgroup microsoft.public.de.german.entwickler.dotnet.csharp Forum microsoft.public.de.german.entwickler.dotnet.csharp |
![]() |
|
|
Themen-Optionen | Ansicht |
|
#1
|
|||
|
|||
|
Hi,
irgendwo stehe ich mal wieder auf dem Schlauch: Wie aktualisiere ich während eine DragAndDrop-Vorganges die Schreibmarke. Bisher ist es mir nur gelungen, den Text an Mausposition einzufügen, aber ohne Caretposition wäre das ein Blindflug für den Anwender. Schon mal danke für Tipps. Gruß Werner -- Reguläre Ausdrücke testen? http://www.weepee.de/de/wps_regex/wps_regex.html www.weepee.eu |
|
|
||||
|
||||
|
|
|
#2
|
|||
|
|||
|
Hi,
Zu leicht, oder zu schwierig? Hat niemand einen heißen Tipp? Gruß Werner -- Reguläre Ausdrücke testen? http://www.weepee.de/de/wps_regex/wps_regex.html www.weepee.eu |
|
#3
|
|||
|
|||
|
Werner Perplies wrote:
> Zu leicht, oder zu schwierig? Keine Ahnung, ich für meinen Teil habe es halt noch nicht ausprobiert :-) > Hat niemand einen heißen Tipp? Ich nehme an, Du verwendest eine Standard Win Form TextBox? - Wenn Du an der Mausposition einfügen kannst, lässt das den Schluss zu, dass Du bereits eine Umrechnung von X,Y -> String Index hast. - Du solltest mit den Eigenschaften SelectionStart/SelectionLength das Caret setzen können -- wenn ich mich recht entsinne, muss SelectionLength dabei auf 0 oder 1 gesetzt werden. Hilft Dir das weiter? -- Immo Landwerth |
|
#4
|
|||
|
|||
|
Hallo Immo,
Am Thu, 05 Nov 2009 10:40:24 -0800 schrieb Immo Landwerth: > Werner Perplies wrote: > >> Zu leicht, oder zu schwierig? > > Keine Ahnung, ich für meinen Teil habe es halt noch nicht ausprobiert > :-) > >> Hat niemand einen heißen Tipp? > > Ich nehme an, Du verwendest eine Standard Win Form TextBox? > > - Wenn Du an der Mausposition einfügen kannst, lässt das den Schluss > zu, > dass Du bereits eine Umrechnung von X,Y -> String Index hast. > > - Du solltest mit den Eigenschaften SelectionStart/SelectionLength das > Caret setzen können -- wenn ich mich recht entsinne, muss > SelectionLength dabei auf 0 oder 1 gesetzt werden. > > Hilft Dir das weiter? Danke. In die Richtung habe ich auch schon gedacht, aber an welcher Stelle mache ich das? Die Schreibmarke muss ja mit dem Mauszeiger "mitlaufen". Gruß Werner -- Reguläre Ausdrücke testen? http://www.weepee.de/de/wps_regex/wps_regex.html www.weepee.eu |
|
#5
|
|||
|
|||
|
Hallo Werner,
> Wie aktualisiere ich während eine DragAndDrop-Vorganges die Schreibmarke. Essentiell benutzt man oft: [TextBoxBase.GetPositionFromCharIndex-Methode (System.Windows.Forms)] http://msdn.microsoft.com/de-de/libr... arindex.aspx Hier ein Beispiel als grober Ansatz: TreeView tv = new TreeView(); TextBox tb = new TextBox(); private void Form1_Load(object sender, EventArgs e) { tb.DragEnter += new DragEventHandler(tb_DragEnter); tb.DragDrop += new DragEventHandler(tb_DragDrop); tv.ItemDrag += new ItemDragEventHandler(tv_ItemDrag); Controls.Add(tb); tb.Text = "abcdefghijk"; tb.AllowDrop = true; FülleTreeView(tv, "Eins", "Zwei", "Drei", "Vier"); Controls.Add(tv); tb.Top = tv.Height + 10; } private void FülleTreeView(TreeView tv, params string[] namen) { foreach (string name in namen) tv.Nodes.Add(name); } private int TextBoxCaretIndexFromPoint(TextBox tb, int x, int y) { Point p = tb.PointToClient(new Point(x, y)); int i = tb.GetCharIndexFromPosition(p); if (i == tb.Text.Length - 1) { Point c = tb.GetPositionFromCharIndex(i); if (p.X > c.X) i++; } return i; } private void tv_ItemDrag(object sender, ItemDragEventArgs e) { if (e.Button != MouseButtons.Left) return; object item = e.Item; tv.DoDragDrop(((TreeNode)item).Text, DragDropEffects.Copy | DragDropEffects.Scroll); } private void tb_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) e.Effect = DragDropEffects.Copy | DragDropEffects.Scroll; else e.Effect = DragDropEffects.None; Console.WriteLine(e.ToString()); } private void tb_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) { int charIndex = TextBoxCaretIndexFromPoint(tb, e.X, e.Y); tb.SelectionLength = 0; tb.SelectionStart = charIndex; tb.SelectedText = (string)e.Data.GetData(DataFormats.StringFormat); } } // später ggf. noch (u.a.) : [DllImport("user32.dll")] public extern static int ShowCaret(IntPtr hwnd); [DllImport("user32.dll")] public extern static int HideCaret(IntPtr hwnd); ciao Frank -- Dipl.Inf. Frank Dzaebel [MCP/MVP C#] http://Dzaebel.NET |
|
#6
|
|||
|
|||
|
Nachtrag, ich schrieb:
> [TextBoxBase.GetPositionFromCharIndex-Methode ... gemeint ist, wie in meinem Sample-Code: [TextBoxBase.GetCharIndexFromPosition-Methode (System.Windows.Forms)] http://msdn.microsoft.com/de-de/libr... osition.aspx ciao Frank -- Dipl.Inf. Frank Dzaebel [MCP/MVP C#] http://Dzaebel.NET |
|
#7
|
|||
|
|||
|
Werner Perplies wrote:
> Danke. Bitte. > In die Richtung habe ich auch schon gedacht, aber an welcher Stelle > mache ich das? > > Die Schreibmarke muss ja mit dem Mauszeiger "mitlaufen". Gute Frage; mal mit den Drag Over (ö.Ä, wie z.B. MouseMove) probiert? Ich habe keine Ahnung, ob die sauber während Drag & Drop Operationen funktionieren, sehe aber auch keinen Grund warum nicht? -- Immo Landwerth |
|
#8
|
|||
|
|||
|
> // später ggf. noch (u.a.) :
> [DllImport("user32.dll")] > public extern static int ShowCaret(IntPtr hwnd); > [DllImport("user32.dll")] > public extern static int HideCaret(IntPtr hwnd); Zum einen ein grober Ansatz, wie soetwas benutzt werden "kann": // Der Code ist hier noch nicht optimal! using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace DragDropCaret { public partial class Form1 : Form { public Form1() { InitializeComponent(); } TreeView tv = new TreeView(); CaretTextBox tb = new CaretTextBox(); class TextBoxUtil { public static int TextBoxCaretIndexFromPoint(TextBox tb, int x, int y) { Point p = tb.PointToClient(new Point(x, y)); int i = tb.GetCharIndexFromPosition(p); if (i == tb.Text.Length - 1) { Point c = tb.GetPositionFromCharIndex(i); if (p.X > c.X) i++; } return i; } } class CaretTextBox : TextBox { bool isCaretShown = false; const int WM_NCHITEST = 0x84; const int zweiByte = 0x10; const int maskLetztenBeidenBytes = 0x00FF; const int caretBreite = 2; protected override void WndProc(ref Message m) { if (m.Msg == WM_NCHITEST) { int lp = m.LParam.ToInt32(); Point point = new Point(lp & maskLetztenBeidenBytes, lp >> zweiByte); Point p = PointToClient(point); if ((Control.MouseButtons & MouseButtons.Left) != 0) { CreateCaret(Handle, IntPtr.Zero, caretBreite, Font.Height); ShowCaret(Handle); SetCaretPos(p.X, p.Y - Font.Height); isCaretShown = true; } else if (isCaretShown) { HideCaret(Handle); isCaretShown = false; } } base.WndProc(ref m); } } private void Form1_Load(object sender, EventArgs e) { tb.DragEnter += new DragEventHandler(tb_DragEnter); tb.DragDrop += new DragEventHandler(tb_DragDrop); tv.ItemDrag += new ItemDragEventHandler(tv_ItemDrag); Controls.Add(tb); tb.Text = "abcdefghijk\r\nlmnopqrst"; tb.AllowDrop = true; tv.Height = 70; tb.Multiline = true; tb.Height = 40; FülleTreeView(tv, "Eins", "Zwei", "Drei", "Vier"); Controls.Add(tv); tb.Top = tv.Height + 10; } private void FülleTreeView(TreeView tv, params string[] namen) { foreach (string name in namen) tv.Nodes.Add(name); } private void tv_ItemDrag(object sender, ItemDragEventArgs e) { if (e.Button != MouseButtons.Left) return; object item = e.Item; tv.DoDragDrop(((TreeNode)item).Text, DragDropEffects.Copy | DragDropEffects.Scroll); } private void tb_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) e.Effect = DragDropEffects.Copy | DragDropEffects.Scroll; else e.Effect = DragDropEffects.None; } private void tb_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.StringFormat)) { int charIndex = TextBoxUtil. TextBoxCaretIndexFromPoint(tb, e.X, e.Y); tb.SelectionLength = 0; tb.SelectionStart = charIndex; tb.SelectedText = (string)e.Data.GetData(DataFormats.StringFormat); tb.Focus(); } } [DllImport("user32.dll")] public extern static int CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight); [DllImport("user32.dll")] public extern static int SetCaretPos(int x, int y); [DllImport("user32.dll")] public extern static int ShowCaret(IntPtr hwnd); [DllImport("user32.dll")] public extern static int HideCaret(IntPtr hwnd); } } __________ Zum anderen hier ein Link, der zwar nicht Dein Problem der Einfügemarke behandelt, aber vielleicht als Hintergrund ganz nett ist: [vbAccelerator - Contents of code file: DragDropTextBox.cs] http://www.vbaccelerator.com/home/ne...TextBox_cs.asp ciao Frank -- Dipl.Inf. Frank Dzaebel [MCP/MVP C#] http://Dzaebel.NET |
|
#9
|
|||
|
|||
|
Hallo Immo,
Danke. Am Thu, 05 Nov 2009 13:47:35 -0800 schrieb Immo Landwerth: > Werner Perplies wrote: > >> Danke. > > Bitte. > >> In die Richtung habe ich auch schon gedacht, aber an welcher Stelle >> mache ich das? >> >> Die Schreibmarke muss ja mit dem Mauszeiger "mitlaufen". > > Gute Frage; mal mit den Drag Over (ö.Ä, wie z.B. MouseMove) probiert? > Ich habe keine Ahnung, ob die sauber während Drag & Drop Operationen > funktionieren, sehe aber auch keinen Grund warum nicht? Ja, das probiere ich mal aus. Werner -- Reguläre Ausdrücke testen? http://www.weepee.de/de/wps_regex/wps_regex.html www.weepee.eu |
|
#10
|
|||
|
|||
|
Hallo Frank,
Danke. Am Fri, 6 Nov 2009 08:04:49 +0100 schrieb Frank Dzaebel: >> // später ggf. noch (u.a.) : >> [DllImport("user32.dll")] >> public extern static int ShowCaret(IntPtr hwnd); >> [DllImport("user32.dll")] >> public extern static int HideCaret(IntPtr hwnd); > > Zum einen ein grober Ansatz, wie soetwas benutzt werden "kann": > > // Der Code ist hier noch nicht optimal! > using System; > using System.Drawing; > using System.Windows.Forms; > using System.Runtime.InteropServices; > > namespace DragDropCaret > { > public partial class Form1 : Form > { > public Form1() > { > InitializeComponent(); > } > > TreeView tv = new TreeView(); > CaretTextBox tb = new CaretTextBox(); > > class TextBoxUtil > { > public static int TextBoxCaretIndexFromPoint(TextBox tb, int x, int y) > { > Point p = tb.PointToClient(new Point(x, y)); > int i = tb.GetCharIndexFromPosition(p); > if (i == tb.Text.Length - 1) > { > Point c = tb.GetPositionFromCharIndex(i); > if (p.X > c.X) i++; > } > return i; > } > } > > class CaretTextBox : TextBox > { > bool isCaretShown = false; > const int WM_NCHITEST = 0x84; > const int zweiByte = 0x10; > const int maskLetztenBeidenBytes = 0x00FF; > const int caretBreite = 2; > > protected override void WndProc(ref Message m) > { > if (m.Msg == WM_NCHITEST) > { > int lp = m.LParam.ToInt32(); > Point point = new Point(lp & maskLetztenBeidenBytes, lp >> > zweiByte); > Point p = PointToClient(point); > if ((Control.MouseButtons & MouseButtons.Left) != 0) > { > CreateCaret(Handle, IntPtr.Zero, caretBreite, Font.Height); > ShowCaret(Handle); SetCaretPos(p.X, p.Y - Font.Height); > isCaretShown = true; > } > else > if (isCaretShown) > { > HideCaret(Handle); > isCaretShown = false; > } > } > base.WndProc(ref m); > } > } > > private void Form1_Load(object sender, EventArgs e) > { > tb.DragEnter += new DragEventHandler(tb_DragEnter); > tb.DragDrop += new DragEventHandler(tb_DragDrop); > tv.ItemDrag += new ItemDragEventHandler(tv_ItemDrag); > Controls.Add(tb); tb.Text = "abcdefghijk\r\nlmnopqrst"; > tb.AllowDrop = true; tv.Height = 70; > tb.Multiline = true; tb.Height = 40; > FülleTreeView(tv, "Eins", "Zwei", "Drei", "Vier"); > Controls.Add(tv); tb.Top = tv.Height + 10; > } > > private void FülleTreeView(TreeView tv, params string[] namen) > { > foreach (string name in namen) > tv.Nodes.Add(name); > } > > private void tv_ItemDrag(object sender, ItemDragEventArgs e) > { > if (e.Button != MouseButtons.Left) return; > object item = e.Item; > tv.DoDragDrop(((TreeNode)item).Text, > DragDropEffects.Copy | DragDropEffects.Scroll); > } > > private void tb_DragEnter(object sender, DragEventArgs e) > { > if (e.Data.GetDataPresent(DataFormats.StringFormat)) > e.Effect = DragDropEffects.Copy | DragDropEffects.Scroll; > else > e.Effect = DragDropEffects.None; > } > > private void tb_DragDrop(object sender, DragEventArgs e) > { > if (e.Data.GetDataPresent(DataFormats.StringFormat)) > { > int charIndex = TextBoxUtil. > TextBoxCaretIndexFromPoint(tb, e.X, e.Y); > tb.SelectionLength = 0; > tb.SelectionStart = charIndex; > tb.SelectedText = (string)e.Data.GetData(DataFormats.StringFormat); > tb.Focus(); > } > } > > [DllImport("user32.dll")] > public extern static int CreateCaret(IntPtr hwnd, > IntPtr hBitmap, int nWidth, int nHeight); > > [DllImport("user32.dll")] > public extern static int SetCaretPos(int x, int y); > > [DllImport("user32.dll")] > public extern static int ShowCaret(IntPtr hwnd); > > [DllImport("user32.dll")] > public extern static int HideCaret(IntPtr hwnd); > } > } Ich schaue mir das an, bisher konnte ich aber Dein Beispiel noch nicht zum Laufen bekommen. Ich übersehe da wohl irgendetwas. > __________ > > Zum anderen hier ein Link, der zwar nicht Dein Problem der Einfügemarke > behandelt, aber vielleicht als Hintergrund ganz nett ist: > > [vbAccelerator - Contents of code file: DragDropTextBox.cs] > http://www.vbaccelerator.com/home/ne...TextBox_cs.asp > > > ciao Frank Gruß Werner -- Reguläre Ausdrücke testen? http://www.weepee.de/de/wps_regex/wps_regex.html www.weepee.eu |
|
|
|
|
![]() |
| Themen-Optionen | |
| Ansicht | |
|
|
Ähnliche Themen
|
||||
| Thema | Erstellt von | Forum | Antworten | Letzter Beitrag |
| Treeview DragAndDrop | Werner Perplies | Newsgroup microsoft.public.de.german.entwickler.dotnet.csharp | 5 | 05-02-2009 05:30 AM |
| Tot während der Datensicherung | Dieter A Franken | Newsgroup de.comp.hardware.laufwerke.festplatten | 29 | 03-18-2009 08:01 AM |
| Tot während der Datensicherung | Dieter A Franken | Newsgroup de.comp.hardware.kuehlung+laermdaemmung | 3 | 03-14-2009 03:56 PM |
| [TR] [AQ] Leseecke während Augenblicke X | Luigi Rotta | Newsgroup de.rec.fotografie | 0 | 08-15-2008 09:38 PM |
| Tod während Spiel | Helmut Weber | Newsgroup de.alt.games.schach | 3 | 11-13-2007 09:25 AM |