【问题标题】:How to get label value from Picturebox on Picturebox click event如何在Picturebox点击事件上从Picturebox获取标签值
【发布时间】:2020-04-26 18:36:46
【问题描述】:

当用户单击 flowLayoutPanel1 内的 PictureBox 时,我尝试了多种方法从 PictureBox 读取标签值。 enter image description here 任何人都可以帮助我。

从附图中,我想在用户点击“图片框点击事件”时读取价格值。

pic.Click += new EventHandler(picture_click);
void picture_click(object sender, EventArgs e) {
    if (pic != null) {
        pic.BorderStyle = BorderStyle.None;
        pic = (PictureBox)sender;
        pic.BorderStyle = BorderStyle.Fixed3D;
    }
}

【问题讨论】:

  • 我们可以看看你的代码吗?什么语言?我假设一些 dot net one
  • 我没有正确的代码,我像 pic.Click += new EventHandler(picture_click);无效图片点击(对象发送者,EventArgs e){如果(图片!=空){pic.BorderStyle = BorderStyle.None; pic =(图片框)发件人; pic.BorderStyle = BorderStyle.Fixed3D; } }
  • Winform 的 C#
  • 看附图,你就会知道我的实际需求是什么。
  • 文字是图片框的一部分还是单独的标签?

标签: c# winforms picturebox flowlayoutpanel


【解决方案1】:
foreach (Control c in pic.Controls)
            {
                if (c.GetType().Name == "Label")
                {
                    if(pic.Controls.IndexOf(c).ToString() == "0")
                    {
                        _Prc = c.Text.Replace("Rs.", "");
                        _Prc = _Prc.Replace("/-", "");
                    }
                    else if (pic.Controls.IndexOf(c).ToString() == "1")
                    {
                        _Menu = c.Text;
                    } 
                }
            }

【讨论】:

    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 2015-04-22
    • 2017-03-20
    • 1970-01-01
    • 2016-12-22
    相关资源
    最近更新 更多