comboBox有问题 [英] having problem with comboBox

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

问题描述

嗨 我有一张地图,我想如果用户从comboBox中选择一个项目,该城市将被显示.
我的问题是,当我加载程序并选择一个项(从comboBox中)时,显示了地图的point(0,0),但这只是第一次,之后便可以正常工作了.
有什么问题吗?

Hi I have a map and I want if the user selects an item from comboBox that city will be shown.
my problem is when I load the program and select an item(from comboBox), point(0,0) of the map is shown but it is just for the first time and after that it is work correctly.
what is the problem?

 private void button2_Click(object sender, EventArgs e)
        {
            Zoomin.Enabled = false;
            Zoomout.Enabled = true;
            panel2.AutoScrollPosition = new System.Drawing.Point(0, 0);
 pictureBox2.Location = new Point(0, 0);
                Point panelcenter = new Point((this.panel2.Width / 2), (this.panel2.Height / 2)); // find the centerpoint of the panel
                Point offsetinpicturebox = new Point((this.pictureBox2.Location.X + city_x[comboBox1.SelectedIndex]), (this.pictureBox2.Location.Y + city_y[comboBox1.SelectedIndex])); // find the offset of the mouse click
                Point offsetfromcenter = new Point((panelcenter.X - offsetinpicturebox.X), (panelcenter.Y - offsetinpicturebox.Y)); // find the difference between the mouse click and the center
                this.panel2.AutoScrollPosition = new Point(
                    (Math.Abs(this.panel2.AutoScrollPosition.X) + (-1 * offsetfromcenter.X)),
                    (Math.Abs(this.panel2.AutoScrollPosition.Y) + (-1 * offsetfromcenter.Y))
                );
                pictureBox2.Image = WindowsFormsApplication1.Properties.Resources.Iran_Way_Map;
                pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;
                pictureBox2.Width = 3779;
                pictureBox2.Height = 2884;
                Graphics g = Graphics.FromImage(pictureBox2.Image);
                Pen p = new Pen(Color.Black, 5);
                g.DrawEllipse(p,city_x[comboBox1.SelectedIndex]-14 , city_y[comboBox1.SelectedIndex]-14 , 30, 30);
                pictureBox2.Invalidate();
}



这是我的代码,但是第一次选择城市并不能正常工作.



It is my code but it doesnt work just for the first time that I select a city.

推荐答案

我认为这与未初始化蜂鸣器的图片框有关第一个按钮单击.每次在方法末尾初始化城市的大小时,但是第一次选择城市时,这还没有完成,因此可能会失败.
I think it has something to do with the picturebox not beeing initialized on the first button click. Each time you initialize the size of it at the end of your method but the first time you select a city this isn''t done yet and therefor probably fails.
pictureBox2.Width = 3779;
pictureBox2.Height = 2884;



尝试更早地对其进行初始化,例如以Shown形式的事件.

祝你好运!



Try to initialize it earlier, like in the form Shown event for example.

Good luck!


这篇关于comboBox有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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