none
pls help RRS feed

  • Question

  • hi,

    i created usercontrol,inthat i have numericupdown control.
    i have form.that form has tabcontrol.i added this usercontrol to one of the tab page.
    now i want to get the value of numeric control when form loads.how to do that.pls help.


    my code is


    myUsercontrol.cs


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    //using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    namespace Project1
    {
        public partial class myUserControl : UserControl
        {
            public myUserControl()
            {
                InitializeComponent();
                setval();
            }
            public void setval()
            {
                numericUpDown1.Value = 25;
            }
        }
    }
    -------------------------
    formdi.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 Project1
    {
        public partial class Formdi : Form
        {
            public Formdi()
            {
                InitializeComponent();
                settabs();
            }
            private void Formdi_Load(object sender, EventArgs e)
            {
                //here capture the value of numericupdown1

            }
            private void settabs()
            {
               
                myUserControl mycon = new myUserControl();
                tabPage2.Controls.Add(mycon);
              
            }
           
        }
    }

    Wednesday, May 4, 2011 2:08 PM

Answers

  • This should help...

    public partial class myUserControl : UserControl
    {
      public myUserControl()
      {
        InitializeComponent();
          
        MyValue = 25;
      }
    
      public decimal MyValue
      {
        get { return numericUpDown1.Value; }
        set { numericUpDown1.Value = value; }
      }
    }
    
    public partial class Formdi : Form
    {
      myUserControl mycon = new myUserControl();
    
      public Formdi()
      {
        InitializeComponent();
        settabs();
      }
      private void Formdi_Load(object sender, EventArgs e)
      {
        decimal val = mycon.MyValue;
        // ...
      }
    
      private void settabs()
      {
        tabPage2.Controls.Add(mycon);
      }
    }
    

    ShaneB

    • Marked as answer by eryang Tuesday, May 17, 2011 9:24 AM
    Thursday, May 5, 2011 3:32 AM