开发者

Accessing data between user controls

I am a beginner for Visual Studio C# 2008. Currently, I am 开发者_如何学Pythoncreating the program which requires me to have user input in one User Control item and this data is needed to be passed on to another User Control for arithmetic manipulation.

My first User Control is called Structure_Data. I will be getting input values from the textboxes named LengthB_txt, WidthB_txt and HeightB_txt.

These value inputs in the textboxes above will be accessed in a new UserControl called CollectionArea.

I do not know how to connect the User controls as well as to access the data. In my User Control: Collection Area, to make my final result appear in the Ad_txt textbox, I did the following codes. However, I got error :

'WindowsFormsApplication1.Structure_Data.LengthB_txt' is inaccessible due to its protection level

Please help me. I am stuck! =( Thanks...


private void Ad_txt_TextChanged(object sender, EventArgs e)
    {
      //  const double PI = 3.14159265;
        double Lb;
        double Wb;
        double Hb;

        // Get the input value for Dimensions: Length
        Lb = Convert.ToDouble(StructDataPass.LengthB_txt.Text);
        Wb = Convert.ToDouble(StructDataPass.WidthB_txt.Text);
        Hb = Convert.ToDouble(StructDataPass.HeightB_txt.Text);

        double Ad_temp=0;
        double result_temp1=0;
        result_temp1 = Math.Pow(3 * Hb, 2);
        Ad_temp = Lb*Wb*6*Hb*(Lb+Wb)+(Math.PI)*result_temp1;
        Ad_txt.Text = Convert.ToString(Ad_temp);

    }


How about the following:

  1. Create a class with a property for each control
  2. Each usercontrol gets a reference to the class instance which would be initialised in the main form.
  3. When a value changes in a user control raise an event which is caught my the main form
  4. The other user control would be subscribed to that event and refresh its textbox
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜