2016-09-11 10 views
0

私はWinform C#を初めて使用しています。WinForm CのテキストボックスMaximumSizeとMinimumSizeの設定方法C#

TextBoxプロパティまたはTextEditプロパティの最大サイズと最小サイズ幅をアプリケーションワイドに設定したいとします。どうすれば設定できますか?

+0

あなたは**広い**アプリケーションとはどういう意味ですか? – Berkay

+0

継承を使用しない場合は、Winformsで遠く離れません。 TextBoxから独自のクラスを派生させて、コンストラクタで優先プロパティ値を設定するだけです。すべてのUIデザインで一貫して新しいコントロール(コンパイル後にツールボックスの上部に追加されたもの)を使用すると、あなたが求めているものが得られます。 –

+0

ありがとうございます。あなたの提案は理解されています。しかし、私は、既存のTextEditにいくつかの可能性を期待していました。 –

答えて

1

このように、コンストラクタにあなたの設定を実装、TextBoxから継承classを作成します。@Hansは既存のインプレースエディタを拡張することができ、その後、あなたは簡単にこれらを使用することができ、言ったように

public class MyTextBox : TextBox { 
    public MyTextBox() : base { 
     //Set your properties as you like 
    } 
} 
0

任意のアプリケーションでのカスタムコントロール

別のプロジェクトを作成し、既存のDevExpresコントロールを継承するクラスを作成するだけで済みます。あなたの要求に応じて、TextEditEx:TextEditに継承されたTextEditクラスを継承することができます。

Custom Editors
は、カスタムエディタ(CustomEdit)を作成するためのこの単純な例を考えてみましょう。これは、TextEditクラスの子孫を表します。新しいリポジトリアイテムクラスはRepositoryItemCustomEditです。説明のために新しいプロパティ(UseDefaultMode)を導入しています。

using System.Drawing; 
using System.Reflection; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Reflection; 
using DevExpress.XtraEditors; 
using DevExpress.XtraEditors.Repository; 
using DevExpress.XtraEditors.Registrator; 
using DevExpress.XtraEditors.Drawing; 
using DevExpress.XtraEditors.ViewInfo; 
using DevExpress.Accessibility; 

namespace DevExpress.CustomEditors { 

    //The attribute that points to the registration method 
    [UserRepositoryItem("RegisterCustomEdit")] 
    public class RepositoryItemCustomEdit : RepositoryItemTextEdit { 

     //The static constructor that calls the registration method 
     static RepositoryItemCustomEdit() { RegisterCustomEdit(); } 

     //Initialize new properties 
     public RepositoryItemCustomEdit() {    
      useDefaultMode = true; 
     } 

     //The unique name for the custom editor 
     public const string CustomEditName = "CustomEdit"; 

     //Return the unique name 
     public override string EditorTypeName { get { return CustomEditName; } } 

     //Register the editor 
     public static void RegisterCustomEdit() { 
      //Icon representing the editor within a container editor's Designer 
      Image img = null; 
      try { 
       img = (Bitmap)Bitmap.FromStream(Assembly.GetExecutingAssembly(). 
        GetManifestResourceStream("DevExpress.CustomEditors.CustomEdit.bmp")); 
      } 
      catch { 
      } 
      EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(CustomEditName, 
       typeof(CustomEdit), typeof(RepositoryItemCustomEdit), 
       typeof(TextEditViewInfo), new TextEditPainter(), true, img, typeof(TextEditAccessible))); 
     } 

     //A custom property 
     private bool useDefaultMode; 

     public bool UseDefaultMode { 
      get { return useDefaultMode; } 
      set { 
       if(useDefaultMode != value) { 
        useDefaultMode = value;       
        OnPropertiesChanged(); 
       } 
      } 
     } 

     //Override the Assign method 
     public override void Assign(RepositoryItem item) { 
      BeginUpdate(); 
      try { 
       base.Assign(item); 
       RepositoryItemCustomEdit source = item as RepositoryItemCustomEdit; 
       if(source == null) return; 
       useDefaultMode = source.UseDefaultMode; 
      } 
      finally { 
       EndUpdate(); 
      } 
     } 
    } 

    [ToolboxItem(true)] 
    public class CustomEdit : TextEdit { 

     //The static constructor that calls the registration method 
     static CustomEdit() { RepositoryItemCustomEdit.RegisterCustomEdit(); } 

     //Initialize the new instance 
     public CustomEdit() { 
      //... 
     } 

     //Return the unique name 
     public override string EditorTypeName { get { return 
      RepositoryItemCustomEdit.CustomEditName; } } 

     //Override the Properties property 
     //Simply type-cast the object to the custom repository item type 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 
     public new RepositoryItemCustomEdit Properties { 
      get { return base.Properties as RepositoryItemCustomEdit; } 
     } 

    } 
} 

REFERE詳細な情報については、これらのDevExpress社のdocumenationリンク:
How To Extend DevExpress Controls
How to use a custom control in inplace mode in DevExpress containers
Inherited TextEdit - "Properties-Properties" are fixed after set within the contructor
How to create a transparent TextEdit

関連する問題