Class extending the ColorEditor which adds the capability to change the alpha value of the color. For use on a property of type: Microsoft.Xna.Framework.Graphics.Color.
Inheritance: System.Drawing.Design.ColorEditor
Beispiel #1
0
            /// <summary>
            /// Creates a new instance.
            /// </summary>
            /// <param name="colorEditor">The editor this instance belongs to.</param>
            public ColorUiWrapper(XnaColorUiTypeEditor colorEditor)
            {
                Type colorUiType = typeof(ColorEditor).GetNestedType(
                    "ColorUI", BindingFlags.CreateInstance | BindingFlags.NonPublic);
                ConstructorInfo constructorInfo = colorUiType.GetConstructor(
                    new[]
                {
                    typeof(ColorEditor)
                });

                _control = (Control)constructorInfo.Invoke(
                    new object[]
                {
                    colorEditor
                });

                _control.BackColor = SystemColors.Control;

                var alphaPanel = new Panel
                {
                    BackColor = SystemColors.Control,
                    Dock      = DockStyle.Right,
                    Width     = 28
                };

                _control.Controls.Add(alphaPanel);

                _tbAlpha = new TrackBar
                {
                    Orientation = Orientation.Vertical,
                    Dock        = DockStyle.Fill,
                    TickStyle   = TickStyle.None,
                    Maximum     = byte.MaxValue,
                    Minimum     = byte.MinValue
                };

                _tbAlpha.ValueChanged += onTrackBarAlphaValueChanged;

                alphaPanel.Controls.Add(_tbAlpha);

                _lblAlpha = new Label
                {
                    Text      = @"0",
                    Dock      = DockStyle.Bottom,
                    TextAlign = ContentAlignment.MiddleCenter
                };

                alphaPanel.Controls.Add(_lblAlpha);

                Type type = _control.GetType( );

                _startMethodInfo   = type.GetMethod("Start");
                _endMethodInfo     = type.GetMethod("End");
                _valuePropertyInfo = type.GetProperty("Value");

                _control.SizeChanged += onControlSizeChanged;
            }
            /// <summary>
            /// Creates a new instance.
            /// </summary>
            /// <param name="colorEditor">The editor this instance belongs to.</param>
            public ColorUiWrapper( XnaColorUiTypeEditor colorEditor )
            {
                Type colorUiType = typeof( ColorEditor ).GetNestedType(
                    "ColorUI", BindingFlags.CreateInstance | BindingFlags.NonPublic ) ;
                ConstructorInfo constructorInfo = colorUiType.GetConstructor(
                    new[ ]
                        {
                            typeof( ColorEditor )
                        } ) ;
                _control = (Control) constructorInfo.Invoke(
                    new object[ ]
                        {
                            colorEditor
                        } ) ;

                _control.BackColor = SystemColors.Control ;

                var alphaPanel = new Panel
                    {
                        BackColor = SystemColors.Control,
                        Dock = DockStyle.Right,
                        Width = 28
                    } ;
                _control.Controls.Add( alphaPanel ) ;

                _tbAlpha = new TrackBar
                    {
                        Orientation = Orientation.Vertical,
                        Dock = DockStyle.Fill,
                        TickStyle = TickStyle.None,
                        Maximum = byte.MaxValue,
                        Minimum = byte.MinValue
                    } ;

                _tbAlpha.ValueChanged += onTrackBarAlphaValueChanged ;

                alphaPanel.Controls.Add( _tbAlpha ) ;

                _lblAlpha = new Label
                    {
                        Text = @"0",
                        Dock = DockStyle.Bottom,
                        TextAlign = ContentAlignment.MiddleCenter
                    } ;

                alphaPanel.Controls.Add( _lblAlpha ) ;

                Type type = _control.GetType( ) ;

                _startMethodInfo = type.GetMethod( "Start" ) ;
                _endMethodInfo = type.GetMethod( "End" ) ;
                _valuePropertyInfo = type.GetProperty( "Value" ) ;

                _control.SizeChanged += onControlSizeChanged ;
            }