2015-08-14 13 views
5

में सदस्य का मूल वर्ग प्राप्त करें मेरे पास 3 सदस्यों के साथ एक कक्षा है, उनमें से केवल दो प्रासंगिक हैं; एक पॉलीगॉन और दूसरा निर्देशांक का एक int [] है। मैं उस बहुभुज के अनुरूप निर्देशांक से अवगत होना चाहता हूं लेकिन मैं वास्तव में यहां फंस गया हूं।MouseEvent

बहुभुज निर्देशांक से अवगत होने का मतलब है कि मेरा मतलब है कि बहुभुज निर्देशांक मैं उस बहुभुज के साथ कक्षा में संग्रहीत करता हूं और जिसका उपयोग मैं अपने अंक घोषित करने के लिए करता हूं।

निर्देशांक एक्स, वाई और जेड हैं और मैं उन्हें निम्न वर्ग में int [3] में संग्रहीत करता हूं। और मुझे क्या करना चाहते हैं उन घन निर्देशांक को पकड़ने के लिए सक्षम होने के लिए हर घटना शुरू हो रहा है .: है

public class Tile 
{ 
    public int[] coords; 
    public Polygon hex; 
    public List<object> content; 
} 

सूची भराव विधि:

 foreach (int[] i in ValidCoordinates) 
     { 
      int[] coords = i; 

      double apotema = Math.Sqrt(Math.Pow(20, 2) - Math.Pow(20/2, 2)); 

      double auxX = x + (coords[0] * (20 * 3/2)); 
      double auxY = y + (coords[0] * apotema + (coords[1] * apotema * 2)); 

      Polygon poly = Hex.HexagonalPolygon(20, auxX, auxY); 

      poly.Fill = Brushes.Blue; 

      Hexagon.Tile tile = new Hexagon.Casilla(); 

      tile.coords = coords; 
      tile.hex = poly; 

      ListTiles.Add(tile); 
     } 

और मैं सूची बहुभुज सदस्य दिखाने

: इस तरह टाइलें ...

foreach (Hexagon.Tile t in ListTiles) 
{ 
    PolyCanvas.Children.Add(t.hex); 
} 

और फिर एक MouseEvent साथ बहुभुज खोजने के लिए और बदलने के लिए यह गुण है की

private void PolyCanvas_MouseDown(object sender, MouseButtonEventArgs e) 
{ 
    if (e.OriginalSource is Polygon) 
    { 
     Polygon poly = e.OriginalSource as Polygon; 

     poly.Fill = Brushes.Red; 
    } 
} 

एक छोटा सा कोड अधिक ... XMAL:

<Grid Name="MainGrid"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="400"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Canvas Name="PolyCanvas" MouseDown="PolyCanvas_MouseDown" Height="700" Width="1200"> 
    </Canvas> 
    <TextBox Name="txt" Grid.Row="1"></TextBox> 
</Grid> 

मैं अच्छी तरह से एक जवाब के लिए खोज की है, लेकिन मैं पता कर रहा हूँ।

+0

प्रयास करें आप अगर माउस बहुभुज पर या अन्य पर दबाया जाँच करना चाहते हैं? –

+0

बहुभुज पर, जिसे मैंने दबाया था। – Commit

+0

क्या आपने 'प्रेषक 'से जानकारी प्राप्त करने का प्रयास किया है? –

उत्तर

1

इस

foreach (int[] i in ValidCoordinates) 
{ 
    int[] coords = i; 

    double apotema = Math.Sqrt(Math.Pow(20, 2) - Math.Pow(20/2, 2)); 

    double auxX = x + (coords[0] * (20 * 3/2)); 
    double auxY = y + (coords[0] * apotema + (coords[1] * apotema * 2)); 

    Polygon poly = Hex.HexagonalPolygon(20, auxX, auxY); 

    poly.Fill = Brushes.Blue; 

    Hexagon.Tile tile = new Hexagon.Casilla(); 

    tile.coords = coords; 
    tile.hex = poly; 
    ListTiles.Add(tile); 
} 
... 
//put values into tile and then set as tag 
PolyCanvas.Tag = tile; 
... 
private void PolyCanvas_MouseDown(object sender, MouseButtonEventArgs e) 
{  
    var canvas = sender as System.Windows.Controls.Canvas; 
    if (canvas.Name == "PolyCanvas") 
    { 
      if(canvas.Tag != null) 
      var tiles = (Tile)canvas.Tag; 
    } 
} 
+0

मुझे लगता है कि आप मुझे याद कर सकते हैं। मैं पहले से ही कैनवास के संबंध में बहुभुज के समन्वयक एक्स, वाई बता सकता हूं। मैं जिन निर्देशांकों की बात कर रहा था वे क्लास टाइल्स में हैं, जो क्यूब निर्देशांक (x, y, z) हैं और पॉइंट निर्देशांक के साथ कुछ लेना देना नहीं है। अस्पष्ट होने के लिए खेद है, इसे स्पष्ट करने के लिए अब प्रश्न को संपादित करने के लिए जाएं। और वैसे भी आपकी मदद के लिए धन्यवाद। – Commit

+0

अब आप क्या चाहते हैं? –

+0

मैंने सवाल को सही किया, उम्मीद है कि अब यह कम भ्रमित है। – Commit

संबंधित मुद्दे