如何重设comboBox和更改图像 [英] How to reset comboBox and change the images

查看:64
本文介绍了如何重设comboBox和更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c#在Window Application Form中进行房屋目录搜索.
有"3 comboBox"和一个搜索按钮".更改新的3个comboBox选择后,可以查看完整图像的PictureBox下面的图像缩略图不会更改或更新.如何重置comboBox和图片?

ComboBox1(故事选择):
1,2,3,4

ComboBox2(费用选择):
500,001-1,000,000/1,000,001-3,000,000
3,000,001-6,000,000
6,000,001-10,000,000
10,000,001起

ComboBox3(样式):
泰国
现代
小镇之家
__________________________________________________________________________

I''m trying to do a house catalog search in Window Application Form by c#.
There are " 3 comboBox " and a "search button ". After changing the new selection of 3 comboBox the image thumbnails below the PictureBox which it can be view a full image doesn''t change or update. How can I reset the comboBox , and Pictures?

ComboBox1 ( Stories Select ) :
1,2,3,4

ComboBox2 (Cost Select ) :
500,001-1,000,000 /1,000,001-3,000,000
3,000,001 - 6,000,000
6,000,001 - 10,000,000
10,000,001- up

ComboBox3 (Style ) :
THAI
MODERN
TOWNHOME
__________________________________________________________________________

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace HOUSE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {

            if (comboBox1.SelectedIndex == 0 && comboBox2.SelectedIndex == 0 && comboBox3.SelectedIndex == 1)
           
            {

                string[] piclist = { "R1-1.jpg", "R1-1plan.jpg", "R1-2.jpg", "R1-2plan.jpg", "R1-3.jpg", "R1-3plan.jpg" };
                int startlocation = 5;
                for (int i = 0; i < 6; i++)
                {

                    PictureBox px = new PictureBox();
                    px.Click += new System.EventHandler(picture_click);
                    px.Size = new Size(80, 80);
                    px.SizeMode = PictureBoxSizeMode.StretchImage;
                    px.Location = new Point(startlocation, 5);
                    px.ImageLocation = "c:\\" + piclist[i];
                    this.panel1.Controls.Add(px);
                    startlocation = startlocation + 5 + 80;

                }
               


            }
            
                if (comboBox1.SelectedIndex == 0 && comboBox2.SelectedIndex == 1 && comboBox3.SelectedIndex == 1)

                {


                    string[] piclist = { "M1-1.jpg", "M1-1plan.jpg", "M1-2.jpg", "M1-2plan.jpg", "M1-3.jpg", "M1-3plan.jpg", 
                                              "M1-4.jpg", "M1-4plan.jpg", "M1-5.jpg", "M1-5plan.jpg" };
                    int startlocation = 5;
                    for (int i = 0; i < 10; i++)
                    {

                        PictureBox px = new PictureBox();
                        px.Click += new System.EventHandler(picture_click);
                        px.Size = new Size(80, 80);
                        px.SizeMode = PictureBoxSizeMode.StretchImage;
                        px.Location = new Point(startlocation, 5);
                        px.ImageLocation = "c:\\" + piclist[i];
                        this.panel1.Controls.Add(px);
                        startlocation = startlocation + 5 + 80;

                    }



                }
            
        }
            private void picture_click(object sender, EventArgs e)

            {
            PictureBox px = (PictureBox)sender;
            pictureBox1.ImageLocation = (px.ImageLocation);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            
            }

            private void btnZoomIn_Click(object sender, EventArgs e)
            {
                double ZOOMFACTOR = 1.25;   // = 25% smaller or larger
                int MINMAX = 5;
                if ((pictureBox1.Width < (MINMAX * pictureBox1.Width)) &&

                   (pictureBox1.Height < (MINMAX * pictureBox1.Height)))
                {

                    pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * ZOOMFACTOR);

                    pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * ZOOMFACTOR);

                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

                }
            }

            private void btnZoomOut_Click(object sender, EventArgs e)
            {
                double ZOOMFACTOR = 1.25;
                int MINMAX = 5;
                if ((pictureBox1.Width > (pictureBox1.Width / MINMAX)) &&
                    (pictureBox1.Height > (pictureBox1.Height / MINMAX)))
                {
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Width = Convert.ToInt32(pictureBox1.Width / ZOOMFACTOR);
                    pictureBox1.Height = Convert.ToInt32(pictureBox1.Height / ZOOMFACTOR);
                }
            }

            private void btnReset_Click(object sender, EventArgs e)
            {
                comboBox1.DataSource = null;
                comboBox2.DataSource = null;
                comboBox3.DataSource = null;
                //comboBox1.Refresh();
                //comboBox2.Refresh();
                //comboBox3.Refresh();
                //pictureBox1.Image = null;

                //this.panel1.Visible = false;
                ////pictureBox1.Visible=false;
            }



        }

    }

推荐答案

尝试一下

combobox1.selectedIndex = 0;

pictireBox.Visible = false;



谢谢,
Try this

combobox1.selectedIndex = 0;

pictireBox.Visible = false;



Thanx,


这篇关于如何重设comboBox和更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆