【发布时间】:2016-05-07 13:24:59
【问题描述】:
当我稍后将此 UserControl 拖动到我的 form1 设计器时,我希望能够键入例如 PaintDrawingControl1。在具有所有属性的点之后,属性字体和文本不是已经存在的,但是我需要在代码中而不是字体和 label1.Text 以便用户可以输入任何文本到绘图字符串和任何类型的字体。 我的意思是在这一行:PaintDrawingControl.font =.... 或 PaintDrawingControl.text = "draw this text"
整个想法是制作一个 UserControl 来在它上面拉绳,这样它就不会闪烁。如果我在 form1 绘制事件中拉绳,则使用计时器时文本会闪烁。
e.Graphics.DrawString(label1.Text,
font, Brushes.Black, 10, 10);
替换 label1.Text 并将变量字体替换为全局字体,以便用户可以在 form1 设计器中拖动控件后将其设置为。 因此,在 form1 代码中,我将能够执行以下操作:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DateCounter
{
public partial class PaintDrawingControl : UserControl
{
public PaintDrawingControl()
{
InitializeComponent();
}
private void PaintDrawingControl_Load(object sender, EventArgs e)
{
}
private void PaintDrawingControl_Paint(object sender, PaintEventArgs e)
{
if (DesignMode) return;
e.Graphics.DrawString(label1.Text,
font, Brushes.Black, 10, 10);
}
}
}
【问题讨论】:
-
好的,我找到了方法。现在正是我想要的,但它正在工作。现在将用我到目前为止所做的事情更新我的问题。
-
请从问题中删除答案部分并将其作为答案发布。这样,问题将更具可读性,答案将对未来的读者更有用。