Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to subclass control?
Message
 
 
À
19/04/2008 19:30:01
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01184867
Message ID:
01401021
Vues:
41
>Hi Matt,
>
>Sorry for taking so long to get back to you, but I've been out of town for awhile and haven't been online.
>
>>the correct font appeared in the form textboxes at design-time, but the correct color only appeared at run-time. I made sure to "reset" the color property to get back to [DefaultValue], but the correct color still did not appear at design-time.
>
>I think that might be a bug, or maybe it's by design, but I found that if you're overriding the ForeColor of a TextBox (and other controls as well), then you also need to do the BackColor ... without setting a DefaultValue for the BackColor, the ForeColor doesn't seem to work the way it should.
>
>>It seems redundant to define a local class field with the desired color, and then also assigning the [DefaultValue] on the getter/setter to the same exact values. Looks like a good place for an oversight to happen when revising the code. Is there a good way to read the [DefaultValue] seeting from the local class field?
>
>This isn't quite what you asked about, but I thought I'd just elaborate a bit on this topic and maybe it will make more sense. The [DefaultValue] attribute serves two purposes:
>
> 1) It allows the property to be easily Reset to it's Default Value from the Property Sheet.
> 2) It prevents the code that sets the default value from actually showing up in the InitializeComponent() method.
>
>That second point is pretty important. Let's use a TextBox as an example, along with it's BackColor property. Say that you've not used the [DefaultValue] attribute in your TextBox, and simply set the value of the BackColor in your TextBox's constructor so that it looks like this:
>
>
>public class MyTextBox : TextBox
>{
>	public MyTextBox()
>	{
>		this.BackColor = Color.DarkGreen;
>	}
>}
>
>
Do you have a sample of the Class that has some code in its methods?

I want to write a common DataGrid class with MouseUp event as well as some custom method we can call called FormatGrid.

I have this code in the form right now
#region Grid Mouse Up Event

        /// <summary>
        /// Search grid mouse up event.       
        /// </summary>
        private void grdSearch_MouseUp(object sender, MouseEventArgs e)
        {
            DataGrid.HitTestInfo hti = this.grdSearch.HitTest(e.X, e.Y);
            try
            {
                switch (hti.Type)
                {
                    case DataGrid.HitTestType.Cell:
                        {
                            this.grdSearch.Select(hti.Row);
                            _rowNumber = hti.Row;
                            break;
                        }
                    case DataGrid.HitTestType.ColumnHeader:
                        {
                            break;
                        }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());

            }
        }
#endregion
And I started to write my class:
{
    public partial class grdOrderDetails:DataGrid 
    {
        private int _rowNumber = 0;
        public int _RowNumber
        {
            get
            {
                return this._rowNumber;
            }
            set
            {              
                this._rowNumber = value;
            }
        }
    }
But not sure how to incorporate the code above into this class.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform