Solved

.net Bug??

Posted on 2007-03-24
2
163 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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 …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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