How to pass value from one user control to another user control using c#

  • Thread starter Thread starter MSA_Aydn
  • Start date Start date
M

MSA_Aydn

Guest
Hi,

I am developing a form application with c #. I use 2 user controls in the form application I developed, these user controls have one picturebox.

I want to send the data from the picturebox in usercontrol 1 to the picturebox in usercontrol 2.

but i haven't done it yet.

// This is main form code

namespace FrmDrag
{
public partial class Form1 : Form
{
static Form1 _obj;
private bool mouseDown;
private Point lastPosition;
previewTab ptab = new previewTab();
resultsTab rtab = new resultsTab();

public Panel PnlContainer
{
get { return panelContainer; }
set { panelContainer = value; }
}
public static Form1 Instance
{
get
{
if (_obj == null)
{
_obj = new Form1();
}
return _obj;
}
}


public Form1()
{

InitializeComponent();
_obj = this;
ptab.Dock = DockStyle.Fill;
rtab.Dock = DockStyle.Fill;
panelContainer.Controls.Add(ptab);
panelContainer.Controls.Add(rtab);
this.panelContainer.Controls["previewTab"].BringToFront();


}


private void Form1_Load(object sender, EventArgs e)
{
menuSidePanel.Height = previewBtn.Height;
menuSidePanel.Left = previewBtn.Left;

}

private void previewBtn_MouseMove(object sender, MouseEventArgs e)
{

menuSidePanel.Height = previewBtn.Height;
menuSidePanel.Left = previewBtn.Left;

}

private void resultsBtn_MouseMove(object sender, MouseEventArgs e)
{
menuSidePanel.Height = resultsBtn.Height;
menuSidePanel.Left = resultsBtn.Left;
}



private void exitBtn_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void previewBtn_Click(object sender, EventArgs e)
{

this.panelContainer.Controls["previewTab"].BringToFront();


}

private void resultsBtn_Click(object sender, EventArgs e)
{
resultsTab rsltTab = new resultsTab();
rsltTab.rsltTabPicture.Image = rtab.rsltTabPicture.Image;
this.panelContainer.Controls["resultsTab"].BringToFront();
}

private void headerPanel_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;
lastPosition = e.Location;
}

private void headerPanel_MouseUp(object sender, MouseEventArgs e)
{
mouseDown = false;
this.Opacity = 1;
}

private void headerPanel_MouseMove(object sender, MouseEventArgs e)
{
if (mouseDown)
{
this.Location = new Point((this.Location.X - lastPosition.X) + e.X,(this.Location.Y - lastPosition.Y) + e.Y);
this.Opacity = 0.4;
this.Update();
}

}
}
}

// this is usercontrol1 code



namespace FrmDrag
{
public partial class previewTab : UserControl
{

public PictureBox prvTabPicture // property
{
get { return previewTabPictureBox; } // get method
set { previewTabPictureBox = value; } // set method
}
resultsTab rsltTb = new resultsTab();
public previewTab()
{
InitializeComponent();
}

private void countBtn_Click(object sender, EventArgs e)
{
if (!Form1.Instance.PnlContainer.Controls.ContainsKey("resultsTab"))
{

rsltTb.Dock = DockStyle.Fill;
Form1.Instance.PnlContainer.Controls.Add(rsltTb);
}

rsltTb.rsltTabPicture.Image = previewTabPictureBox.Image;
Form1.Instance.PnlContainer.Controls["resultsTab"].BringToFront();


}



private void snapBtn_MouseMove(object sender, MouseEventArgs e)
{
menuSidePanel1.Height = snapBtn.Height;
menuSidePanel1.Top = snapBtn.Top;
}

private void countBtn_MouseMove(object sender, MouseEventArgs e)
{
menuSidePanel1.Height = countBtn.Height;
menuSidePanel1.Top = countBtn.Top;
}

private void previewTabStartBtn_MouseMove(object sender, MouseEventArgs e)
{
menuSidePanel1.Height = previewTabStartBtn.Height;
menuSidePanel1.Top = previewTabStartBtn.Top;
}

private void brightnessSlider_ValueChanged(object sender, EventArgs e)
{
label2.Text = "Brightness="+brightnessSlider.Value;
}

}
}

// and this is usercontrol2 code

namespace FrmDrag
{
public partial class resultsTab : UserControl
{


public PictureBox rsltTabPicture // property
{
get { return resultTabPcitureBox; } // get method
set { resultTabPcitureBox = value; } // set method
}
public string labelText // property
{
get { return label1.Text; } // get method
set { label1.Text = value; } // set method
}
public resultsTab()
{
InitializeComponent();

}


}
}






Thank you for your advice,

Continue reading...
 
Back
Top