IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Déplacer un node et ajouter un lien hypertexte


Sujet :

C#

  1. #1
    Membre habitué Avatar de Simicro
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Mai 2012
    Messages : 136
    Points : 196
    Points
    196
    Par défaut Déplacer un node et ajouter un lien hypertexte
    Bonjour,

    Dans une TreeView, j'ai essayé de déplacer un node : j'arrive bien à le déplacer dans un autre node (par glisser-déposer) mais pas à le déplacer pour changer l'ordre sans changer de niveau.

    Exemple : déplacer "Bush Flight Simulator" pour le positionner entre "Aerofly FS" et "FlightGear"

    Nom : RZRv7.png
Affichages : 252
Taille : 33,0 Ko

    J'aurais aussi aimé savoir si on peut mettre un lien hypertexte dans un node pour que en cas de clic le navigateur par défaut se lance.

    Nom : vaYQg.png
Affichages : 232
Taille : 156,1 Ko

    J'ai trouvé un composant qui le fait mais pour... $99 (avec d'autres fonctionnalités bien sûr).

    https://www.lidorsystems.com/support...hyperlink.aspx
    Tony
    Hobbyiste débutant Delphi 7

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour
    Pour ajouter un lien hypertexte il faut :
    1/ se munir d'un TreeNode "perso" hérité (voir ci-après le Class NodeLink)de qui héberge un LabelLink
    2/ se munir d'un TreeView "perso" hérité également(voir ci-après le Class TreeViewLink) qui "accepte" un TreeNode normal mais aussi ton TreeNode "perso"
    aka NodeLink.
    Voici le code qui t'épargnera peut être 99 $

    code behind.cs du class NodeLink:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    namespace LibLinkNode
    {
        public class NodeLink:TreeNode
        {
     
            private string _url = string.Empty;
            public string Url
            {
                get { return _url; }
                set { _url = value; }
            }
            private LinkLabel _linkLabel = null;
            public LinkLabel LinkLabel
            {
                get { return _linkLabel; }
                set { _linkLabel= value; }
            }
            public NodeLink()
            {
                this._linkLabel = new LinkLabel();
                this._linkLabel.AutoSize = true;
                this._linkLabel.DisabledLinkColor = System.Drawing.Color.Red;
                this._linkLabel.VisitedLinkColor = System.Drawing.Color.Blue;
                this._linkLabel.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
                this._linkLabel.LinkColor = System.Drawing.Color.Navy;
     
                this._linkLabel.TabIndex = 0;
                this._linkLabel.TabStop = true;
     
     
            }
            public NodeLink(string description, string url):this()
            {
                this._url = url;
     
                //add white spaces
                description=description.PadRight(url.Length, ' ');
                this._linkLabel.Text = description;
                this._linkLabel.Links[0].LinkData = this._url ;
     
            }
     
     
        }
    }
    code behind.cs du class TreeViewLink:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
     
    namespace LibLinkNode
    {
        public partial class TreeViewLink : TreeView
        {
            private NodeLink m_CurrentNode = null;
     
            public TreeViewLink()
            {
                InitializeComponent();
     
            }
     
            protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
            {// Are we dealing with a dropdown node?
                if (e.Node is NodeLink)
                {
                    this.m_CurrentNode = (NodeLink)e.Node;
     
                    // Need to add the node's ComboBox to the
                    // TreeView's list of controls for it to work
                    this.Controls.Add(this.m_CurrentNode.LinkLabel);
                    // Now show the ComboBox
                    this.m_CurrentNode.LinkLabel.Show();
                    // Set the bounds of the ComboBox, with
                    // a little adjustment to make it look right
                    this.m_CurrentNode.LinkLabel.SetBounds(
                        this.m_CurrentNode.Bounds.X - 1,
                        this.m_CurrentNode.Bounds.Y - 2,
                        this.m_CurrentNode.Bounds.Width + 25,
                        this.m_CurrentNode.Bounds.Height);
     
                    // Listen to the SelectedValueChanged
                    // event of the node's ComboBox
                    this.m_CurrentNode.LinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkLabel_LinkClicked);
     
     
                }
                base.OnNodeMouseClick(e);
            }
     
            void LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                LinkLabel lnk = sender as LinkLabel;
     
                lnk.Links[lnk.Links.IndexOf(e.Link)].Visited = true;
     
                string target = e.Link.LinkData as string;
     
                // If the value looks like a URL, navigate to it.
                // Otherwise, display it in a message box.
                if (null != target && target.StartsWith("www"))
                {
                    System.Diagnostics.Process.Start(target);
                }
                else
                {
                    MessageBox.Show("Item clicked: " + target);
                }
     
            }
     
     
        }
    }
    code behind.cs du form user:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
     
     public partial class Test : Form
        {
            private ArrayList custArray = new ArrayList();
            public Test()
            {
                InitializeComponent();
            }
     
            private void Test_Load(object sender, EventArgs e)
            {
                FillMyTreeView();
     
     
     
            }
            private void FillMyTreeView()
            {
                // Add customers to the ArrayList of Customer objects.
                for (int i = 0; i < 5; i++)
                {
                    custArray.Add(new Customer("Customer" + i.ToString()));
                }
     
                // Add suppliers to each Customer object in the ArrayList.
                Supplier supplier = null;
                foreach (Customer cust in custArray)
                {
                    supplier = new Supplier("Visit Microsoft", "www.microsoft.com");
                    cust.CustomerSuppliers.Add(supplier);
                    supplier = new Supplier("Visit Google", "www.google.fr");
                    cust.CustomerSuppliers.Add(supplier);
                    supplier = new Supplier("Visit Developpez.Net Forums" , "www.Developpez.Net");
                    cust.CustomerSuppliers.Add(supplier);
                }
     
     
                treeViewLink1.BeginUpdate();
     
               treeViewLink1.Nodes.Clear();
     
                // Add a root TreeNode for each Customer object in the ArrayList.
                foreach (Customer cust in custArray)
                {
                   treeViewLink1.Nodes.Add(new TreeNode(cust.CustomerName));
     
                    // Add a child treenode for each Supplier object in the current Customer object.
                    foreach (Supplier supplierItem in cust.CustomerSuppliers)
                    {
                        NodeLink suppNode = new NodeLink(cust.CustomerName + "." + supplierItem.SupplierDesc,supplierItem.SupplierUrl);
                       treeViewLink1.Nodes[custArray.IndexOf(cust)].Nodes.Add(suppNode);
     
                    }
                }
     
                // Reset the cursor to the default for all controls.
                Cursor.Current = Cursors.Default;
     
                // Begin repainting the TreeView.
               treeViewLink1.EndUpdate();
            }
        }
    N.B: il cliquer sur le "node child" représentant le lien (tirets) pour faire apparaître le lien.

    Pour le déplacement il faut probablement un insertion & une suppression.
    bon code.

  3. #3
    Membre habitué Avatar de Simicro
    Homme Profil pro
    Inscrit en
    Mai 2012
    Messages
    136
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Mai 2012
    Messages : 136
    Points : 196
    Points
    196
    Par défaut
    Bonjour MABROUKI,

    Je te remercie bien pour ton temps et le code.
    Tony
    Hobbyiste débutant Delphi 7

Discussions similaires

  1. [AC-2003] ajouter un lien hypertexte dans mon email
    Par Bmichel59 dans le forum VBA Access
    Réponses: 7
    Dernier message: 08/06/2011, 16h22
  2. Copier/Coller une cellule en y ajoutant un lien hypertexte
    Par Benjycool dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 14/01/2009, 15h01
  3. [XML] comment ajouter un lien hypertexte
    Par yakaoser dans le forum XML/XSL et SOAP
    Réponses: 7
    Dernier message: 16/05/2008, 16h57
  4. Bouton pour ajouter un lien hypertexte dans un champ
    Par Fredo67 dans le forum VBA Access
    Réponses: 2
    Dernier message: 22/01/2008, 11h43
  5. lister des fichier et ajouter un lien hypertexte
    Par Citrouilli dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 24/05/2007, 09h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo