当前位置: 首页>>代码示例>>C#>>正文


C# IWindowsFormsEditorService接口代码示例

本文整理汇总了C#中System.Windows.Forms.Design.IWindowsFormsEditorService接口的典型用法代码示例。如果您正苦于以下问题:C# IWindowsFormsEditorService接口的具体用法?C# IWindowsFormsEditorService怎么用?C# IWindowsFormsEditorService使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。


IWindowsFormsEditorService接口属于System.Windows.Forms.Design命名空间,在下文中一共展示了IWindowsFormsEditorService接口的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestDialogEditor

//引入命名空间
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace IWindowsFormsEditorServiceExample
{	
    // Example UITypeEditor that uses the IWindowsFormsEditorService 
    // to display a Form.
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
    public class TestDialogEditor : UITypeEditor
    {
        public TestDialogEditor()
        {
        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            // Indicates that this editor can display a Form-based interface.
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(
            ITypeDescriptorContext context, 
            IServiceProvider provider, 
            object value)
        {
            // Attempts to obtain an IWindowsFormsEditorService.
            IWindowsFormsEditorService edSvc = 
                (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (edSvc == null)
            {
                return null;
            }
            
            // Displays a StringInputDialog Form to get a user-adjustable 
            // string value.
            using (StringInputDialog form = new StringInputDialog((string)value))
            {
                if (edSvc.ShowDialog(form) == DialogResult.OK)
                {
                    return form.inputTextBox.Text;
                }
            }

            // If OK was not pressed, return the original value
            return value;
        }        
    }

    // Example Form for entering a string.
    internal class StringInputDialog : Form
    {
        private System.Windows.Forms.Button ok_button;
        private System.Windows.Forms.Button cancel_button;
        public System.Windows.Forms.TextBox inputTextBox;

        public StringInputDialog(string text)
        {
            InitializeComponent();
            inputTextBox.Text = text;
        }

        private void InitializeComponent()
        {
            this.ok_button = new System.Windows.Forms.Button();
            this.cancel_button = new System.Windows.Forms.Button();
            this.inputTextBox = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            this.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.ok_button.Location = new System.Drawing.Point(180, 43);
            this.ok_button.Name = "ok_button";
            this.ok_button.TabIndex = 1;
            this.ok_button.Text = "OK";      
            this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;            
            this.cancel_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.cancel_button.Location = new System.Drawing.Point(260, 43);
            this.cancel_button.Name = "cancel_button";
            this.cancel_button.TabIndex = 2;
            this.cancel_button.Text = "Cancel";            
            this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.inputTextBox.Location = new System.Drawing.Point(6, 9);
            this.inputTextBox.Name = "inputTextBox";
            this.inputTextBox.Size = new System.Drawing.Size(327, 20);
            this.inputTextBox.TabIndex = 0;
            this.inputTextBox.Text = "";            
            this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.ClientSize = new System.Drawing.Size(342, 73);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.inputTextBox,
                                                                          this.cancel_button,
                                                                          this.ok_button});
            this.MinimumSize = new System.Drawing.Size(350, 100);
            this.Name = "StringInputDialog";
            this.Text = "String Input Dialog";
            this.ResumeLayout(false);
        }
    }

    // Provides an example control that displays instructions in design mode,
    // with which the example UITypeEditor is associated.
    public class WinFormsEdServiceDialogExampleControl : UserControl
    {
        [EditorAttribute(typeof(TestDialogEditor), typeof(UITypeEditor))]
        public string TestDialogString
        {
            get
            {
                return localDialogTestString;
            }
            set
            {
                localDialogTestString = value;
            }
        }
        private string localDialogTestString;
      
        public WinFormsEdServiceDialogExampleControl()
        {
            localDialogTestString = "Test String"; 
            this.Size = new Size(210, 74);
            this.BackColor = Color.Beige;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if( this.DesignMode )
            {
                e.Graphics.DrawString("Use the Properties window to show", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 5);
                e.Graphics.DrawString("a Form dialog box, using the", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 17);
                e.Graphics.DrawString("IWindowsFormsEditorService, for", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 29);
                e.Graphics.DrawString("configuring this control's", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 41);
                e.Graphics.DrawString("TestDialogString property.", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 53);
            }
            else
            {
                e.Graphics.DrawString("This example requires design mode.", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 5);
            }
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms.Design,代码行数:146,代码来源:IWindowsFormsEditorService

示例2: TestDropDownEditor

//引入命名空间
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace IWindowsFormsEditorServiceExample
{	
    // Example UITypeEditor that uses the IWindowsFormsEditorService to 
    // display a drop-down control.
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
    public class TestDropDownEditor : System.Drawing.Design.UITypeEditor
    {
        public TestDropDownEditor()
        {
        }
    
        public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            // Indicates that this editor can display a control-based 
            // drop-down interface.
            return UITypeEditorEditStyle.DropDown;
        }
    
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            // Attempts to obtain an IWindowsFormsEditorService.
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if( edSvc == null )
                return value;       
            
            // Displays a drop-down control.
            StringInputControl inputControl = new StringInputControl((string)value, edSvc);
            edSvc.DropDownControl(inputControl);
            return inputControl.inputTextBox.Text;
        }
    }

    // Example control for entering a string.
    internal class StringInputControl : System.Windows.Forms.UserControl
    {
        public System.Windows.Forms.TextBox inputTextBox;
        private System.Windows.Forms.Button ok_button;
        private System.Windows.Forms.Button cancel_button;
        private IWindowsFormsEditorService edSvc;

        public StringInputControl(string text, IWindowsFormsEditorService edSvc)
        {
            InitializeComponent();
            inputTextBox.Text = text;
            // Stores IWindowsFormsEditorService reference to use to 
            // close the control.
            this.edSvc = edSvc;
        }

        private void InitializeComponent()
        {
            this.inputTextBox = new System.Windows.Forms.TextBox();
            this.ok_button = new System.Windows.Forms.Button();
            this.cancel_button = new System.Windows.Forms.Button();
            this.SuspendLayout();
            this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.inputTextBox.Location = new System.Drawing.Point(6, 7);
            this.inputTextBox.Name = "inputTextBox";
            this.inputTextBox.Size = new System.Drawing.Size(336, 20);
            this.inputTextBox.TabIndex = 0;
            this.inputTextBox.Text = "";
            this.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.ok_button.Location = new System.Drawing.Point(186, 38);
            this.ok_button.Name = "ok_button";
            this.ok_button.TabIndex = 1;
            this.ok_button.Text = "OK";
            this.ok_button.Click += new EventHandler(this.CloseControl);
            this.cancel_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;            
            this.cancel_button.Location = new System.Drawing.Point(267, 38);
            this.cancel_button.Name = "cancel_button";
            this.cancel_button.TabIndex = 2;
            this.cancel_button.Text = "Cancel";
            this.cancel_button.Click += new EventHandler(this.CloseControl);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.cancel_button,
                                                                          this.ok_button,
                                                                          this.inputTextBox});
            this.Name = "StringInputControl";
            this.Size = new System.Drawing.Size(350, 70);
            this.ResumeLayout(false);
        }

        private void CloseControl(object sender, EventArgs e)
        {
            edSvc.CloseDropDown();
        }
    }
    
    // Provides an example control that displays instructions in design mode,
    // with which the example UITypeEditor is associated.
    public class WinFormsEdServiceDropDownExampleControl : UserControl
    {
        [EditorAttribute(typeof(TestDropDownEditor), typeof(UITypeEditor))]
        public string TestDropDownString
        {
            get
            {
                return localDropDownTestString;
            }
            set
            {       
                localDropDownTestString = value;
            }
        }
        
        private string localDropDownTestString;

        public WinFormsEdServiceDropDownExampleControl()
        {
            localDropDownTestString = "Test String";
            this.Size = new Size(210, 74);
            this.BackColor = Color.Beige;
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if( this.DesignMode )
            {
                e.Graphics.DrawString("Use the Properties window to show", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 5);
                e.Graphics.DrawString("a drop-down control, using the", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 17);
                e.Graphics.DrawString("IWindowsFormsEditorService, for", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 29);
                e.Graphics.DrawString("configuring this control's", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 41);
                e.Graphics.DrawString("TestDropDownString property.", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 53);
            }
            else
            {
                e.Graphics.DrawString("This example requires design mode.", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 5);
            }
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms.Design,代码行数:143,代码来源:IWindowsFormsEditorService


注:本文中的System.Windows.Forms.Design.IWindowsFormsEditorService接口示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。