How to access and modify TextBox text in a Visual c++ Express Forms app.?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tony rivard
    New Member
    • Oct 2010
    • 2

    #1

    How to access and modify TextBox text in a Visual c++ Express Forms app.?

    I am fairly new to C++ and need help with the following

    I Created a Forms application in Visualc++ Express with a TextBox control

    I now want to access that textbox and change its content programmaticall y.

    I cannot seem to reference it in any way. I've tried many things but still keep getting compile errors

    Most of the code is generated by VisualC++ including the initialization of the form. This works fine and puts the form up on screen when executed. But any code I've added to try and access the textbox generates compile errors.

    If anyone could tell me what the basic overall code structure should be I would appreciate it. Thanks.
  • stfu
    New Member
    • May 2010
    • 1

    #2
    What errors? Show your code and maybe try this:
    Code:
    textBox1->Text = "TextBox Test Control";

    Comment

    • Tony rivard
      New Member
      • Oct 2010
      • 2

      #3
      // TestBed3.cpp : main project file.

      #include "stdafx.h"
      #include "Form1.h"
      #include <iostream>
      using namespace TestBed3;

      [STAThreadAttrib ute]

      int main(array<Syst em::String ^> ^args)
      {
      // Enabling Windows XP visual effects before any controls are created
      Application::En ableVisualStyle s();
      Application::Se tCompatibleText RenderingDefaul t(false);

      // Create the main window and run it
      Application::Ru n(gcnew Form1());

      textBox1->Text = "TextBox Test Control";

      return 0;
      }

      I've inserted the line in main but these are the errors I get.

      1>TestBed3.cpp( 19): error C2065: 'textBox1' : undeclared identifier
      1>TestBed3.cpp( 19): error C2227: left of '->Text' must point to class/struct/union/generic type
      1> type is ''unknown-type''

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Code:
        textBox1->Text = "TextBox Test Control";
        Assumiong the code above works, where do you create textBox1? The compiler can't find your textbox.

        Comment

        Working...