CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2012
    Posts
    13

    Question Find control or check if control exists

    Hey all,

    So I wanted to make a program where you can add a textbox or what ever for stuff.
    The code typed in the textbox is also a part of result in the results.

    But if the control doesn't exists, than the result is NOT related to the textbox.
    If the control does exists, than the result is related to the textbox.

    My question now is, how to check if a textbox (or a control, no matter which) does exists.
    I thought about something like this:
    Code:
    if (Control::Exists("textBox1")
    {
    }
    But this one doesn't work.

    I also tried this:
    Code:
     if (textBox1 == NULL)
    {
    }
    This one does neither work.

    I got one simple solution, and that is the findControl stuff.
    But I only can find those for VB or C#.

    So someone got me a better solution or can explain the C# findControl stuff to me?

    Thanks,
    Miraclezz

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Find control or check if control exists

    You already have noticed that there's no such thing as a static Control::Exists() method, and I, personally, have no idea of any "C# findControl stuff". Perhaps someone who knows C# better than I do can tell you about that. But to check whether a given control is present on a given form, you may inspect that form's Controls property. However, which particular criterium of the controls in there you're going to inspect depends on your concrete scenario, that I don't know of course.

    Checking for textBox1 == NULL is basically a valid idea, except that (1) in C++/CLI you'd rather need to compare against nullptr instead of NULL (though I, myself, never actually tried to check against NULL in C++/CLI; maybe that even would work given you include a header that defines NULL) and (2) a control variale you created using the IDE named textBox1 would of course be != nullptr since it gets assigned a valid control in the form's InitializeComponent() method.

    All the above pertains to checking for the existence of a given control on one given form. Checking whether a given control exists somewhere throughougt your entire app is possible as well, yet considerably more complicated.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Jun 2013
    Posts
    1

    Re: Find control or check if control exists

    * * * * If ListBox1.Created.Equals(True) Then
    * * * * * * MsgBox("ListBox1.Created.Equals(True)")
    * * * * End If

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured