| re: Inheriting from a text box.....
Bruce,
OK - I get a big DUH! moment!. What you said makes absolutely perfect sense.
I guess I just assumed since I could 'see' the text box on the screen I
needed to add it manually (which is what I did).
You changes worked perfectly.
Thanks!
"Bruce Wood" <brucewood@canada.com> wrote in message
news:1141075416.162354.6860@p10g2000cwp.googlegrou ps.com...[color=blue]
> Your biggest problem here is that you have _two_ text boxes in this
> class.
>
> The first is the object instance itself: "this". Your class _is_ a
> TextBox.
>
> The second is the one you declare _inside_ your class,
> tbResultsMessages. This is a second, separate text box that is not
> parented anywhere and so will not appear on any surface. I have no idea
> how you convinced the Visual Studio Designer to put a TextBox on your
> TextBox. This looks like a UserControl that was changed to inherit from
> TextBox instead, which is another way to do the same thing (but more
> laborious, since it requires duplicating all of the TextBox properties
> in your UserControl).
>
> So, you do a lot of stuff manipulating tbResultsMessages, but since
> that text box doesn't appear anywhere on your screen, you can't see any
> of the text.
>
> Get rid of tbResultsMessages and the Designer-generated code, and
> change references to tbResultsMessages in AddItemMessages to be "this."
> You can get rid of OnPaint, as well: it's not needed. That leaves you
> with something like this:
>
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Drawing;
> using System.Data;
> using System.Windows.Forms;
>
>
> namespace MarlinVisualControls
> {
> /// <summary>
> /// Summary description for ResultMessages.
> /// </summary>
> public class ResultMessages : System.Windows.Forms.TextBox
> {
> private int mNumItemsDisplay = 20;
>
> /// <summary>
> /// Number of items that should be displayed in the text box.
> Default is 20.
> /// </summary>
> [DefaultValue(20)]
> public int prpNumItemsDisplay
> {
> get { return mNumItemsDisplay; }
> set { mNumItemsDisplay = value; }
> }
>
> /// <summary>
> /// Adds message to text box. Also makes sure there aren't to
> many
> messages already. (With Refresh)
> /// </summary>
> /// <param name="pvsMessage">Text to add to the text
> box.</param>
> public void AddItemToMessages ( string pvsMessage )
> {
> string newText = DateTime.Now.ToString() + " " +
> pvsMessage.Trim() +
> Environment.NewLine + this.Text;
> string[] lmsgs = newText.Split('\n');
> if ( lmsgs.Length > mNumItemsDisplay )
> {
> string lsNewMsgs = "";
> for ( int i = 0; i < mNumItemsDisplay; i++ )
> {
> string lsNewStr = lmsgs[i].Replace("\n", "");
> lsNewStr = lsNewStr.Replace("\r", "");
> lsNewMsgs += lsNewStr + Environment.NewLine;
> }
> newText = lsNewMsgs;
> }
> this.Text = newText;
> this.Select(0, 0);
> }
> }
> }
>[/color] |