?
Solved

.net Bug??

Posted on 2007-03-24
2
Medium Priority
?
168 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 375 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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