【问题标题】:Unloading image from picturebox if string matches如果字符串匹配,则从图片框中卸载图像
【发布时间】:2012-06-26 15:07:45
【问题描述】:

我有两个列表框,允许用户将项目从第一个列表框转移到第二个列表框

当用户单击按钮时,它会比较所选项目,如果匹配特定字符串,则将图像加载到图片框中。

我做了一个函数,删除添加到第二个列表框的当前项目, 但我想以某种方式阅读选择并删除了哪个项目。 我想我可以放一些像

if(listBox2.Items.RemoveAt(listBox2.SelectedIndex="String") { picturebox.Image=null; }

示例代码

   private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.RemoveAt(listBox2.SelectedIndex); 
    }

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    不清楚您要做什么。
    但是,如果您想根据在列表框中选择的项目从图片框中删除图像,也许这会有所帮助:

    private void button2_Click(object sender, EventArgs e)     
    {    
         if(listbox2.SelectedIndex >= 0)
         {
             string curItem = listBox2.Items[listbox2.SelectedIndex].ToString();
             if(curItem == "SomeOtherString")
             {
                 listBox2.Items.RemoveAt(listBox2.SelectedIndex);      
                 picturebox.Image.Dispose();
                 picturebox.Image = null; // Not really necessary
             }
         }
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多