2012-12-09 29 views
-1

我有两种形式的主窗口和第二个窗口。我的第二个窗口(Form2)可以从表格2写入文本到表格1.在班级中,我可以为我的文本选择颜色,但是我的问题是当我按下发送文本的按钮时,它会显示没有我选择的颜色的文本,所以当我发送示例黄色时,它只是在Form1中的黑色文本。C中两种颜色之间的文本#

我不是C#专家,因为我很新。我相信它是一个非常简单的问题,但对我来说并不那么容易。

Form1.cs

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace tester 
{ 
    public partial class Form1 : Form 
    { 
    public string text; 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     Form2 NewForm2 = new Form2(this); 
     NewForm2.Show(); 
    } 

    internal void populate() 
    { 
     richTextBox1.Text = text; 
    } 
} 

Form2.cs

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

    namespace Tester 
    { 
    public partial class Form2 : Form 
    { 
    Form1 texting; 
    public Form2(Form1 iForm) 
    { 
     texting = iForm; 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     texting.text = richTextBox1.Text; 
     texting.populate(); 
     this.Close(); 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     if (MyColorDialog.ShowDialog() != DialogResult.Cancel) 
     { 
      richTextBox1.ForeColor = MyColorDialog.Color; 
     } 
    } 
} 
+1

字符串变量只包含“字符串”(谁会想到?)。 你想要的也是接管Texbox的“设计”。所以最简单的方法是公开文本框,而不是字符串变量。然后说一些linke Form1.YourBox.ForeColor = richTextBox1.ForeColor .... – CSharpie

回答

0

正如你在你的Form1中做public string text,你可以做一个public Color rictTextBoxColor属性。然后设置它,并在您的填充方法中引用它

相关问题