1

私は2つの異なるを持っていますForms。私の最初のフォームForm1は、TextBoxと呼ばれるメイン フォームですtextbox1。私の他のフォームが呼び出されFontSettings、使用されることになっているため、データForm1を継承できFontSettingsます。と をからに送信しようとしていstringます。このように見えます。2 integersFontSettingsForm1

  • フォント設定:

    Form1 form1 = new Form1();
    form1.insertFont(family, size, color);
    
  • Form1 :

    public void insertFont(string a, int b, string c)
    {
        if (textBox1.SelectionLength > 0)
        {
            xx = textBox1.SelectedText;
            textBox1.SelectedText = textBox1.SelectedText.Replace(xx, "" + a + "\" + b + c + "a");    
        }
        else
        {
            textBox1.Paste("" + a + "\" + b + c + "a");
        }
    }
    

使用される文字列と両方の整数はpublicです。

誰かが私が間違っていることを説明してください。

4

3 に答える 3

0

forsettings から form1 プロパティを変更したい場合、それを行う 1 つの方法は、form1 コントロールを見つけて、以下のように直接変更することです。

private void button1_Click(object sender, EventArgs e)
{
    TextBox t = Application.OpenForms["Form1"].Controls["textBox1"] as TextBox;
    t.Text = "some value here...";
    // do the same for the other two controls
    this.Close();
}
于 2013-09-13T06:07:04.577 に答える
0

シンプル。「form1」から FontSettings フォームを開く以下のコードを参照してください。

FontSettings newform = new FontSettings();
newform.ShowDialog();
MessageBox.Show(newform.MyString);
MessageBox.Show(string.Format("{0}", newform.MyInt1));
MessageBox.Show(string.Format("{0}", newform.MyInt2));

次に、FontSettings フォームで、いくつかのパブリック プロパティを作成して、「form1」から参照できるようにします。

public string MyString { get; set; }
public int MyInt1 { get; set; }
public int MyInt2 { get; set; }

次に、ボタンをクリックして次の操作を行います。

private void button1_Click(object sender, EventArgs e)
{
    MyString = "some value here...";
    MyInt1 = 28;
    MyInt2 = 77;
    this.Close();
}
于 2013-09-13T02:07:17.420 に答える