【问题标题】:Getting buttonbackground image from dynamically added button从动态添加的按钮获取按钮背景图像
【发布时间】:2012-02-03 18:48:41
【问题描述】:

我正在根据我的应用程序资源中的图像数量使用按钮填充表单。

我正在循环浏览资源中的图片,foreach图片创建一个按钮,然后将背景图片设置为图片。

现在我需要获取我单击的按钮的图像并将其传递给方法。我如何做到这一点?

提前致谢。

我的代码如下:

  ResourceSet resourceSet = Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
        foreach (DictionaryEntry entry in resourceSet)
        {
            object resource = entry.Value;
            Button b = new Button();
            b.BackgroundImage = (Image)resource;
            b.BackgroundImageLayout = ImageLayout.Stretch;
            b.Bounds = new Rectangle(left, top, buttonSize, buttonSize);
            this.Controls.Add(b);
            left += buttonSize;
            if (left + buttonSize > this.ClientSize.Width)
            {
                left = 0;
                top += 100;
            }
            b.Click += new EventHandler(buttonClick);
        }

【问题讨论】:

    标签: c# button


    【解决方案1】:

    你的意思是这样的

    protected void buttonClick(object sender, EventArgs args)
    {
         Button myButton = (Button)sender;
         ImageProcessMethod(myButton.BackgroundImage);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      • 2014-07-06
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多