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

Windows Presentation Foundation Discussion :

Arcs dans wpf


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Inscrit en
    Mai 2009
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Mai 2009
    Messages : 1
    Par défaut Arcs dans wpf
    Bonsoir a tous

    j'aimerai savoir comment pouvoir dessiner un arcs entre deux points de manière dynamique,j'ai trouver comment le faire avec xml mais j'aimerai pouvoir le créer d'une manière dynamique pour pouvoir changer quelque coordonnées.

    merci d'avance

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour snake91
    c'est l'enfer de la bataille de Guadalcanal si tu connais le film.....

    voici le 1er Winform qui cree un ArcSegment dans "la galerie des classes hierachique xaml" qu'il faudra helas parcourir dans le code que tu devra ecrira - cela va sans dire-:

    Code xaml : 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
     
    <Window x:Class="WpfDrawArc.WinArcXaml"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Canvas>
     
            <!-- Cree un arc  -->
            <!--pour creer un arc il faut traverser la hierachie en sens inverse 
            en partant de l'interieur:
            *1-ArcSegment
            *2-PathSegmentCollection
            *3-PathFigure avec point de depart
            *4-PathFigureCollection qui va contenir le  PathFigure
            *5-PathGeometry qui va contenir la collection de figures
            *6-Path qui va contenir le tout-->
     
            <Path Stroke="Black" StrokeThickness="2" >
                <Path.Data>
                    <PathGeometry>
                        <PathGeometry.Figures>
                            <PathFigureCollection>
                                <PathFigure StartPoint="50,50">
                                    <PathFigure.Segments>
                                        <PathSegmentCollection>
                                            <ArcSegment 
                                                x:Name="myArcSegment" 
                                                Size="90,90" 
                                                IsStroked="True" 
                                                IsLargeArc="False"
                                                IsSmoothJoin="True" 
                                                SweepDirection="Clockwise"  
                                                Point="150,150" />
                                        </PathSegmentCollection>
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathFigureCollection>
                        </PathGeometry.Figures>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </Canvas>
     
    </Window>
    voici maintenant le 2eme Winform qui cree le meme ArcSegment en code-behind avec un bouton addArc:
    code xaml:
    Code xaml : 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
     
    <Window x:Class="WpfDrawArc.WinArcCode"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WinArcCode" Height="300" Width="300">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
     
            <Canvas 
                x:Name="myCanvas"> 
            </Canvas>
            <Button
                Grid.Row="1"
                x:Name="myButton" 
                Content="addAtc"
                Click="myButton_Click" 
                Width="100"
                Height="30" 
                VerticalAlignment="Bottom">
     
            </Button>
        </Grid>
    </Window>
    code-behind du 2eme Winform:
    Code c# : 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
    66
    67
    68
    69
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
     
    namespace WpfDrawArc
    {
        /// <summary>
        /// Logique d'interaction pour WinArcCode.xaml
        /// </summary>
        public partial class WinArcCode : Window
        {
            public WinArcCode()
            {
                InitializeComponent();
            }
     
            private void myButton_Click(object sender, RoutedEventArgs e)
            {
                //-1  ArcSegment to define the geometry of the path.
                ArcSegment myArcSegment = new ArcSegment();
                myArcSegment.Size = new Size(90, 90);
                myArcSegment.SweepDirection = SweepDirection.Clockwise;
                myArcSegment.IsStroked = true; 
                myArcSegment.IsLargeArc = false;
                myArcSegment.IsSmoothJoin = true;
                myArcSegment.Point = new Point(150, 150);
     
                // 2- PathSegmentCollection.
                 PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myArcSegment);
     
                // 3- PathFigure to be used for the PathGeometry of myPath.
                PathFigure myPathFigure = new PathFigure();
     
                // starting point for the PathFigure 
                myPathFigure.StartPoint = new Point(50, 50);
                myPathFigure.Segments = myPathSegmentCollection;
     
                // 4- PathFigureCollection myPathFigureCollection = new PathFigureCollection();
                PathFigureCollection myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);
     
                // 5- PathGeometry
                PathGeometry myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;
     
                // 6- Path to draw a geometry with.
                Path myPath = new Path();
                myPath.Stroke = Brushes.Black;
                myPath.StrokeThickness = 1;
     
                // 7- specify the shape of the path 
                myPath.Data = myPathGeometry;
     
                // 8- ajout au canvas
                this.myCanvas.Children.Add(myPath); 
            }
        }
    }

    bon code..........

Discussions similaires

  1. [ESP] Comment procéder pour ouvrir une application ESP dans WPF ?
    Par fafarun dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 18/09/2008, 17h22
  2. 3D dans wpf RE
    Par HighTouch dans le forum Windows Presentation Foundation
    Réponses: 5
    Dernier message: 01/08/2008, 15h50
  3. Accélerer le chargement d'images dans WPF
    Par jnussas dans le forum Windows Presentation Foundation
    Réponses: 9
    Dernier message: 13/07/2008, 16h31
  4. Encore un bug dans WPF ? :aie:
    Par smyley dans le forum Windows Presentation Foundation
    Réponses: 8
    Dernier message: 10/07/2008, 11h41
  5. chemin, arc dans un graphe
    Par semaj_james dans le forum Algorithmes et structures de données
    Réponses: 2
    Dernier message: 29/11/2005, 16h45

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