buon girno tento di boxare un custom control cosi come si fa per gli altri oggetti nativi ma va in errore
(Unable to cast object of type 'System.Windows.Forms.Button' to type 'prova_custom_control.controllo_nuovo'.)
non so il perche´
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 prova_custom_control
{
public partial class controllo_nuovo : UserControl
{
public controllo_nuovo()
{
InitializeComponent();
}
private void controllo_nuovo_Load(object sender, EventArgs e)
{
}
}
}
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 prova_custom_control
{
public partial class Form1 : Form
{
controllo_nuovo controllo = new controllo_nuovo();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Controls.Add(controllo);
controllo.button1 .Click += new EventHandler(this.controllo_Click);
}
public void controllo_Click(System.Object sender, EventArgs e) {
controllo_nuovo clickato = (controllo_nuovo)sender;
this.BackColor = Color.Red;
}
}
}

891x351
31Kb