Locked textbox text to variable

  • 2012年4月11日 下午 12:35
     
     
    how to assign the text of a textbox to a character type of variable in windows form application on vc++???

所有回覆

  • 2012年4月11日 下午 12:48
     
     
    how to assign the text of a textbox to a character type of variable in windows form application on vc++???
         

    Do you mean just

    textBox->Text = L"Some text";

    ?

    But why are you asking a WinForms question in the MFC/ATL forum?


    David Wilkinson | Visual C++ MVP

    • 已編輯 davewilkMVP 2012年4月11日 下午 12:49 addition
    •  
  • 2012年4月11日 下午 01:28
     
     

    no...

    char variable;

    variable=textBox->Text;

    textbox value to be assigned to a character type of variable

  • 2012年4月11日 下午 02:34
     
     

    On 11/04/2012 15:28, questionRaiser wrote:

    no...

    char variable;

    variable=textBox->Text;

    textbox value to be assigned to a character type of variable

    The Text property can be stored in a String instance.
    Then you can extract the first character (if this is what interests you) and assign it to a character variable.

    Giovanni

  • 2012年4月11日 下午 05:48
     
     
    questionRaiser wrote:
    char variable;
     
    variable=textBox->Text;
     
    textbox value to be assigned to a character type of variable
    Two things here
     
    1. char is a single character, not a string of characters
     
    2. Strings in .NET use 16-bit characters (wchar_t in C++) not 8-bit (char in C++).
     
    But as Giovanni suggsts, it is best to use System::String to store text
     
    String^ str = textBox->Text;
     

    David Wilkinson | Visual C++ MVP
  • 2012年4月12日 上午 07:25
     
     

    the thing is, i am browsing a image path through a dialog box in windows form application in vc++,then i need to work with that path.

    this path should be of string type not String^ for my work to proceed..help..

  • 2012年4月12日 上午 09:32
     
      包含代碼

    How about

    char *string;
    
    strcpy(string, textBox->text);

    Retrieving Text

    To retrieve all text from an edit control, first use the GetWindowTextLength function to  determine the size of buffer needed to contain the text. Next, retrieve the text by using the GetWindowText function.


    PAC

  • 2012年4月12日 上午 09:33
     
     提議的解答
    the thing is, i am browsing a image path through a dialog box in windows form application in vc++,then i need to work with that path.
     
    this path should be of string type not String^ for my work to proceed..help..
    Windows forms are part of the .NET library, which has its own classes for dealing with the file system (see System::IO namespace).
     
    But even if you want to use the standard Windows ways of accessing the file system, you should be using wchar_t strings for the file name, not char strings, because all recent versions of Windows use UTF-16 as the native character set.
     
    Go to
     
    Project properties->Configuration Properties->General->Character Set
     
    and make sure that "Use Unicode Character Set" is chosen.
     

    David Wilkinson | Visual C++ MVP
  • 2012年4月12日 上午 10:00
     
     
    How about
     
    char *string;
     
    strcpy(string, textBox->text);
    This cannot work because
     
    (a) no memory is allocated for "string"
     
    (b) the OP is using WinForms
     
    (c) It should be textBox->Text, not textBox->text
     
    (d) The Text() method returns System::String^, which cannot be used with strcpy.
     

    David Wilkinson | Visual C++ MVP
  • 2012年4月12日 上午 10:23
     
     

    Thanks Dave.  I stand corrected.  I apologize for any confusion...


    PAC

  • 2012年4月12日 上午 11:45
     
     已答覆

    i used another method,which helped me to proceed with my work.

    thank all for suggestion.

  • 2012年4月20日 上午 07:51
    版主
     
     

    Hello,

    Would you please sharing the solution with us?

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us