Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,037

HOME > .NET Framework > Forum > C# WinApp สงสัยเกี่ยวกับ การนำ Control มาลงใน navigator ครับ



 

C# WinApp สงสัยเกี่ยวกับ การนำ Control มาลงใน navigator ครับ

 



Topic : 126129



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



โค้ด 2 ตัวนี้ต่างกันแค่ตัวหนึ่งมีคำว่า TextBox แล้วตัวที่ 2 ก็เปลี่ยนคำว่า TextBox เป็น DateTimePicker แค่นั้นเองครับ
ทั้ง property หรือ event ต่างๆก็เหมือนกัน
แต่ ตัวที่เป็น DateTimePicker มันมีออกมาเวลาเรัยกใช้ผ่าน navigator ครับ
หฤฏฟดฟ

Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//------------------------------------------------------------------------------
// <copyright file="ToolStripTextBox.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

namespace System.WindowsTOR.Forms
{
    using System;
    using System.Drawing;
    using System.Drawing.Design;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows.Forms.Layout;
    using System.Collections.Specialized;
    using System.Runtime.InteropServices;
    using System.Windows.Forms.Design;
    using System.Security;
    using System.Security.Permissions;
    using Microsoft.Win32;
using System.Windows.Forms;

    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class ToolStripTextBoxTOR : ToolStripControlHost
    {

        internal static readonly object EventTextBoxTextAlignChanged = new object();
        internal static readonly object EventAcceptsTabChanged = new object();
        internal static readonly object EventBorderStyleChanged = new object();
        internal static readonly object EventHideSelectionChanged = new object();
        internal static readonly object EventReadOnlyChanged = new object();
        internal static readonly object EventMultilineChanged = new object();
        internal static readonly object EventModifiedChanged = new object();

        public ToolStripTextBoxTOR()
            : base(CreateControlInstance())
        {
            ToolStripTextBoxControl textBox = Control as ToolStripTextBoxControl;
            textBox.Owner = this;
        }

        public ToolStripTextBoxTOR(string name)
            : this()
        {
            this.Name = name;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public ToolStripTextBoxTOR(Control c)
            : base(c)
        {
           // throw new NotSupportedException(SR.GetString(SR.ToolStripMustSupplyItsOwnTextBox));
        }

        [
        Browsable(false),
        EditorBrowsable(EditorBrowsableState.Never),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public override Image BackgroundImage
        {
            get
            {
                return base.BackgroundImage;
            }
            set
            {
                base.BackgroundImage = value;
            }
        }

        [
        Browsable(false),
        EditorBrowsable(EditorBrowsableState.Never),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public override ImageLayout BackgroundImageLayout
        {
            get
            {
                return base.BackgroundImageLayout;
            }
            set
            {
                base.BackgroundImageLayout = value;
            }
        }



        protected override Size DefaultSize
        {
            get
            {
                return new Size(100, 22);
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public TextBox TextBox
        {
            get
            {
                return Control as TextBox;
            }
        }

        private static Control CreateControlInstance()
        {
            TextBox textBox = new ToolStripTextBoxControl();
            textBox.BorderStyle = BorderStyle.Fixed3D;
            textBox.AutoSize = true;
            return textBox;
        }

        private void HandleAcceptsTabChanged(object sender, EventArgs e)
        {
            OnAcceptsTabChanged(e);
        }
        private void HandleBorderStyleChanged(object sender, EventArgs e)
        {
            OnBorderStyleChanged(e);
        }
        private void HandleHideSelectionChanged(object sender, EventArgs e)
        {
            OnHideSelectionChanged(e);
        }
        private void HandleModifiedChanged(object sender, EventArgs e)
        {
            OnModifiedChanged(e);
        }
        private void HandleMultilineChanged(object sender, EventArgs e)
        {
            OnMultilineChanged(e);
        }
        private void HandleReadOnlyChanged(object sender, EventArgs e)
        {
            OnReadOnlyChanged(e);
        }
        void RaiseEvent(object key, EventArgs e)
        {
            EventHandler handler = (EventHandler)Events[key];
            if (handler != null) handler(this, e);
        }
        private void HandleTextBoxTextAlignChanged(object sender, EventArgs e)
        {
            RaiseEvent(EventTextBoxTextAlignChanged, e);
        }
        protected virtual void OnAcceptsTabChanged(EventArgs e)
        {
            RaiseEvent(EventAcceptsTabChanged, e);
        }
        protected virtual void OnBorderStyleChanged(EventArgs e)
        {
            RaiseEvent(EventBorderStyleChanged, e);
        }
        protected virtual void OnHideSelectionChanged(EventArgs e)
        {
            RaiseEvent(EventHideSelectionChanged, e);
        }
        protected virtual void OnModifiedChanged(EventArgs e)
        {
            RaiseEvent(EventModifiedChanged, e);
        }
        protected virtual void OnMultilineChanged(EventArgs e)
        {
            RaiseEvent(EventMultilineChanged, e);
        }
        protected virtual void OnReadOnlyChanged(EventArgs e)
        {
            RaiseEvent(EventReadOnlyChanged, e);
        }


        protected override void OnSubscribeControlEvents(Control control)
        {
            TextBox textBox = control as TextBox;
            if (textBox != null)
            {
                // Please keep this alphabetized and in [....] with Unsubscribe
                // 
                textBox.AcceptsTabChanged += new EventHandler(HandleAcceptsTabChanged);
                textBox.BorderStyleChanged += new EventHandler(HandleBorderStyleChanged);
                textBox.HideSelectionChanged += new EventHandler(HandleHideSelectionChanged);
                textBox.ModifiedChanged += new EventHandler(HandleModifiedChanged);
                textBox.MultilineChanged += new EventHandler(HandleMultilineChanged);
                textBox.ReadOnlyChanged += new EventHandler(HandleReadOnlyChanged);
                textBox.TextAlignChanged += new EventHandler(HandleTextBoxTextAlignChanged);

            }

            base.OnSubscribeControlEvents(control);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {

            TextBox textBox = control as TextBox;
            if (textBox != null)
            {
                // Please keep this alphabetized and in [....] with Subscribe
                // 
                textBox.AcceptsTabChanged -= new EventHandler(HandleAcceptsTabChanged);
                textBox.BorderStyleChanged -= new EventHandler(HandleBorderStyleChanged);
                textBox.HideSelectionChanged -= new EventHandler(HandleHideSelectionChanged);
                textBox.ModifiedChanged -= new EventHandler(HandleModifiedChanged);
                textBox.MultilineChanged -= new EventHandler(HandleMultilineChanged);
                textBox.ReadOnlyChanged -= new EventHandler(HandleReadOnlyChanged);
                textBox.TextAlignChanged -= new EventHandler(HandleTextBoxTextAlignChanged);
            }
            base.OnUnsubscribeControlEvents(control);

        }



        #region WrappedProperties
        [DefaultValue(false)]
        public bool AcceptsTab
        {
            get { return TextBox.AcceptsTab; }
            set { TextBox.AcceptsTab = value; }
        }


        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),Localizable(true),
        Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, ", typeof(UITypeEditor)),
        Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
        public System.Windows.Forms.AutoCompleteStringCollection AutoCompleteCustomSource
        {
            get { return TextBox.AutoCompleteCustomSource; }
            set { TextBox.AutoCompleteCustomSource = value; }
        }

        [DefaultValue(AutoCompleteMode.None),Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
        public AutoCompleteMode AutoCompleteMode
        {
            get { return TextBox.AutoCompleteMode; }
            set { TextBox.AutoCompleteMode = value; }
        }

        [DefaultValue(AutoCompleteSource.None),Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
        public AutoCompleteSource AutoCompleteSource
        {
            get { return TextBox.AutoCompleteSource; }
            set { TextBox.AutoCompleteSource = value; }
        }

        [DefaultValue(BorderStyle.Fixed3D)]
        public BorderStyle BorderStyle
        {
            get { return TextBox.BorderStyle; }
            set { TextBox.BorderStyle = value; }
        }

        [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool CanUndo
        {
            get { return TextBox.CanUndo; }
        }

        [DefaultValue(CharacterCasing.Normal)]
        public CharacterCasing CharacterCasing
        {
            get { return TextBox.CharacterCasing; }
            set { TextBox.CharacterCasing = value; }
        }

        [DefaultValue(true)]
        public bool HideSelection
        {
            get { return TextBox.HideSelection; }
            set { TextBox.HideSelection = value; }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),Localizable(true),
        Editor("System.Windows.Forms.Design.StringArrayEditor, " , typeof(UITypeEditor))]
        public string[] Lines
        {
            get { return TextBox.Lines; }
            set { TextBox.Lines = value; }
        }

        [DefaultValue(32767),Localizable(true)]
        public int MaxLength
        {
            get { return TextBox.MaxLength; }
            set { TextBox.MaxLength = value; }
        }

        [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool Modified
        {
            get { return TextBox.Modified; }
            set { TextBox.Modified = value; }
        }

        [DefaultValue(false),Localizable(true),RefreshProperties(RefreshProperties.All),Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public bool Multiline
        {
            get { return TextBox.Multiline; }
            set { TextBox.Multiline = value; }
        }

        [DefaultValue(false)]
        public bool ReadOnly
        {
            get { return TextBox.ReadOnly; }
            set { TextBox.ReadOnly = value; }
        }
        [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),]
        public string SelectedText
        {
            get { return TextBox.SelectedText; }
            set { TextBox.SelectedText = value; }
        }

        [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int SelectionLength
        {
            get { return TextBox.SelectionLength; }
            set { TextBox.SelectionLength = value; }
        }
        [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int SelectionStart
        {
            get { return TextBox.SelectionStart; }
            set { TextBox.SelectionStart = value; }
        }
        [DefaultValue(true)]
        public bool ShortcutsEnabled
        {
            get { return TextBox.ShortcutsEnabled; }
            set { TextBox.ShortcutsEnabled = value; }
        }
        [Browsable(false)]
        public int TextLength
        {
            get { return TextBox.TextLength; }
        }

        [Localizable(true),DefaultValue(HorizontalAlignment.Left)]
        public HorizontalAlignment TextBoxTextAlign
        {
            get { return TextBox.TextAlign; }
            set { TextBox.TextAlign = value; }
        }

        [Localizable(true),DefaultValue(true),Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public bool WordWrap
        {
            get { return TextBox.WordWrap; }
            set { TextBox.WordWrap = value; }
        }


        #endregion WrappedProperties



        #region WrappedEvents

        public event EventHandler AcceptsTabChanged
        {
            add
            {
                Events.AddHandler(EventAcceptsTabChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventAcceptsTabChanged, value);
            }
        }

        public event EventHandler BorderStyleChanged
        {
            add
            {
                Events.AddHandler(EventBorderStyleChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventBorderStyleChanged, value);
            }
        }

        public event EventHandler HideSelectionChanged
        {
            add
            {
                Events.AddHandler(EventHideSelectionChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventHideSelectionChanged, value);
            }
        }

        public event EventHandler ModifiedChanged
        {
            add
            {
                Events.AddHandler(EventModifiedChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventModifiedChanged, value);
            }
        }

        [  Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public event EventHandler MultilineChanged
        {
            add
            {
                Events.AddHandler(EventMultilineChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventMultilineChanged, value);
            }
        }

        public event EventHandler ReadOnlyChanged
        {
            add
            {
                Events.AddHandler(EventReadOnlyChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventReadOnlyChanged, value);
            }
        }


        public event EventHandler TextBoxTextAlignChanged
        {
            add
            {
                Events.AddHandler(EventTextBoxTextAlignChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventTextBoxTextAlignChanged, value);
            }
        }
        #endregion WrappedEvents

        #region WrappedMethods
        public void AppendText(string text) { TextBox.AppendText(text); }
        public void Clear() { TextBox.Clear(); }
        public void ClearUndo() { TextBox.ClearUndo(); }
        public void Copy() { TextBox.Copy(); }
        public void Cut() { TextBox.Copy(); }
        public void DeselectAll() { TextBox.DeselectAll(); }
        public char GetCharFromPosition(System.Drawing.Point pt) { return TextBox.GetCharFromPosition(pt); }
        public int GetCharIndexFromPosition(System.Drawing.Point pt) { return TextBox.GetCharIndexFromPosition(pt); }
        public int GetFirstCharIndexFromLine(int lineNumber) { return TextBox.GetFirstCharIndexFromLine(lineNumber); }
        public int GetFirstCharIndexOfCurrentLine() { return TextBox.GetFirstCharIndexOfCurrentLine(); }
        public int GetLineFromCharIndex(int index) { return TextBox.GetLineFromCharIndex(index); }
        public System.Drawing.Point GetPositionFromCharIndex(int index) { return TextBox.GetPositionFromCharIndex(index); }
        public void Paste() { TextBox.Paste(); }
        public void ScrollToCaret() { TextBox.ScrollToCaret(); }
        public void Select(int start, int length) { TextBox.Select(start, length); }
        public void SelectAll() { TextBox.SelectAll(); }
        public void Undo() { TextBox.Undo(); }
        #endregion
        private class ToolStripTextBoxControl : TextBox
        {

            private System.WindowsTOR.Forms.ToolStripTextBoxTOR ownerItem;

            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")]  // FXCop doesnt understand that setting Font changes the value of isFontSet
            public ToolStripTextBoxControl()
            {

            }

            public System.WindowsTOR.Forms.ToolStripTextBoxTOR Owner
            {
                get { return ownerItem; }
                set { ownerItem = value; }
            }

            protected override void OnGotFocus(EventArgs e)
            {
                base.OnGotFocus(e);
            }



        }


    }

}




Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//------------------------------------------------------------------------------
// <copyright file="ToolStripTextBox.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

namespace System.WindowsTOR.Forms
{
    using System;
    using System.Drawing;
    using System.Drawing.Design;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows.Forms.Layout;
    using System.Collections.Specialized;
    using System.Runtime.InteropServices;
    using System.Windows.Forms.Design;
    using System.Security;
    using System.Security.Permissions;
    using Microsoft.Win32;
    using System.Windows.Forms;

    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class ToolStripDateTimePickerTOR : ToolStripControlHost
    {
        
        internal static readonly object EventTextBoxTextAlignChanged = new object();
        internal static readonly object EventAcceptsTabChanged = new object();
        internal static readonly object EventBorderStyleChanged = new object();
        internal static readonly object EventHideSelectionChanged = new object();
        internal static readonly object EventReadOnlyChanged = new object();
        internal static readonly object EventMultilineChanged = new object();
        internal static readonly object EventModifiedChanged = new object();

        public ToolStripDateTimePickerTOR()
            : base(CreateControlInstance())
        {
            ToolStripDateTimePickerTORControl textBox = Control as ToolStripDateTimePickerTORControl;
            textBox.Owner = this;
        }

        public ToolStripDateTimePickerTOR(string name)
            : this()
        {
            this.Name = name;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public ToolStripDateTimePickerTOR(Control c)
            : base(c)
        {
            // throw new NotSupportedException(SR.GetString(SR.ToolStripMustSupplyItsOwnTextBox));
        }

        [
        Browsable(false),
        EditorBrowsable(EditorBrowsableState.Never),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public override Image BackgroundImage
        {
            get
            {
                return base.BackgroundImage;
            }
            set
            {
                base.BackgroundImage = value;
            }
        }

        [
        Browsable(false),
        EditorBrowsable(EditorBrowsableState.Never),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public override ImageLayout BackgroundImageLayout
        {
            get
            {
                return base.BackgroundImageLayout;
            }
            set
            {
                base.BackgroundImageLayout = value;
            }
        }



        protected override Size DefaultSize
        {
            get
            {
                return new Size(100, 22);
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public TextBox TextBox
        {
            get
            {
                return Control as TextBox;
            }
        }

        private static Control CreateControlInstance()
        {
            DateTimePicker textBox = new ToolStripDateTimePickerTORControl();
            textBox.Format= DateTimePickerFormat.Short;
            textBox.AutoSize = true;
            return textBox;
        }

        private void HandleAcceptsTabChanged(object sender, EventArgs e)
        {
            OnAcceptsTabChanged(e);
        }
        private void HandleBorderStyleChanged(object sender, EventArgs e)
        {
            OnBorderStyleChanged(e);
        }
        private void HandleHideSelectionChanged(object sender, EventArgs e)
        {
            OnHideSelectionChanged(e);
        }
        private void HandleModifiedChanged(object sender, EventArgs e)
        {
            OnModifiedChanged(e);
        }
        private void HandleMultilineChanged(object sender, EventArgs e)
        {
            OnMultilineChanged(e);
        }
        private void HandleReadOnlyChanged(object sender, EventArgs e)
        {
            OnReadOnlyChanged(e);
        }
        void RaiseEvent(object key, EventArgs e)
        {
            EventHandler handler = (EventHandler)Events[key];
            if (handler != null) handler(this, e);
        }
        private void HandleTextBoxTextAlignChanged(object sender, EventArgs e)
        {
            RaiseEvent(EventTextBoxTextAlignChanged, e);
        }
        protected virtual void OnAcceptsTabChanged(EventArgs e)
        {
            RaiseEvent(EventAcceptsTabChanged, e);
        }
        protected virtual void OnBorderStyleChanged(EventArgs e)
        {
            RaiseEvent(EventBorderStyleChanged, e);
        }
        protected virtual void OnHideSelectionChanged(EventArgs e)
        {
            RaiseEvent(EventHideSelectionChanged, e);
        }
        protected virtual void OnModifiedChanged(EventArgs e)
        {
            RaiseEvent(EventModifiedChanged, e);
        }
        protected virtual void OnMultilineChanged(EventArgs e)
        {
            RaiseEvent(EventMultilineChanged, e);
        }
        protected virtual void OnReadOnlyChanged(EventArgs e)
        {
            RaiseEvent(EventReadOnlyChanged, e);
        }


        protected override void OnSubscribeControlEvents(Control control)
        {
            TextBox textBox = control as TextBox;
            if (textBox != null)
            {
                // Please keep this alphabetized and in [....] with Unsubscribe
                // 
                textBox.AcceptsTabChanged += new EventHandler(HandleAcceptsTabChanged);
                textBox.BorderStyleChanged += new EventHandler(HandleBorderStyleChanged);
                textBox.HideSelectionChanged += new EventHandler(HandleHideSelectionChanged);
                textBox.ModifiedChanged += new EventHandler(HandleModifiedChanged);
                textBox.MultilineChanged += new EventHandler(HandleMultilineChanged);
                textBox.ReadOnlyChanged += new EventHandler(HandleReadOnlyChanged);
                textBox.TextAlignChanged += new EventHandler(HandleTextBoxTextAlignChanged);

            }

            base.OnSubscribeControlEvents(control);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {

            TextBox textBox = control as TextBox;
            if (textBox != null)
            {
                // Please keep this alphabetized and in [....] with Subscribe
                // 
                textBox.AcceptsTabChanged -= new EventHandler(HandleAcceptsTabChanged);
                textBox.BorderStyleChanged -= new EventHandler(HandleBorderStyleChanged);
                textBox.HideSelectionChanged -= new EventHandler(HandleHideSelectionChanged);
                textBox.ModifiedChanged -= new EventHandler(HandleModifiedChanged);
                textBox.MultilineChanged -= new EventHandler(HandleMultilineChanged);
                textBox.ReadOnlyChanged -= new EventHandler(HandleReadOnlyChanged);
                textBox.TextAlignChanged -= new EventHandler(HandleTextBoxTextAlignChanged);
            }
            base.OnUnsubscribeControlEvents(control);

        }



        #region WrappedProperties
        [DefaultValue(false)]
        public bool AcceptsTab
        {
            get { return TextBox.AcceptsTab; }
            set { TextBox.AcceptsTab = value; }
        }


        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Localizable(true),
        Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, ", typeof(UITypeEditor)),
        Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
        public System.Windows.Forms.AutoCompleteStringCollection AutoCompleteCustomSource
        {
            get { return TextBox.AutoCompleteCustomSource; }
            set { TextBox.AutoCompleteCustomSource = value; }
        }

        [DefaultValue(AutoCompleteMode.None), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
        public AutoCompleteMode AutoCompleteMode
        {
            get { return TextBox.AutoCompleteMode; }
            set { TextBox.AutoCompleteMode = value; }
        }

        [DefaultValue(AutoCompleteSource.None), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
        public AutoCompleteSource AutoCompleteSource
        {
            get { return TextBox.AutoCompleteSource; }
            set { TextBox.AutoCompleteSource = value; }
        }

        [DefaultValue(BorderStyle.Fixed3D)]
        public BorderStyle BorderStyle
        {
            get { return TextBox.BorderStyle; }
            set { TextBox.BorderStyle = value; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool CanUndo
        {
            get { return TextBox.CanUndo; }
        }

        [DefaultValue(CharacterCasing.Normal)]
        public CharacterCasing CharacterCasing
        {
            get { return TextBox.CharacterCasing; }
            set { TextBox.CharacterCasing = value; }
        }

        [DefaultValue(true)]
        public bool HideSelection
        {
            get { return TextBox.HideSelection; }
            set { TextBox.HideSelection = value; }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(true),
        Editor("System.Windows.Forms.Design.StringArrayEditor, ", typeof(UITypeEditor))]
        public string[] Lines
        {
            get { return TextBox.Lines; }
            set { TextBox.Lines = value; }
        }

        [DefaultValue(32767), Localizable(true)]
        public int MaxLength
        {
            get { return TextBox.MaxLength; }
            set { TextBox.MaxLength = value; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool Modified
        {
            get { return TextBox.Modified; }
            set { TextBox.Modified = value; }
        }

        [DefaultValue(false), Localizable(true), RefreshProperties(RefreshProperties.All), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public bool Multiline
        {
            get { return TextBox.Multiline; }
            set { TextBox.Multiline = value; }
        }

        [DefaultValue(false)]
        public bool ReadOnly
        {
            get { return TextBox.ReadOnly; }
            set { TextBox.ReadOnly = value; }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),]
        public string SelectedText
        {
            get { return TextBox.SelectedText; }
            set { TextBox.SelectedText = value; }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int SelectionLength
        {
            get { return TextBox.SelectionLength; }
            set { TextBox.SelectionLength = value; }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int SelectionStart
        {
            get { return TextBox.SelectionStart; }
            set { TextBox.SelectionStart = value; }
        }
        [DefaultValue(true)]
        public bool ShortcutsEnabled
        {
            get { return TextBox.ShortcutsEnabled; }
            set { TextBox.ShortcutsEnabled = value; }
        }
        [Browsable(false)]
        public int TextLength
        {
            get { return TextBox.TextLength; }
        }

        [Localizable(true), DefaultValue(HorizontalAlignment.Left)]
        public HorizontalAlignment TextBoxTextAlign
        {
            get { return TextBox.TextAlign; }
            set { TextBox.TextAlign = value; }
        }

        [Localizable(true), DefaultValue(true), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public bool WordWrap
        {
            get { return TextBox.WordWrap; }
            set { TextBox.WordWrap = value; }
        }


        #endregion WrappedProperties



        #region WrappedEvents

        public event EventHandler AcceptsTabChanged
        {
            add
            {
                Events.AddHandler(EventAcceptsTabChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventAcceptsTabChanged, value);
            }
        }

        public event EventHandler BorderStyleChanged
        {
            add
            {
                Events.AddHandler(EventBorderStyleChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventBorderStyleChanged, value);
            }
        }

        public event EventHandler HideSelectionChanged
        {
            add
            {
                Events.AddHandler(EventHideSelectionChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventHideSelectionChanged, value);
            }
        }

        public event EventHandler ModifiedChanged
        {
            add
            {
                Events.AddHandler(EventModifiedChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventModifiedChanged, value);
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public event EventHandler MultilineChanged
        {
            add
            {
                Events.AddHandler(EventMultilineChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventMultilineChanged, value);
            }
        }

        public event EventHandler ReadOnlyChanged
        {
            add
            {
                Events.AddHandler(EventReadOnlyChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventReadOnlyChanged, value);
            }
        }


        public event EventHandler TextBoxTextAlignChanged
        {
            add
            {
                Events.AddHandler(EventTextBoxTextAlignChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventTextBoxTextAlignChanged, value);
            }
        }
        #endregion WrappedEvents

        #region WrappedMethods
        public void AppendText(string text) { TextBox.AppendText(text); }
        public void Clear() { TextBox.Clear(); }
        public void ClearUndo() { TextBox.ClearUndo(); }
        public void Copy() { TextBox.Copy(); }
        public void Cut() { TextBox.Copy(); }
        public void DeselectAll() { TextBox.DeselectAll(); }
        public char GetCharFromPosition(System.Drawing.Point pt) { return TextBox.GetCharFromPosition(pt); }
        public int GetCharIndexFromPosition(System.Drawing.Point pt) { return TextBox.GetCharIndexFromPosition(pt); }
        public int GetFirstCharIndexFromLine(int lineNumber) { return TextBox.GetFirstCharIndexFromLine(lineNumber); }
        public int GetFirstCharIndexOfCurrentLine() { return TextBox.GetFirstCharIndexOfCurrentLine(); }
        public int GetLineFromCharIndex(int index) { return TextBox.GetLineFromCharIndex(index); }
        public System.Drawing.Point GetPositionFromCharIndex(int index) { return TextBox.GetPositionFromCharIndex(index); }
        public void Paste() { TextBox.Paste(); }
        public void ScrollToCaret() { TextBox.ScrollToCaret(); }
        public void Select(int start, int length) { TextBox.Select(start, length); }
        public void SelectAll() { TextBox.SelectAll(); }
        public void Undo() { TextBox.Undo(); }
        #endregion
        private class ToolStripDateTimePickerTORControl : DateTimePicker
        {

            private System.WindowsTOR.Forms.ToolStripDateTimePickerTOR ownerItem;

            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")]  // FXCop doesnt understand that setting Font changes the value of isFontSet
            public ToolStripDateTimePickerTORControl()
            {

            }

            public System.WindowsTOR.Forms.ToolStripDateTimePickerTOR Owner
            {
                get { return ownerItem; }
                set { ownerItem = value; }
            }

            protected override void OnGotFocus(EventArgs e)
            {
                base.OnGotFocus(e);
            }



        }


    }

}






Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x), Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-01-22 17:36:47 By : lamaka.tor View : 913 Reply : 2
 

 

No. 1



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ลองเปลี่ยนมาเป็น Label และตัด property กับ Event บางส่วนออกไป ก็ใช้งานได้ครับ
รึว่า DateTimePicker ต้อง Add ผ่าน ToolStripControlHost เท่านั้นรึครับ

แผเป

Code (C#)
namespace System.WindowsTOR.Forms
{
    using System;
    using System.Drawing;
    using System.Drawing.Design;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows.Forms.Layout;
    using System.Collections.Specialized;
    using System.Runtime.InteropServices;
    using System.Windows.Forms.Design;
    using System.Security;
    using System.Security.Permissions;
    using Microsoft.Win32;
    using System.Windows.Forms;

    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class ToolStripLabelTOR : ToolStripControlHost
    {

        internal static readonly object EventLabelTextAlignChanged = new object();
        internal static readonly object EventAcceptsTabChanged = new object();
        internal static readonly object EventBorderStyleChanged = new object();
        internal static readonly object EventHideSelectionChanged = new object();
        internal static readonly object EventReadOnlyChanged = new object();
        internal static readonly object EventMultilineChanged = new object();
        internal static readonly object EventModifiedChanged = new object();

        public ToolStripLabelTOR()
            : base(CreateControlInstance())
        {
            ToolStripLabelControl Label = Control as ToolStripLabelControl;
            Label.Owner = this;
        }

        public ToolStripLabelTOR(string name)
            : this()
        {
            this.Name = name;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public ToolStripLabelTOR(Control c)
            : base(c)
        {
            // throw new NotSupportedException(SR.GetString(SR.ToolStripMustSupplyItsOwnLabel));
        }

        [
        Browsable(false),
        EditorBrowsable(EditorBrowsableState.Never),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        public override Image BackgroundImage
        {
            get
            {
                return base.BackgroundImage;
            }
            set
            {
                base.BackgroundImage = value;
            }
        }

        [
        Browsable(false),
        EditorBrowsable(EditorBrowsableState.Never),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public override ImageLayout BackgroundImageLayout
        {
            get
            {
                return base.BackgroundImageLayout;
            }
            set
            {
                base.BackgroundImageLayout = value;
            }
        }



        protected override Size DefaultSize
        {
            get
            {
                return new Size(100, 22);
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Label Label
        {
            get
            {
                return Control as Label;
            }
        }

        private static Control CreateControlInstance()
        {
            Label Label = new ToolStripLabelControl();
            Label.BorderStyle = BorderStyle.Fixed3D;
            Label.AutoSize = true;
            return Label;
        }

        private void HandleAcceptsTabChanged(object sender, EventArgs e)
        {
            OnAcceptsTabChanged(e);
        }
        private void HandleBorderStyleChanged(object sender, EventArgs e)
        {
            OnBorderStyleChanged(e);
        }
        private void HandleHideSelectionChanged(object sender, EventArgs e)
        {
            OnHideSelectionChanged(e);
        }
        private void HandleModifiedChanged(object sender, EventArgs e)
        {
            OnModifiedChanged(e);
        }
        private void HandleMultilineChanged(object sender, EventArgs e)
        {
            OnMultilineChanged(e);
        }
        private void HandleReadOnlyChanged(object sender, EventArgs e)
        {
            OnReadOnlyChanged(e);
        }
        void RaiseEvent(object key, EventArgs e)
        {
            EventHandler handler = (EventHandler)Events[key];
            if (handler != null) handler(this, e);
        }
        private void HandleLabelTextAlignChanged(object sender, EventArgs e)
        {
            RaiseEvent(EventLabelTextAlignChanged, e);
        }
        protected virtual void OnAcceptsTabChanged(EventArgs e)
        {
            RaiseEvent(EventAcceptsTabChanged, e);
        }
        protected virtual void OnBorderStyleChanged(EventArgs e)
        {
            RaiseEvent(EventBorderStyleChanged, e);
        }
        protected virtual void OnHideSelectionChanged(EventArgs e)
        {
            RaiseEvent(EventHideSelectionChanged, e);
        }
        protected virtual void OnModifiedChanged(EventArgs e)
        {
            RaiseEvent(EventModifiedChanged, e);
        }
        protected virtual void OnMultilineChanged(EventArgs e)
        {
            RaiseEvent(EventMultilineChanged, e);
        }
        protected virtual void OnReadOnlyChanged(EventArgs e)
        {
            RaiseEvent(EventReadOnlyChanged, e);
        }


        protected override void OnSubscribeControlEvents(Control control)
        {
            Label Label = control as Label;
            if (Label != null)
            {
                // Please keep this alphabetized and in [....] with Unsubscribe
                // 
                Label.TextAlignChanged += new EventHandler(HandleLabelTextAlignChanged);

            }

            base.OnSubscribeControlEvents(control);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {

            Label Label = control as Label;
            if (Label != null)
            {
                // Please keep this alphabetized and in [....] with Subscribe
                // 

                Label.TextAlignChanged -= new EventHandler(HandleLabelTextAlignChanged);
            }
            base.OnUnsubscribeControlEvents(control);

        }





        #region WrappedEvents

        public event EventHandler AcceptsTabChanged
        {
            add
            {
                Events.AddHandler(EventAcceptsTabChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventAcceptsTabChanged, value);
            }
        }

        public event EventHandler BorderStyleChanged
        {
            add
            {
                Events.AddHandler(EventBorderStyleChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventBorderStyleChanged, value);
            }
        }

        public event EventHandler HideSelectionChanged
        {
            add
            {
                Events.AddHandler(EventHideSelectionChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventHideSelectionChanged, value);
            }
        }

        public event EventHandler ModifiedChanged
        {
            add
            {
                Events.AddHandler(EventModifiedChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventModifiedChanged, value);
            }
        }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public event EventHandler MultilineChanged
        {
            add
            {
                Events.AddHandler(EventMultilineChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventMultilineChanged, value);
            }
        }

        public event EventHandler ReadOnlyChanged
        {
            add
            {
                Events.AddHandler(EventReadOnlyChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventReadOnlyChanged, value);
            }
        }


        public event EventHandler LabelTextAlignChanged
        {
            add
            {
                Events.AddHandler(EventLabelTextAlignChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventLabelTextAlignChanged, value);
            }
        }
        #endregion WrappedEvents


        private class ToolStripLabelControl : Label
        {

            private System.WindowsTOR.Forms.ToolStripLabelTOR ownerItem;

            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")]  // FXCop doesnt understand that setting Font changes the value of isFontSet
            public ToolStripLabelControl()
            {
                
            }

            public System.WindowsTOR.Forms.ToolStripLabelTOR Owner
            {
                get { return ownerItem; }
                set { ownerItem = value; }
            }

            protected override void OnGotFocus(EventArgs e)
            {
                base.OnGotFocus(e);
            }



        }


    }

}









ประวัติการแก้ไข
2017-01-22 17:45:17
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-01-22 17:43:11 By : lamaka.tor
 


 

No. 2



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

//ToolStripDateTimePickerTOR
Code (C#)
namespace System.WindowsTOR.Forms
{
    using System;
    using System.Drawing;
    using System.Drawing.Design;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows.Forms.Layout;
    using System.Collections.Specialized;
    using System.Runtime.InteropServices;
    using System.Windows.Forms.Design;
    using System.Security;
    using System.Security.Permissions;
    using Microsoft.Win32;
    using System.Windows.Forms;

    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class ToolStripDateTimePickerTOR : ToolStripControlHost
    {
        
        public ToolStripDateTimePickerTOR()
            : base(CreateControlInstance())
        {
            ToolStripLabelControl Label = Control as ToolStripLabelControl;
            Label.Owner = this;
        }

        public ToolStripDateTimePickerTOR(string name)
            : this()
        {
            this.Name = name;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public ToolStripDateTimePickerTOR(Control c)
            : base(c)
        {
        }

        public Label Label
        {
            get { return Control as Label; }
        }

        private static Control CreateControlInstance()
        {
            DateTimePicker Label = new ToolStripLabelControl();
            Label.AutoSize = true;
            return Label;
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            Label Label = control as Label;
            base.OnSubscribeControlEvents(control);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {
            Label Label = control as Label;
            base.OnUnsubscribeControlEvents(control);
        }

        private class ToolStripLabelControl : DateTimePicker
        {

            private System.WindowsTOR.Forms.ToolStripDateTimePickerTOR ownerItem;
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")]  // FXCop doesnt understand that setting Font changes the value of isFontSet
            public ToolStripLabelControl()
            {

            }

            public System.WindowsTOR.Forms.ToolStripDateTimePickerTOR Owner
            {
                get { return ownerItem; }
                set { ownerItem = value; }
            }

            protected override void OnGotFocus(EventArgs e)
            {
                base.OnGotFocus(e);
            }



        }


    }

}


//ToolStripLabelTOR
Code (C#)
namespace System.WindowsTOR.Forms
{
    using System;
    using System.Drawing;
    using System.Drawing.Design;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Windows.Forms.Layout;
    using System.Collections.Specialized;
    using System.Runtime.InteropServices;
    using System.Windows.Forms.Design;
    using System.Security;
    using System.Security.Permissions;
    using Microsoft.Win32;
    using System.Windows.Forms;

    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.ContextMenuStrip)]
    public class ToolStripLabelTOR : ToolStripControlHost
    {

        public ToolStripLabelTOR()
            : base(CreateControlInstance())
        {
            ToolStripLabelControl Label = Control as ToolStripLabelControl;
            Label.Owner = this;
        }

        public ToolStripLabelTOR(string name)
            : this()
        {
            this.Name = name;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public ToolStripLabelTOR(Control c)
            : base(c)
        {
        }

        public Label Label
        {
            get{return Control as Label;}
        }

        private static Control CreateControlInstance()
        {
            Label Label = new ToolStripLabelControl();
            Label.BorderStyle = BorderStyle.Fixed3D;
            Label.AutoSize = true;
            return Label;
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            Label Label = control as Label;
            base.OnSubscribeControlEvents(control);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {
            Label Label = control as Label;
            base.OnUnsubscribeControlEvents(control);
        }

        private class ToolStripLabelControl : Label
        {

            private System.WindowsTOR.Forms.ToolStripLabelTOR ownerItem;
            [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")]  // FXCop doesnt understand that setting Font changes the value of isFontSet
            public ToolStripLabelControl()
            {
                
            }

            public System.WindowsTOR.Forms.ToolStripLabelTOR Owner
            {
                get { return ownerItem; }
                set { ownerItem = value; }
            }

            protected override void OnGotFocus(EventArgs e)
            {
                base.OnGotFocus(e);
            }



        }


    }

}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-01-22 18:07:14 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# WinApp สงสัยเกี่ยวกับ การนำ Control มาลงใน navigator ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่