问题描述
嗨
我想知道如何在flowlayoutpanel中添加束带.我使用下面的代码在矩形中绘制了一个字符串.
I want to know how to add drawstring to flowlayoutpanel . I have drawn a string in a rectangle using below code.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle rect = new Rectangle(10,100,100,100);
e.Graphics.DrawString("hello",this.Font, Brushes.Blue, rect);
}
现在,如何将绘制的字符串添加到flowlayoutpanel?
Now, how to add this drawn string to flowlayoutpanel?
推荐答案
如果它是标准的FlowLayoutPanel,则应处理Paint事件,例如:(将FlowLayoutPanel放入Windows窗体)
if its a standard FlowLayoutPanel, hten handle the Paint event like: (put a FlowLayoutPanel to a Windows Form)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.flowLayoutPanel1.Paint += flowLayoutPanel1_Paint;
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(10, 100, 100, 100);
e.Graphics.DrawString("hello", this.Font, Brushes.Blue, rect);
}
}
else从FlowLayoutPanel派生,并像上面一样使用OnPaint覆盖.喜欢:
else derive from FlowLayoutPanel and use the OnPaint override like you did above. Like:
public class MyFlowPanel:FlowLayoutPanel
{
public MyFlowPanel()
{
this.BackColor = Color.Cyan;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle rect = new Rectangle(10, 100, 100, 100);
e.Graphics.DrawString("hello", this.Font, Brushes.Blue, rect);
}
}
从设计器工具箱"的新顶部条目中构建并将其拖到表单"中.
Build and drag this to a Form from the Designer Toolbox new top entry.
此致
托尔斯滕
这篇关于如何将绘制字符串添加到flowlayoutpanel-C#Visual Studio-WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!