本文介绍了面板中的C#绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用这种方法绘制面板:
I want to draw in a panel with this method:
protected override void InitOutput(object output)
{
if (output is Control)
{
Control c = (Control)output;
g.FillRectangle(hb, 7, 10, 30 - 19, 5);
...
}
我可以输入文字:
protected override void InitOutput(object output)
{
if (output is Control)
{
Control c = (Control)output;
lbl.Name = "lbl";
lbl.Size = new System.Drawing.Size(10, 10);
lbl.TabIndex = 5;
lbl.Text = "test";
panel.Location = new System.Drawing.Point(1, 1);
panel.Name = "panelSys";
panel.Size = new System.Drawing.Size(20, 20);
panel.TabIndex = 5;
panel.Controls.Add(lbl);
c.Controls.Add(panelSys);
}
希望你能帮助我谢谢
推荐答案
我不确定为什么需要InitOtuput函数,但是如果要从中进行绘制,您可以这样做:
I am not sure why do you need InitOtuput function but if you want to draw from it you could do it like this:
private void InitOutput(object output)
{
if (output is Control)
{
Control c = (Control)output;
c.Paint += new System.Windows.Forms.PaintEventHandler(c_Paint);
// Invalidate needed to rise paint event
c.Invalidate();
}
}
private void c_Paint(object sender, PaintEventArgs e)
{
SolidBrush hb = new SolidBrush(Color.Red);
e.Graphics.FillRectangle(hb, 7, 10, 30 - 19, 5);
e.Graphics.DrawString("test", DefaultFont, hb, new PointF(50, 50));
}
此外,您不需要使用标签来绘制文本,您可以使用Graphics.DrawSting来绘制它
Additionaly you don't need to use label to draw text u can draw it using Graphics.DrawSting
这篇关于面板中的C#绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!