コード例 #1
0
        private void Customize_Shape_Load(object sender, EventArgs e)
        {
            Type type       = s.GetType();
            var  properties = type.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly);

            try
            {
                labelInfoShape.Text         = $"{type.Name}:\n{properties[0].Name}/{properties[1].Name}:";
                textBoxCharacteristics.Text = $"{properties[0].GetValue(s)},{properties[1].GetValue(s)}";
            }
            catch (IndexOutOfRangeException)
            {
                labelInfoShape.Text         = $"{type.Name}:\n{properties[0].Name}:";
                textBoxCharacteristics.Text = $"{properties[0].GetValue(s)}";
            }
            if (type == typeof(Rectangle))
            {
                labelPoint.Text = "Up-left point:";
            }
            else if (type == typeof(Triangle))
            {
                labelPoint.Text = "Base starting point:";
            }
            else
            {
                labelPoint.Text = "Center point:";
            }
            textBoxPoint.Text     = $"{s.Position.X},{s.Position.Y}";
            textBoxPen.Text       = $"{s.ShapeContourWidth}";
            comboBoxPenColor.Text = $"{s.ShapeContourColor.Name}";
            if (s.filled)
            {
                comboBoxFillColor.Text = $"{s.FillingColor.Name}";
            }
        }
コード例 #2
0
ファイル: Scene.cs プロジェクト: darinaKrasimirova/drawingApp
        private void ShowInfoSelected(Shape sh)
        {
            if (sh == null)
            {
                labelSelectedShape.Text = "";
                labelShapeType.Text     = "";
                labelSize.Text          = "";
                labelLocation.Text      = "";
                labelAreaSelected.Text  = "";
                labelNote.Text          = "";
            }
            else
            {
                labelSelectedShape.Text = "Selected Shape:";
                Type type       = sh.GetType();
                var  properties = type.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly);

                if (type == typeof(Rectangle) && ((int)properties[0].GetValue(sh) == (int)properties[1].GetValue(sh)))
                {
                    labelShapeType.Text = "Type: Square";
                }
                else if (type == typeof(Ellipse) && ((int)properties[0].GetValue(sh) == (int)properties[1].GetValue(sh)))
                {
                    labelShapeType.Text = "Type: Circle";
                }
                else
                {
                    labelShapeType.Text = "Type: " + type.Name;
                }

                try
                {
                    if ((int)properties[0].GetValue(sh) == (int)properties[1].GetValue(sh))
                    {
                        labelSize.Text = $"Size: {properties[0].Name}-{properties[0].GetValue(sh)}";
                    }
                    else
                    {
                        labelSize.Text = $"Size: {properties[0].Name}-{properties[0].GetValue(sh)},{properties[1].Name}-{properties[1].GetValue(sh)}";
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    labelSize.Text = $"Size: {properties[0].Name}-{properties[0].GetValue(sh)}";
                }
                string location = "";
                if (type == typeof(Rectangle))
                {
                    location = "Upper-left point";
                }
                else if (type == typeof(Triangle))
                {
                    location = "Base Start point";
                }
                else
                {
                    location = "Center";
                }
                labelLocation.Text     = $"Location: {location}({sh.Position.X},{sh.Position.Y})";
                labelAreaSelected.Text = $"Area: {sh.GetArea()}";
            }
        }