Solved

.net Bug??

Posted on 2007-03-24
2
160 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
Comment Utility
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
Comment Utility
correction:  "Text is not an abstract property"
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Total in textboxes 9 33
Separate a number and letter from a string 25 23
.Net application crashing 6 18
Spacing between controls 4 13
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now