Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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!");
            }

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
Posted
Comments
Dave Kreskowiak 21-Feb-11 13:24pm    
IMHO, that's a bad way to tell specify the target size of an image. You'd have to enumerate all of the numeric up/down controls in your container (whatever you're using here) and set them individually.

BTW: What's with all the Convert.ToInt32 calls? You don't need them at all.

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
 
Share this answer
 
v3
Comments
Espen Harlinn 25-Feb-11 6:46am    
Amazing effort, my 5
Sergey Alexandrovich Kryukov 25-Feb-11 19:14pm    
Thank you, Espen. Unfortunately, mostly criticism; before it comes to the essential application goals of the work, a lot should be improved...
--SA
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():

C#
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


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

C#
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


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
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 21-Feb-11 14:29pm    
OP commented:

Ye, i understand that i am learn programming but i've got problem to modify it in this application in link i wrote above. Could u check this application code in link and tell me where should i add it? It's a lot of code where i'm stacking in
Sergey Alexandrovich Kryukov 21-Feb-11 14:39pm    
I added the event usage. Add this code at the end of your form's constructor.
You don't need separate method for event handles, better use anonymous form I show.

I don't see relevant link in your question. I think I gave you very complete working code for your Question.

--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900