2017-10-17 3 views
0

Je dessine un pentagone en toile wpf qui fonctionne bien mais je ne sais vraiment pas comment dessiner un simple point/point dans ma toile. J'ai demandé google et je ne peux pas trouver le bon/une réponse simple.Comment dessiner un point simple dans un canevas wpf C# en utilisant les coordonnées x et y?

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    string x = xCoo.Text; 
    string y = yCoo.Text; 
    commandText = "Select f.p_ID, f.bezeichnung from figure05 f " + 
    "where SDO_CONTAINS(f.shape, " + 
    "SDO_GEOMETRY(2001, NULL, " + 
    "SDO_POINT_TYPE("+Convert.ToInt32(x)+", "+Convert.ToInt32(y)+", NULL), NULL, NULL" + 
    ")) = 'TRUE';"; 
    using (OleDbConnection conn = new OleDbConnection(cs)) 
    { 
     try 
     { 
      conn.Open(); 
      MessageBox.Show("Connection open!"); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
     cmd = new OleDbCommand(commandText, conn); 
     OleDbDataReader reader = cmd.ExecuteReader(); 
     if (reader.Read()) 
     { 
      MessageBox.Show("Point is in Pentagon"); 
      //Drawing point here 
     } 

    } 
} 

ma toile:

<Canvas Name="myCanvas" Background="LightBlue" HorizontalAlignment="Left" Height="301" Margin="10,10,0,0" VerticalAlignment="Top" Width="318"/> 

Merci pour tout type d'aide!

+0

Vous pouvez dessiner une ligne avec une longueur nulle, soit identique début et le point final, un StrokeThickness approprié et StrokeStartLineCap et StrokeEndLineCap définis sur Square ou Round. – Clemens

Répondre

-2

Vous pouvez simplement dessiner une ellipse comme ici a expliqué:

Jetez aussi un coup d'oeil à l'adresse suivante:

EDIT: Comme mentionné dans les commentaires ici un exemple comment dessiner un seul pixel sur un canevas avec un objet Ellipse à la position 50,50.

MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:WpfApp1" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 

     <Button Grid.Column="0" Grid.Row="0" Name="drawButton" Content="Draw!" Click="DrawButton_OnClick" /> 

     <Canvas Grid.Column="0" Grid.Row="1" Name="myCanvas" Background="LightBlue" /> 
    </Grid> 
</Window> 

MainWindow.xaml.cs

using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Media; 
using System.Windows.Shapes; 

namespace WpfApp1 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
     } 

     private void DrawButton_OnClick(object sender, RoutedEventArgs e) 
     { 
      var brush = new SolidColorBrush(Colors.Black); 

      var ellipse = new Ellipse 
      { 
       Stroke = brush, 
       Fill = brush, 
       StrokeThickness = 1, 
       Height = 1, 
       Width = 1, 
      }; 

      Canvas.SetLeft(ellipse, 50); 
      Canvas.SetTop(ellipse, 50); 

      myCanvas.Children.Add(ellipse); 
     } 
    } 
} 
+0

n'est pas là une manière plus simple de dessiner un point? Comme Point p = new Point (x, y) et l'ajouter à ma toile? Je ne trouve rien sur Internet. Ou dois-je dessiner une ellipse? –

+0

Eh bien, vous pouvez dessiner un seul pixel avec une ligne aussi. Voici un autre approcah: [WPF Canvas - Single Pixel Grid] (https://stackoverflow.com/questions/2916496/wpf-canvas-single-pixel-grid) – ChW