Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Actually I created user control and successfully added with tools option but when this control use in another form. So write some code then
below code are fired
XML
private void userControl11_Load(object sender, EventArgs e)
        {
            label1.Text = "UserControl loaded";
            // Button1
            //
            this.Button1.Location = new System.Drawing.Point(0, 0);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(75, 23);
            this.Button1.TabIndex = 0;
            <b>this.Button1.Click += new System.EventHandler(this.Button1_Click);
</b>            //


but
C#
public void Button1_Click(object sender, EventArgs e)
       {

           label1.Text = "Clicked by buttto1";
       }



when using next code is not fire why >
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 test_CreatePannel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Windows.Forms.Button Button1;
private System.Windows.Forms.Button Button2;
private System.Windows.Forms.Button Button3;
private void userControl11_Load(object sender, EventArgs e)
{
label1.Text = "UserControl loaded";
// Button1
//
this.Button1.Location = new System.Drawing.Point(0, 0);
this.Button1.Name = "Button1";
this.Button1.Size = new System.Drawing.Size(75, 23);
this.Button1.TabIndex = 0;
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
}

public void Button1_Click(object sender, EventArgs e)
{

label1.Text = "Clicked by buttto1";
}

private void btnAdd_Click(object sender, EventArgs e)
{
label1.Text = "Clicked by buttton Add";

}

}
}
Posted
Comments
BillWoodruff 24-Mar-14 15:29pm    
Is the Label in the Form, or the UserControl ?
Ramkrishn Mishra 25-Mar-14 2:19am    
UserControl have contain one button as alias button1 and one more button as alias btnAdd,Label have contain by form when click to btnadd then printed label1.text ="Click to BtnAdd" and when click to button1 then button1 not fired. I have write code . Can You advice how did completed this task.

Actually I want to create Collection of Terminal which display that connect or not and responsible for connect or disconnect.
http://img.brothersoft.com/screenshots/softimage/m/mc3_-_mouse_click_cyber_cafe_software-271987-1268103759.jpeg
gggustafson 25-Mar-14 16:26pm    
In your user control, did you supply a delegate/event pair that would pass to their subscribers the fact that the button was clicked?
Ramkrishn Mishra 26-Mar-14 2:22am    
Actually I am trying understanding to delegate and event concept but not understand that how to do code ?
I am Created UserControl explicitly have code below :-
namespace test_CreateUserControl
{

public partial class UserControl1 : UserControl
{
// public event EventHandler StatusChanged;
public event EventHandler InnerButtonClick;
public UserControl1()
{
InitializeComponent();
InnerButton.Click +=new EventHandler(InnerButton_Click);
}
private void InnerButton_Click(Object sender, EventArgs e)
{
if (InnerButtonClick != null)
{
InnerButtonClick(InnerButton, e);

}
}
/* protected virtual void OnStatusChanged(EventArgs e)
{
EventHandler eh = StatusChanged;
if (eh != null)
{
eh(this, e);
}
}

private void Button1_Click(object sender, EventArgs e)
{
OnStatusChanged(new EventArgs());
}*/
}
}

Then successfully usercontrol added with tool then code again in Form1

namespace test_CreatePannel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Windows.Forms.Button Button1;
private System.Windows.Forms.Button Button2;
private System.Windows.Forms.Button Button3;
private void userControl11_Load(object sender, EventArgs e)
{
label1.Text = "UserControl loaded";
}

private void InnerButton(object sender, EventArgs e)
{
label1.Text = "This is Clicked by inner Button";
}

private void btnAdd_Click_1(object sender, EventArgs e)
{
label1.Text = "This is Clicked by buttton Add";
}

}
}

Plz advice where write the code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900