c#执行生命周期的组件
我在解决方案中创建了一个组件。我可以在表单上使用此组件。 我是这样做的:c#执行生命周期的组件,c#,components,lifecycle,C#,Components,Lifecycle,我在解决方案中创建了一个组件。我可以在表单上使用此组件。 我是这样做的: 我创建了一个类库,创建了我的组件 创建一个测试项目,并在我的soloution中添加引用,在测试项目中添加我的组件 我有一些代码来说明我的组件的功能。我为此编写了一个函数,但我不知道如何在我的组件中使用我的函数。我需要帮助。我想学习我的组件工作哪个项目?因此,我需要在将组件加载到表单后调用函数。因为我需要学习这个表格的项目名称。 这是我的组件 [System.ComponentModel.Description("This
[System.ComponentModel.Description("This component using for update an application")]
public class MyComponent : System.Windows.Forms.Control
{
protected static string userName;
protected static string userPassWord;
ButtonState state = ButtonState.Normal;
[System.ComponentModel.Description("UserName for DB Connection"),
System.ComponentModel.Category("UserPanel"),
System.ComponentModel.DefaultValue(null)]
public string UserName
{
get
{
return userName;
}
set
{
userName = value;
}
}
[System.ComponentModel.Description("Password for DB Connection"),
System.ComponentModel.Category("UserPanel"),
System.ComponentModel.DefaultValue(null)]
public string UserPassWord
{
get
{
return userPassWord;
}
set
{
userPassWord = value;
}
}
public MyComponent()
{
InitializeComponent();
}
private void InitializeComponent()
{
userName = "username";
userPassWord = "pass";
}
protected override void OnPaint(PaintEventArgs e)
{
Draw(e.Graphics);
base.OnPaint(e);
}
protected virtual void Draw(Graphics g)
{
DrawButton(g);
}
protected virtual void DrawButton(Graphics g)
{
Rectangle rcButton = new Rectangle(0, 0, this.Width, this.Height);
ControlPaint.DrawButton(g, rcButton, state );
}
public void MyFunction()
{
// What my components do.
string appname =System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
}
我试图用代码“System.Reflection.Assembly.GetExecutionGassembly().GetName().name”来学习项目名称,但它给了我“MyComponenet”。我想让它给我“测试项目”
现在我需要做什么?我想我需要一个这样的函数
protected override void afterComponenetsCreatedOnForm()
{
base.afterComponenetsCreatedOnForm();
MyFunction();
}
这对我来说非常重要,我希望有人能来帮助我,我用了“Application.ProductName;”而不是“System.Reflection.Assembly.getExecutionGassembly().GetName().Name;”但是现在它给了我“Microsoft®Visual Studio®2012”,但是如果我在任何形式的应用程序中使用这段代码,它会给我MyProjectName
Assembly.getExecutionGassembly().GetName().Name
始终提供当前运行此代码的程序集的名称。所以很可能你打错电话了。但由于我方不了解您真正想要实现的目标,因此必须从您方做一点解释,请接受您的回答@ManuelZelenka。我确实在我的数据库中嵌入了一些项目。我知道InitLayout,Update,Refresh函数的意思。但我需要学习如何才能找到我的组件以哪种形式运行?如果我的项目版本(运行我的组件网的项目版本)低于数据库项目版本,则我的组件将在数据库上更新。首先,我的组件需要知道它在哪里运行?我希望你能理解我。我为我的语言感到抱歉:(所以我需要了解组件生命周期的哪一部分我可以找到我的组件运行的地方(哪个项目?)?这意味着,我需要组件生命周期的一部分,就像在@ManuelZelenka表单上创建之后一样