问题 CustomPropertyGrid和CustomCollectionEditor-福彩12选5走势图集合中的更改

tim8w

知名会员
已加入
2020年9月8日
留言内容
81
编程经验
10+
我有一个CustomeEditor与CustomePropertyGrid。从CustomCollectionEditor中,我可以福彩12选5走势图到何时单击“确定”或“取消”按钮。我已经尝试了PropertyGrid文档中的几乎所有相关事件,而且似乎没有激发PropertyGrid的事件让我知道CollectionEditor中的“确定”按钮发生了。我该如何福彩12选5走势图?
 

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,534
地点
悉尼,澳大利亚
编程经验
10+
我可以福彩12选5走势图何时单击“确定”或“取消”按钮。
您实际上是说您无法福彩12选5走势图到它吗?
 

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,534
地点
悉尼,澳大利亚
编程经验
10+
I've never done what you're doing so I don't know the details of how it's usually done but I would assume you are calling CreateCollectionForm and then calling ShowDialog on that form. That method will return a result that indicates which button was clicked and you can do whatever you want with that. If you are creating custom classes then you can add your own custom event and raise it when ShowDialog returns DialogResult.OK. As you have provided no relevant code, I have only been able to rely on the results of some very quick research, so I'm not sure whether there is some specific reason that this suggestion wouldn't work.
 

tim8w

知名会员
已加入
2020年9月8日
留言内容
81
编程经验
10+
我可以从CollectionEditor中福彩12选5走势图到它,但是我需要某种方式才能从定义PropertyGrid的主窗体中福彩12选5走势图到它。我已经检查了PropertyGrid上的所有相关文档,并且似乎没有任何方法可以福彩12选5走势图其托管的集合中的任何更改。我将在此处发布相关代码:

主窗体PropertyGrid分配。这是我想知道集合是否更改的地方。

DefectPropertyGrid.SelectedObject = new FirstPassYield.PropertyGridItems();:
DefectPropertyGrid.SelectedObject = new FirstPassYield.PropertyGridItems();


PropertyGridItems的定义:

C#:
    internal class PropertyGridItems
    {
        private DefectCollection _Defects = new DefectCollection();

        [Editor(typeof(FirstPassYield.MyCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
        [Category("Defects")]
        [DisplayName("Add Defects")]
        [Description("Click on the Collection elipsis (...) to add the defects found for this WO Number.")]
        public DefectCollection Defects
        {
            get { return _Defects; }
            set { _Defects = value; }
        }
    }

MyCollectionEditor的定义:

C#:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using System.ComponentModel.Design;
using System.Windows.Forms;

namespace FirstPassYield
{
    public class MyCollectionEditor : CollectionEditor
    {
        public static bool bEditingCollection = false;

        public delegate void MyFormClosedEventHandler(object sender, FormClosedEventArgs e);

        //public event MyFormClosedEventHandler MyFormClosed;

        public delegate void MyFormLoadEventHandler(object sender, System.EventArgs e);

        //public event MyFormLoadEventHandler MyFormLoad;


        public delegate void MyFormControlAddedEventHandler(object sender, System.EventArgs e);

        //public event MyFormControlAddedEventHandler MyFormControlAdded;

        public MyCollectionEditor(Type type)
            : base(type)
        {
        }

        protected override string GetDisplayText(object value)
        {
            Defect item = new Defect();
            item = (FirstPassYield.Defect)value;

            if (String.IsNullOrEmpty(item.DefectCode))
                return base.GetDisplayText(" ");
            else
            {
                String sDisplay = item.DefectCode.ToString().Substring(0, item.DefectCode.ToString().IndexOf(":"));
                return base.GetDisplayText(string.Format("{0}", sDisplay));
            }
        }

        protected override CollectionForm CreateCollectionForm()
        {
            CollectionForm collectionForm = base.CreateCollectionForm();
            Font myDialogFont = new Font("Microsoft San Seraf", 16.0f, FontStyle.Bold); // Form's Font
            Font myFont = new Font("Microsoft San Seraf", 16.0f, FontStyle.Bold);       // Individual Item's Font

            // Set the Dialog Font
            collectionForm.Font = myDialogFont;

            // Turn OFF Help Button
            collectionForm.HelpButton = false;

            // Set the BackColor, StartPosition and Size of the form
            collectionForm.BackColor = Color.FromName("SteelBlue");
            collectionForm.StartPosition = FormStartPosition.CenterParent;
            collectionForm.Size = new Size(1100, 500);

            // Add Form Handlers for trapping Load and Close
            collectionForm.FormClosed += this.collection_FormClosed;
            collectionForm.Load += this.collection_FormLoad;

            var overArchingTableLayoutPanel = collectionForm.Controls["overArchingTableLayoutPanel"];

            // Change the size of the "listbox"
            Size mySize = new Size(200, 337);
            overArchingTableLayoutPanel.Controls["listbox"].Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left;
            overArchingTableLayoutPanel.Controls["listbox"].Size = mySize;

            var addRemoveTableLayoutPanel = overArchingTableLayoutPanel.Controls["addRemoveTableLayoutPanel"];
            // Change the width of the Add/Remove Buttons to match the new "listbox" size
            addRemoveTableLayoutPanel.Controls["addButton"].Anchor = 0;
            addRemoveTableLayoutPanel.Controls["addButton"].Width = addRemoveTableLayoutPanel.Controls["addButton"].Width / 2;
            addRemoveTableLayoutPanel.Controls["removeButton"].Anchor = 0;
            addRemoveTableLayoutPanel.Controls["removeButton"].Width = addRemoveTableLayoutPanel.Controls["removeButton"].Width / 2;
            // Set the BackColor of the Buttons - It appears that they get set by default to the form's BackColor
            addRemoveTableLayoutPanel.Controls["addButton"].BackColor = Color.FromName("Control");
            addRemoveTableLayoutPanel.Controls["removeButton"].BackColor = Color.FromName("Control");
            // Set the Font for the Add, Remove buttons
            addRemoveTableLayoutPanel.Controls["addButton"].Font = myFont;
            addRemoveTableLayoutPanel.Controls["removeButton"].Font = myFont;
            // Add Handlers for trapping Add and Remove Buttons
            addRemoveTableLayoutPanel.Controls["addButton"].Click += AddButton_Click;
            addRemoveTableLayoutPanel.Controls["removeButton"].Click += RemoveButton_Click;

            var okCancelTableLayoutPanel = overArchingTableLayoutPanel.Controls["okCancelTableLayoutPanel"];
            // Set the BackColor of the Buttons - It appears that they get set by default to the form's BackColor
            okCancelTableLayoutPanel.Controls["okButton"].BackColor = Color.FromName("Control");
            okCancelTableLayoutPanel.Controls["cancelButton"].BackColor = Color.FromName("Control");
            // Set the Font for the OK, Cancel buttons
            okCancelTableLayoutPanel.Controls["okButton"].Font = myFont;
            okCancelTableLayoutPanel.Controls["cancelButton"].Font = myFont;
            // Add Handlers for trapping OK and Cancel Buttons
            okCancelTableLayoutPanel.Controls["okButton"].Click += OKButton_Click;
            okCancelTableLayoutPanel.Controls["cancelButton"].Click += CancelButton_Click;

            // Change the Member Labels' Text, Color and Font
            overArchingTableLayoutPanel.Controls["membersLabel"].Text = "&Defect List:";
            overArchingTableLayoutPanel.Controls["membersLabel"].ForeColor = Color.FromName("White");
            overArchingTableLayoutPanel.Controls["membersLabel"].Font = myFont;
            // Change the Properties Labels' Text, Color and Font
            overArchingTableLayoutPanel.Controls["propertiesLabel"].Text = "&Properties:";
            overArchingTableLayoutPanel.Controls["propertiesLabel"].ForeColor = Color.FromName("White");
            overArchingTableLayoutPanel.Controls["propertiesLabel"].Font = myFont;
            // Set the BackColor of the Buttons - It appears that they get set by default to the form's BackColor
            overArchingTableLayoutPanel.Controls["upButton"].BackColor = Color.FromName("Control");
            overArchingTableLayoutPanel.Controls["downButton"].BackColor = Color.FromName("Control");
            // Add Handlers for trapping Up and Down Buttons
            overArchingTableLayoutPanel.Controls["upButton"].Click += UpButton_Click;
            overArchingTableLayoutPanel.Controls["downButton"].Click += DownButton_Click;

            var propertyBrowser = overArchingTableLayoutPanel.Controls["propertyBrowser"] as PropertyGrid;
            if (propertyBrowser.Controls.Count != 0)
            {
                // Set the PropertySorting and ToolbarVisibilty
                propertyBrowser.PropertySort = PropertySort.NoSort;
                propertyBrowser.ToolbarVisible = false;
            }

            // Do something based on which Collection Editor was called
            switch (collectionForm.Text)
            {
                case "Defect Collection Editor":
                    {
                        break;
                    }
            }

            // Hide Add, Remove, Up and Down Buttons
            //collectionForm.Controls["overArchingTableLayoutPanel"].Controls["addRemoveTableLayoutPanel"].Controls["addButton"].Visible = false;
            //collectionForm.Controls["overArchingTableLayoutPanel"].Controls["addRemoveTableLayoutPanel"].Controls["removeButton"].Visible = false;
            //collectionForm.Controls["overArchingTableLayoutPanel"].Controls["upButton"].Visible = false;
            //collectionForm.Controls["overArchingTableLayoutPanel"].Controls["downButton"].Visible = false;

            return collectionForm;
        }

        private void collection_FormLoad(object sender, System.EventArgs e)
        {
            bEditingCollection = true;
        }

        private void AddButton_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Add Button Clicked");
        }

        private void RemoveButton_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Remove Button Clicked");
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("OK Button Clicked");
            FirstPassYield.frmFirstPassYield.bCollectionChanged = true;
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Cancel Button Clicked");
        }

        private void UpButton_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Up Button Clicked");
        }

        private void DownButton_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Down Button Clicked");
        }

        private void collection_FormClosed(object sender, FormClosedEventArgs e)
        {
            bEditingCollection = false;
        }
    }
}

正如您在Custom CollectionEditor中看到的那样,我可以知道已按下了哪些按钮。我真的只需要知道按下OK键即可,但在这里不是。我需要检查主窗体中的一堆控件。
 
最佳 底部