我的問題很簡單。我想單擊Form1中的一個面板,這將導致放置在form2上的userControl1中的label1更改爲「Text」。C#:試圖改變一個usercontrol文本框和背景顏色
單擊此面板也會更改所述userControl1的背景顏色。由於其保護級別,我收到錯誤「'TileInterFaceTest.Usercontrol1.label1'」,這讓我感到困惑。
即使單獨運行顏色更改代碼,它也無法達到所需結果。
要說清楚的是,在C#和編程方面,我是一個新手。直到現在我一直在使用Visual Basic,所以類,方法和對象的概念對我來說有點困惑。
這裏是我的代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TileInterFaceTest
{
public partial class Form1 : Form
{
public UserControl1 userControl1 = new UserControl1();
public Form2 form2 = new Form2();
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void panel1_DoubleClick(object sender, EventArgs e)
{
}
private void panel1_Click(object sender, EventArgs e)
{
form2.Show();
userControl1.BackColor = System.Drawing.Color.Red;
userControl1.label1 = "Text";
}
}
}
如果有人願意,仍然需要幫助。 – ShreddedWheat 2015-03-13 18:49:50