从此站点将值从组合框发送到应用程序中的numericUpDown [英] Send value from Combobox to numericUpDown in application from this site

查看:57
本文介绍了从此站点将值从组合框发送到应用程序中的numericUpDown的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,大家好!

我正在开发用于调整图片大小的应用程序...
当我可以向列表中添加一些图片时,我正在修改某个应用程序,并且可以为所有图片中的每张图片设置在numericUpDown中,例如1024x768 ...带有图片的列表也是如此-每张图片都有自己的两个numericUpDown控件,用于显示宽度和高...

我对其进行了重建,并使此numericUpDown可见为False.然后将其从两个numericUpDown更改为两个组合框,其中第一个组合800 1024和1280中的项目以及第二个组合600 768和1024中的items属性.
所以我有这段代码可以从组合框向我的numericupdown发送数字


Hi there all good people !

I am developing application to resize pictures...
I am modify some application when i can add some pictures to list and for the each of all the pictures i can set in numericUpDown a size like 1024x768 ... So is the list with pictures - each one picture has own two numericUpDown controls for width and heigh ...

I rebuild it and make visible of this numericUpDown to False.. And change it from two numericUpDown to two combobox with item in first combo 800 1024 and 1280 and second combo 600 768 and 1024 in items property..

So i have this code to send numbers to my numericupdown from comboboxes


public void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            try
            {
                if ((string)comboBox1.SelectedItem == "male")
                {
                    numericUpDown_SizeX.Value = Convert.ToInt32(800);
                    numericUpDown_SizeY.Value = Convert.ToInt32(600);
                }
                else if ((string)comboBox1.SelectedItem == "srednie")
                {
                    numericUpDown_SizeX.Value = Convert.ToInt32(1024);
                    numericUpDown_SizeY.Value = Convert.ToInt32(768);
                }
                else if ((string)comboBox1.SelectedItem == "duze")
                {
                    numericUpDown_SizeX.Value = Convert.ToInt32(1280);
                    numericUpDown_SizeY.Value = Convert.ToInt32(1024);
                }
            }
            catch
            {
                MessageBox.Show("Tego zdjęcia nie da się skonwertować do tej rozdzielczości!");
            }


而且工作正常...

而且我可以选择任何添加的图片来控制尺寸..好的

但知道我尝试创建1个组合框来设置所有图片的宽度和高度...我认为这很容易,所以我添加了1x组合框来做...而我却出错了...

也许问题是我需要什么代码才能将窗体上的所有numericUpDown控件更改为某个值,然后将其从combobox放入NumericUpDown ...

为了清楚起见,我修改了此应用程序.
我的问题的最佳答案将是如何为组合框中列表中所有选择的图片设置所有numericUpDown的值...

我正在谈论的这个应用程序来自以下站点的链接:
批处理图像 [


and it''s work fine...

and i can choose for any added picture in wons controls the size.. ok

but know i try to create 1 combobox to set the valus width and height for all pictures... I thought it will be easy so i add 1x combobox to do it... and i have errors...

Maybe the question is what code i need to change all numericUpDown controls on form on some value and put it in thi NumericUpDown from combobox...

For clear i modify this application.
The best answer on my question will be how to set the value for all numericUpDown''s for all choosed pictures on list from combobox...

This application what i am talking about it''s from this site from link:
Batch Image[^]

Please help me

best regards,
nighttrain

推荐答案

Robert,

您要求我查看您的代码.不幸的是,我无能为力.您在使用非常基本的内容时遇到了很多问题,并且还没有做好充分准备的工作-到目前为止.

我给你一些笔记.首先,您包含不是源代码的文件这一事实告诉我您可能不确定文件的哪一部分是您的源代码.如果是这样,则不能真正保留代码.请记住,您应该使用版本控制来确保安全和高效.你的名字很差.它不符合Microsoft命名规则.实际上,自动生成的代码中的所有名称(如"Form1")都应重命名,并使用敏感名称,不能使用下划线.不要告诉我这无关紧要:这就是可支持性.您显然没有考虑可支持性.您的代码填充了您永远不应该使用的立即字符串常量.即使"是不可接受的,也应使用string.Empty.另外,我认为您没有听取好的建议.人们指出,"Convert.ToInt32(800)"纯粹是胡说八道,但仍在您的代码中.

好的,我会花时间,向您提供一些建议,但是如果您不听这些建议的话,为什么我会对这样的挫败感感兴趣?

接下来,在"UDirTree.cs"中查看竞争对象"C:"和"C:\\".这只是犯罪:硬编码目录.在任何情况下它都不会有用.用户使用的任何文件都可以在任何地方;一台计算机可能根本没有这样的磁盘.

我终于意识到,您不知道在查看CImage.cs时在做什么(为什么文件名中的所有那些"C"?文件也应该命名得很好……).什么是开关(索引)情况0,情况1 ..?这是无稽之谈!如果您添加/删除/重新排序列表项怎么办?一切都会崩溃.有一个属性SelectedObject.无需任何情况,只需将所选对象转换为项目的运行时类型,然后以人类可读的名称在UI中显示该项目,即可使用覆盖的ToString生成类型.我对这个问题的回答中描述了该技术:
显示图像从列表框中 [ ^ ].

底层类型是枚举.您可以使用以下内容以易于阅读的方式显示它们:人类可读的枚举元数据 [ ^ ].

通常,您需要摆脱所有这些立即常数.这对于字符串尤其重要.用英语以外的其他语言开发UI很有问题.这是一个好主意,以全球化的方式开发英语的所有内容,然后将其本地化.

我认为这足够了.您确实需要处理更简单的任务,但要理解所写的每一行.

谢谢.
--- SA
Robert,

You asked me to look at your code. Unfortunately, I cannot do much to help you. You have so many problems with very basic stuff and trying to the work you''re not quite prepared for — just yet.

I''ll give you few notes. First, the fact you include files which are not your source code tells me you''re may be not sure what part of files is your source code. If this is true, you cannot really preserve your code. Remember, you should work with Revision Control to be safe and productive. Your naming is very poor; it does not compliant with Microsoft naming rules. Practically, all names from auto-generated code (like "Form1") should be renamed, given sensitive names, no underscore. Don''t tell me this is insignificant: this is supportability. You apparently don''t think about supportability. You code is fill of immediate string constants which you never should use. Even "" is unacceptable, you should use string.Empty. Also, I don''t think you listen for good advice. People pointed out, "Convert.ToInt32(800)" is pure nonsense, but it''s still in your code.

OK, I''ll spend my time, will give you a number of advices, but if you don''t listen to them… Why would I be interested is such frustration?

Next, look at your contants "C:", and "C:\\" in "UDirTree.cs". This is simply a crime: hard-coded directory. There is no situation when it can be useful. Any files your user is working with can be anywhere; a computer may not have such disk at all.

I finally realized that you do not understand what are your doing looking at CImage.cs (why all those "C" in file names? Files should also be named nicely…). What is that switch(indice) case 0, case 1..? This is nonsense! What if you add/remove/reorder list items? Everything will get broken. There is a property SelectedObject. No case needed, you simply cast your selected object to your run-time type of your item, and to present the item in UI in human-readable name make a type with overridden ToString. The technique is described in my answer to this question: Displaying an image from a list box[^].

The underlying type is enumeration. You can present them in human-readable way using this: Human-readable Enumeration Meta-data[^].

You generally need to get rid of all those immediate constants. This is especially important for strings. Developing UI in the language other than English is very problematic. This is really good idea to develop everything in English in globalized manner and then localize it.

I think this is enough. You really need to work at more simple tasks but understanding every single line you write.

Thank you.
---SA


这都是 duze 冗长的词.为什么要将任何数据以立即常量的形式硬编码在代码上呢?更糟糕的是,当它们真正属于字符串资源时,编写立即字符串常量的方式.样式和可支持性很差.

更重要的是,即使您想要由ComboBox控制的大小,也根本不需要case块.您需要的是ComboBox的数据类/结构,该类具有双重作用:包含大小数据并以一些人类可读的字符串形式显示在屏幕上.您只需要覆盖object.ToString():

This is all duze wordy. Why having so any data hard-coded in the form of immediate constants dispersed over the code? Even worse is the manner to write immediate string constants when they really belong to string resources. The style and supportability is very bad.

More to the point, even if you want to the size controlled by ComboBox, you don''t need a case block at all. What you need is the data class/structure for your ComboBox which play the dual role: contain the size data and show up on the screen as some human-readable string. All you need is to override object.ToString():

internal struct ListItemHelper {
    internal ListItemHelper(System.Drawing.Size size) { Size = size; }
    public override string ToString() {
        return string.Format("{0}x{1}", Size.Width, Size.Height);
    } //ToString
    internal System.Drawing.Size Size;
} //ListItemHelper



要使用它,您现在可以使用Size而不是字符串



To use it, you can work now with Size, not with strings

ComboBox cb = new ComboBox();

//...

//This is how to populate items:
cb.Items.Add(new ListItemHelper(new Size(800, 600)));
//...

//This is how to extract size from selected item:
Size size = ((ListItemHelper)cb.SelectedItem).Size;
//...

//Here is how to use it in your event:
cb.SelectedValueChanged += delegate(
    object sender, System.EventArgs eventArgs) {
        Size size = ((ListItemHelper)cb.SelectedItem).Size;
        //use size the way you want
} //cb.SelectedValueChanged

//chances are, you C# is of the version 3 or later,
//then the code could be simpler using lambda form:
cb.SelectedValueChanged += (sender, eventArgs) => {
    Size size = ((ListItemHelper)cb.SelectedItem).Size;
    //use size the way you want
} //cb.SelectedValueChanged



容易得多,不是吗.

请让我告诉你,现在您在编码风格和理解开发方面存在严重问题,需要学习很多.
不用担心,它将伴随经验. Jeszcze Polska Nie Zginela!

—SA



Much easier, isn''t it.

Please, let me tell you that right now you have serious problems with coding style and understanding development, need to learn a lot.
Don''t worry, it will come with experience. Jeszcze Polska Nie Zginela!

—SA


这篇关于从此站点将值从组合框发送到应用程序中的numericUpDown的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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