我创建了一个继承自Windows.System.Forms.Controls的自定义控件.
这是我控制的代码:
public partial class MonthEventComponent : Control
{
private Color couleur;
private Label labelEvenement;
public MonthEventComponent(Color couleur_c, String labelEvenement_c )
{
InitializeComponent();
this.couleur = couleur_c;
this.labelEvenement.Text = labelEvenement_c;
this.labelEvenement.ForeColor = couleur;
this.labelEvenement.BackColor = Color.White;
this.labelEvenement.TextAlign = ContentAlignment.MiddleLeft;
this.labelEvenement.Dock = DockStyle.Fill;
this.Controls.Add(labelEvenement);
}
public MonthEventComponent()
{
InitializeComponent();
this.couleur = Color.Black;
this.labelEvenement = new Label();
this.labelEvenement.ForeColor = couleur;
this.labelEvenement.BackColor = Color.White;
this.labelEvenement.Text = "Evénement Initialiser";
this.labelEvenement.TextAlign = ContentAlignment.MiddleLeft;
this.labelEvenement.Dock = DockStyle.Fill;
this.Controls.Add(labelEvenement);
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
MessageBox.Show("Click");
}
}
我想在DataGridViewCell上插入此控件或多个此控件,但我不知道如何执行此操作.
提前感谢您的回答,
最好的祝福,
PS:我是法国人,我为任何语言错误道歉.
解决方法:
我会假设你使用Winforms?
Here是关于如何在Winforms DataGridViewCell中托管控件的MSDN教程.
从教程:
The DataGridView control provides
several column types, enabling your
users to enter and edit values in a
variety of ways. If these column types
do not meet your data-entry needs,
however, you can create your own
column types with cells that host
controls of your choosing. To do this,
you must define classes that derive
from DataGridViewColumn and
DataGridViewCell. You must also define
a class that derives from Control and
implements the
IDataGridViewEditingControl interface.