Solved

.net Bug??

Posted on 2007-03-24
2
165 Views
Last Modified: 2013-12-17
First of all it's not really a question. I've already solved the problem by a workarround, but I simply want to know: WHY?!

Why does the following don't show the text on the screen? (simple version of the original code)

I inherit a textbox:

internal class MyTroubleTextBox : System.Windows.Forms.TextBox
{
    private string m_internalSave;
     public override string Text
    {
        get
        {
            return this.m_internalSave;
        }
        set
        {
            this.m_internalSave = value;
            base.Text = value;
        }
    }
}

Afterwards I set a Button on the Form and my inherited Textbox. Everytime the button is pressed I do the
following code:

protected void OnButtonPressed(object sender, System.Eventarg e){
{
    MyTextbox.Text += "C";
}

When you debugg the code step by step every value is set correctly, but no text is shown on the screen...

When you change two lines in the inherited class it works (more or less... one C less than there is infact (of course))

internal class MyTroubleTextBox : System.Windows.Forms.TextBox
{
    private string m_internalSave;
     public override string Text
    {
        get
        {
            return this.m_internalSave;
        }
        set
        {            
            base.Text = value;
            this.m_internalSave = value;
        }
    }
}

I'm using .net 2.0 and VS2005 prof.

Any ideas WHY this happens??????

best regards
0
Comment
Question by:_Eyeball_
  • 2
2 Comments
 
LVL 9

Accepted Solution

by:
ripahoratiu earned 125 total points
ID: 18791054
Well, it's not a bug, it's a normal behavior. Let's take it step by step:
1. The Text method of TextBox is not a virtual method. That means it has an implementation. Most probably its implementation comprise of raise some "ReRender" invisible from outside event when the text is changed and the corresponding event handler redraws it or effectively compare the values on set and redraw the text. This is what you've overrided.
2. Override stands for: "Provides a new implementation of a virtual member inherited from a base class."  and "An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method." So you basically dropped the old implementation (present in TextBox.Text) and provided a new one. As your implementation has nothing that effectively draws the text, nothing changes.
0
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 18791093
correction:  "Text is not an abstract property"
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 57
VB.Net Tranfer data between to VB.Net apps 8 40
.NET 2008 VB and C# 6 39
Why do I get the message "Message has been thrown by target of an invocation"? 22 55
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question