Meinews.de  


Zurück   Meinews.de > Forum > Newsgroups microsoft.public.de.* 1 Forum > Newsgroup microsoft.public.de.german.entwickler.dotnet.csharp
Registrieren FAQ Benutzerliste Kalender Suchen Heutige Beiträge Alle Foren als gelesen markieren

Newsgroup microsoft.public.de.german.entwickler.dotnet.csharp Forum microsoft.public.de.german.entwickler.dotnet.csharp

Antwort
 
Themen-Optionen Ansicht
  #1  
Alt 11-05-2009, 10:52 AM
Werner Perplies
 
Beiträge: n/a
Standard Caretposition während DragAndDrop

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
Mit Zitat antworten
Alt Today
Advertising
Google Adsense
 
This advertising will not be shown
in this way to registered members.
Register your free account today
and become a member on
Meinews.de
Standard Sponsored Links

  #2  
Alt 11-05-2009, 02:26 PM
Werner Perplies
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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
Mit Zitat antworten
  #3  
Alt 11-05-2009, 06:40 PM
Immo Landwerth
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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
Mit Zitat antworten
  #4  
Alt 11-05-2009, 06:50 PM
Werner Perplies
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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
Mit Zitat antworten
  #5  
Alt 11-05-2009, 07:28 PM
Frank Dzaebel
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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

Mit Zitat antworten
  #6  
Alt 11-05-2009, 07:38 PM
Frank Dzaebel
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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

Mit Zitat antworten
  #7  
Alt 11-05-2009, 09:47 PM
Immo Landwerth
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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
Mit Zitat antworten
  #8  
Alt 11-06-2009, 07:04 AM
Frank Dzaebel
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

> // 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

Mit Zitat antworten
  #9  
Alt 11-06-2009, 09:05 AM
Werner Perplies
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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
Mit Zitat antworten
  #10  
Alt 11-06-2009, 09:07 AM
Werner Perplies
 
Beiträge: n/a
Standard Re: Caretposition während DragAndDrop

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
Mit Zitat antworten
 
Antwort


Themen-Optionen
Ansicht

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen
Es ist dir nicht erlaubt, auf Beiträge zu antworten
Es ist dir nicht erlaubt, Anhänge anzufügen
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten

vB Code ist An
Smileys sind An
[IMG] Code ist An
HTML-Code ist Aus

Ä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


Alle Zeitangaben in WEZ. Es ist jetzt 09:04 AM Uhr.





Powered by: vBulletin Version 3.6.7 (Deutsch)
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Forum SEO by Zoints