string 값들을 textbox 쪽에 .text 형식으로 저장하는것..

fkqpfwl121의 이미지


예를들어 form1에서 string[] args = new string[10];

args[0] = " ****oksafpokasf ";
args[1] = " 9281401824 ";

이렇게 있고 생성자를 통해서 이렇게 넘겨주었습니다.

form2 fr = new form2(args);

그리고 form2 부분에서

public Form2(String[] st)
{
InitializeComponent();
textBox1.Text = st.ToString();

}

이렇게 받는것을 정의하였고 아무 이상이 없습니다.

근데 실행을 하면 textbox의 값에 System.String[] 이렇게 나옵니다.

제가원하는건 이게 아니라 st[0] , st[1] ... 에 저장한 .text의 값이 나와야 하는데

어떻게 나오게 해야할지 모르겠습니다.

그래서 생성자를 써서

public Form2(String[] st)
{
InitializeComponent();

for (int i = 0; i < 3; i++)
{
textBox1.Text = st[i];

}
}

이렇게 만들어서 값이 나오지만, 마지막 textbox에 출력된것 하나만 나오는게 아니라

.text에 순서 대로 쌓이게 하고 싶습니다.

어떻게 해야 하나요?

shint의 이미지


문자열 누적방법
textBox1.Text = textBox1.Text + st[i];

textBox1.Text = textBox1.Text + st[i].ToString();

C#의 string은 new를 해준다음. delete가 없네요.

정확한 내용은 C# 책을 참고하시기 바랍니다.

String 클래스
https://msdn.microsoft.com/ko-kr/library/system.string(v=vs.110).aspx#

방법: System::String을 표준 문자열로 변환
https://msdn.microsoft.com/ko-kr/library/1b4az623.aspx#

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

fkqpfwl121의 이미지

form1의 체크박스에 체크를 하고 확인을 누르면 form2의 textbox에 말씀하신 tostring을 써서 이어져 됩니다.

그런데 나머지는 다 되는데 form1에서 하나씩 눌러도 되고 2개씩 눌러도 되는데 3을 누르고 1을 누르게 되면

왠지모르게 체크를 한 순서대로 나오질 않습니다.

체크 2를 누르고 체크3을 눌렀는데 체크2 체크3이 아니라 사진에는 체크3 체크2가 나온는 이유를 잘 모르겠습니다..;

꼼꼼히 본다고 보는데 이유는 잘 모르겠습니다.. 도와주세요 ㅠㅠ

form1 에서의 코드입니다.

namespace WindowsFormsApplication999
{
public partial class Form1 : Form
{
CheckBox[] boxes = new CheckBox[3];


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
CheckBox[] cbs = new CheckBox[3];

int checkBoxIndex = 0;

//모든 컨트롤 갯수 만큼 for문을 돌림, 체크박스 뿐아니라 버튼, 라벨까지 전부 포함
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is CheckBox)
{
cbs[checkBoxIndex++] = (CheckBox)this.Controls[i];
}
}

// 체크된 체크박수 갯수 알아냄
int arrayLength = 0;
for (int i = 0; i < cbs.Length; i++)
{
if (cbs[i].Checked)
{
arrayLength++;
}
}

string[] args = new string[arrayLength];
int argsIndex = 0;
for (int i = 0; i < cbs.Length; i++)
{
if (cbs[i].Checked)
{
args[argsIndex++] = cbs[i].Text;

}
}

Form2 fm = new Form2(args,argsIndex);
fm.Show();

//for (int i = 0; i < 3; i++)
//{
// boxes[i] = new CheckBox();
// boxes[i].Checked = true;
//}

//CheckBox[] count = new CheckBox[3];

//count[0] = checkBox1;
//count[1] = checkBox2;
//count[2] = checkBox3;

//for (int z = 0; z < 3; z++)
//{
// if (boxes[z].Checked == count[z].Checked)
// {
// count[z].Enabled = false;

// }
//}

//Form2 fm = new Form2();
//fm.Show();
}
}
}

그리고 form2에서의 코드입니다.

namespace WindowsFormsApplication999
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

public Form2(String[] st,int n)
{
InitializeComponent();

for (int i = 0; i < n; i++)
{
textBox1.Text = textBox1.Text + st[i].ToString() ;

}
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void Form2_Load(object sender, EventArgs e)
{

}
}
}

댓글 첨부 파일: 
첨부파일 크기
Image icon abc.png222.21 KB

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.