我在Control中遇到了一段奇怪的代码。
if (ParentForm != null)
{
traceBlock.Log("ParentForm is null");
if (!ParentForm.IsHandleCreated)
{
ParentForm.HandleCreated += (sender, e) =>
{
var text = PhysDocContext.Document.GetHeader(PhysDocContext);
ParentForm.Text = text
假设我有一些这样的组件:
class SomeForm : Form
{
private Control example;
public void Stuff()
{
this.example = new ComboBox();
// ...
this.Controls.Add(example);
}
public void OtherStuff()
{
this.Controls.Remove(example);
}
}
谁负责调用示例控件上的Dispose?从this
我正在尝试编写一个窗体主题类库,以便以一种简单的方式为我将要处理的任何项目调整窗体布局。
这基本上是它应该是什么样子的一个想法:
从本质上讲,插件的工作原理如下:
// form class, which inherits the plugin class
class FormToTheme : ThemedForm
{
public FormToTheme()
{
// some code here
}
}
// plugin class itself
class ThemedForm: Form
{
public ThemedForm()
我正在做一个Winforms项目,它将有几个"lookup“风格的用户控件。这些控件可以嵌入到各种窗体中,但通常是独立的。我想设计一个Windows窗体,它可以承载一个通用的用户控件,并执行这些查找中常见的几个任务。我的大脑告诉我这样做,但这显然不起作用:
public partial class LookupHostForm<TUserControl> : Form where TUserControl : UserControl
有没有一种方法可以让我使用一个窗体来托管多个用户控件,而不需要窗体知道/关心用户控件是什么?
我创建了一个从另一个表单派生的表单,如下所示:
Public Class MyForm
' ...etc
End Class
Public Class MyDerivedForm
Inherits MyBaseForm
' ...etc
End Class
Public Class MyOtherDerivedForm
Inherits MyBaseForm
' ...etc
End Class
这非常有效,我可以使用窗体设计器将控件添加到派生窗体中。但我想在不干扰MyBaseForm或MyOtherDerivedForm的情
我已经在我的应用程序中创建了许多自定义用户控件。它们是使用Validates()方法验证自己内容的控件。当我单击窗体上的按钮时,我想在任何具有该方法的控件上调用该方法。实现这一目标的最佳方法是什么?
我能够识别和控件,并检查它们是否有方法,但不确定在这一点如何调用它。(所有控件都以‘cc’开头)
foreach (Control c in this.Controls)
{
if (c.Name.Length > 2 && c.Name.Substring(0, 2).Equals("cc"))
我重写了OnPaint方法,以便在屏幕上绘制椭圆。
protected override void OnPaint(PaintEventArgs e)
{
MessageBox.Show("Paint");
if (debugStarted)
{
int y = rtbLogicCode.PlaceToPoint(new Place(0, debugLine)).Y;
if (rtbLogicCode.GetVisibleState(debugLine).ToStri
我有一个包含以下代码的基本表单:
Sub New()
InitializeComponent()
Me.InitRibbonPageGroups()
End Sub
Sub InitRibbonPageGroups()
Dim Ribbon As RibbonControl = Nothing
For Each c As Object In Me.Controls
If Not TryCast(c, WCLib.ClsCompMyRibbonControl) Is Nothing Then
Ribbon = c
我有一个WinForms应用程序,例如,它有两种不同类型的对象和一种常见的表单。
Public Class A:
{
private MyForm formA = new MyForm();
public void ShowForm()
{
formA.ShowDialog();
}
}
Public Class B:
{
private MyForm formB = new MyForm();
public void ShowForm()
{
formB.ShowDialog();
}
}
Public clas