Solved

.net Bug??

Posted on 2007-03-24
2
166 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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