Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to select text in a Node? (Read 227 times)
GrandSon
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Nov 26th, 2023
How to select text in a Node?
Mar 29th, 2024 at 6:36am
Print Post  
Nodes(e.g. ShapeNode) are moved  when user try drag text to select.

I want to allow my user to select text on the node by drag mouse, and copy(Ctrl+C).

I tyied use EditComponent bellow:
Code (C++)
Select All
var node = new CompositeNode { Bounds = new RectangleF(15, 35, 50, 7) };
var e = new EditComponent { Text = "editcomponent" };
e.TextChanging += (s, e) => e.Cancel = true;
node.Components.Add(e);
_diagram.Nodes.Add(node);
 



This is worked I want(Select by mouse, Disallow editing, Can copy text) except Caret is shown.
Can I hide Caret?
Or are there other solutions?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3159
Joined: Oct 19th, 2005
Re: How to select text in a Node?
Reply #1 - Mar 29th, 2024 at 11:54am
Print Post  
Caret is shown when the EditComponent has focus. If you don't need users to enter text but only select, you could set e.Focusable = false; then caret will be hidden, selection will still work, but Ctrl+C won't be handled by the component (not having the keyboard focus to detect shortcut). You could handle it from DiagramView.KeyDown handler instead, by finding the SelectionStart -> SelectionLength substring of last clicked component and sending that to clipboard. Otherwise we could add some property to only hide the caret for next release.

For ShapeNodes, you might call BeginEdit from NodePointed event handler to make text immediately selectable. If you handle DiagramView.EnterInplaceEditMode event, you could customize TextBox colors to match the node's background, making the editor less obtrusive.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
GrandSon
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Nov 26th, 2023
Re: How to select text in a Node?
Reply #2 - Apr 2nd, 2024 at 1:40am
Print Post  
Thank you, I resolved.

Code (C++)
Select All
var node = new CompositeNode { Bounds = new RectangleF(15, 35, 50, 7) };
var e = new EditComponent { Text = "editcomponent" };
e.TextChanging += (s, e) => e.Cancel = true;
e.Focusable = false;

node.Components.Add(e);
_diagram.Nodes.Add(node);
_view.KeyDown += (o, ev) =>
{
    if(ev.Modifiers == Keys.Control && ev.KeyCode == Keys.C)
    {
        var s = e.SelectionStart;
        var l = e.SelectionLength;
        if(l < 0) // Adjustment when selecting from behind
        {
            (s, l) = (s + l, Math.Abs(l));
        }
        Clipboard.SetText(e.Text.Substring(s, l));
    }
};
 



Quote:
For ShapeNodes, you might call BeginEdit from NodePointed event handler to make text immediately selectable.

I'll try this too later.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint