User Control and Window form
-
Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help
-
Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help
-
Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help
I think the simplest way is: 1- add a usercontrol to your project 2- add a button, named in Button1 to your usercontrol, set Button1 "Modifiers" property to Public. 3- build your project. 4- after adding your user control, named in UserControl1 to your form, add this lines of code: ------------------- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler UserControl1.Button1.Click, AddressOf Button_Click End Sub Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'do your task here End Sub ------------------- 5- what you wanted is done
-
I think the simplest way is: 1- add a usercontrol to your project 2- add a button, named in Button1 to your usercontrol, set Button1 "Modifiers" property to Public. 3- build your project. 4- after adding your user control, named in UserControl1 to your form, add this lines of code: ------------------- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler UserControl1.Button1.Click, AddressOf Button_Click End Sub Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'do your task here End Sub ------------------- 5- what you wanted is done
Unknown C# dialect.
Luc Pattyn
-
Hi, I have a user control in a window form. In user control i have a button. On click over this button i want to change the window form label text. How i can do it ? I am new to c#. please help
Hello, Here some code for the suggestions from "V". UserControl code:
public event EventHandler ButtonClickChanged;
protected virtual void OnButtonClickChanged(System.EventArgs e)
{
if (ButtonClickChanged != null)
{
ButtonClickChanged(this, e);
}
}private void button1_Click(object sender, System.EventArgs e)
{
OnButtonClickChanged(System.EventArgs.Empty);
}Forms code:
public Form1()
{
InitializeComponent();userControl11.ButtonClickChanged+=new EventHandler(userControl11\_ButtonClickChanged);
}
private void userControl11_ButtonClickChanged(object sender, EventArgs e)
{
//youre code
}Hope that helps! All the best, Martin
-
Unknown C# dialect.
Luc Pattyn
add these line of code to your form: private void Button_Click(object sender, System.EventArgs e) { // do your task here } then in your form load event add: UserControl1.Button1.Click += new System.EventHandler(this.Button_Click);
-
add these line of code to your form: private void Button_Click(object sender, System.EventArgs e) { // do your task here } then in your form load event add: UserControl1.Button1.Click += new System.EventHandler(this.Button_Click);
Sure. I think I understood the first time. My remark was it did not really look like C#, the subject of this message board. :)
Luc Pattyn