【问题标题】:c# Add transparent label on web eye web cam controlc#在web eye web cam控件上添加透明标签
【发布时间】:2017-07-27 13:52:24
【问题描述】:

我一直在制作钢铁侠的 hud。我正在使用 WebEye 访问网络摄像头...现在我必须在网络摄像头控件上添加标签,但标签不透明 每个控件我都试过了,但不能使用透明功能..

这是我的代码

 foreach (WebCameraId camera in webCameraControl1.GetVideoCaptureDevices())
        {
            comboBox1.Items.Add(new ComboBoxItem(camera));
        }

        if (comboBox1.Items.Count > 0)
        {
            comboBox1.SelectedItem = comboBox1.Items[0];
        }

        ComboBoxItem i = (ComboBoxItem)comboBox1.SelectedItem;

        try
        {
            webCameraControl1.StartCapture(i.Id);
        }
        finally
        {
            //Do something if u want to
        }

请帮忙!!

【问题讨论】:

  • 您的目标是什么:Winforms、WPF、ASP..? 始终正确标记您的问题!
  • Winforms 对透明度没有真正的支持。当您将标签的背景颜色设置为 Color.Transparent 时,它会使用其父控件的背景来模拟透明度。
  • 还有其他方法可以实现吗? @ZoharPeled
  • 可能。您可以创建自己的真正透明标签,但它确实有它的缺点。这个周末我会试着给你找一个例子。

标签: c# winforms transparency webcam


【解决方案1】:

实际上,创建透明标签对视频没有帮助。如果您的 webCameraControl 不是密封类,您可以继承它以直接在其表面添加文本,就像我对这个图片框所做的那样:

public partial class LabledPictureBox : PictureBox
{
    public LabledPictureBox()
    {
        InitializeComponent();
    }

    #region properties

    // I needed to override these properties to make them Browsable....

    [Browsable(true)]
    public override string Text
    {
        get
        {
            return base.Text;
        }

        set
        {
            base.Text = value;
        }
    }

    [Browsable(true)]
    public override Font Font
    {
        get
        {
            return base.Font;
        }

        set
        {
            base.Font = value;
        }
    }

    [Browsable(true)]
    public override Color ForeColor
    {
        get
        {
            return base.ForeColor;
        }

        set
        {
            base.ForeColor = value;
        }
    }

    #endregion properties

    protected override void OnPaint(PaintEventArgs pe)
    {
        base.OnPaint(pe);

        // This is actually the only code line that's needed to add the text to the picture box
        TextRenderer.DrawText(pe.Graphics, this.Text, this.Font, pe.ClipRectangle, this.ForeColor);
    }
}

这里最重要的是base.OnPaint 之后的那一行——该行实际上直接在已绘制控件的表面上绘制文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多