[C#] make MultiIcon Class to work with 256x256 png's

Discussion in 'Mixed Languages' started by FreeStyler, Jul 30, 2012.

  1. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    I have a found a very useful icon class i like to use in a program, unfortunately it doesn't seem to support 256x256 icon's
    Basically what i think is wrong that icon width and height are calculated as byte values, and a byte value can be no more than 255

    http://www.codeproject.com/Articles/6171/Access-multiple-icons-in-a-single-icon-file

    Anyone know how to fix this class to support 256x256 png icons?
     
  2. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #2 stevemk14ebr, Jul 30, 2012
    Last edited: Jul 30, 2012
    i played with it and even adjusted the array so when the ico is read into memory, it will read 1 less byte to be less than the array limit but it still gave me a out of range exception idk man im stumped.

    i dont get an error until it's writinng the bitmap to the image box and even writing to a new bitmap before the image box gives an error(.tobitmap) so i think the memory stream is to large for the .tobitmap function
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    That is a nice little class, and changing large to jumbo (4) not work with it, have you tried IconLib:

    http://www.codeproject.com/Articles/16178/IconLib-Icons-Unfolded-MultiIcon-and-Windows-Vista

    not sure if it can get a 256 from a smaller one.. ?
    Icons are not my thing..:eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    Gonna check it out, looks promising
     
  5. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    Mmm that lib seems quite complicated, and not very well documented :(

    I basically need something simple that checks if various icon format exist in a loaded icon, eg:

     
  6. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    #7 FreeStyler, Jul 31, 2012
    Last edited: Jul 31, 2012
    (OP)
    Thats seems about right...thx.

    Now i need something that compares a pre-defined array/list (required icon sizes, bitdepths) with the array/list containing these icons sizes, bitdepths. The order of bitmaps in the icon can differ from the order of pre-defined array/list with values, is that possible?

    [edit]
    Ok, seems i have solved this... now the next step :)
     
  8. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    #8 FreeStyler, Aug 1, 2012
    Last edited: Aug 1, 2012
    (OP)
    Well, it's getting near to be finished

    [​IMG]

    btw, how can i make sure textBox1.Text (Manufacturer) and a icon are selected/typed in before enabling the 'Create Device Metadate Package' button (disabling the button until these 2 are selected/typed in)
    textBox2.Text (Model) may be empty, dropDown1 (Enclosure Type) defaults to 'Computer' so no check is needed here either.
     
  9. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #9 stevemk14ebr, Aug 1, 2012
    Last edited by a moderator: Apr 20, 2017
    vb.net
    Code:
      Public Sub disablecheck()
            'if the textbox has nothing in it and the picturebox has nothing in it then disable button 
            If TextBox1.Text = String.Empty And PictureBox1.Image Is Nothing Then
                Button1.Enabled = False
                'else if textbox length is longer than 0 characters and picturebox1.image is something then enable
                'when the textbox is filled and then all characters backspaced this check fails, i don't know why because this checks for all possible characters?
            ElseIf Not String.IsNullOrWhiteSpace(TextBox1.Text.Trim) And Not PictureBox1.Image Is Nothing Then
                Button1.Enabled = True
            End If
        End Sub
       
     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            'make sure your timer is enabled
            Call disablecheck()
        End Sub
    noticed this is c# here's c# code (converted with developerfusion.com)
    Code:
    public void disablecheck()
    {
    //if the textbox has nothing in it and the picturebox has nothing in it then disable button 
    if (TextBox1.Text == string.Empty & PictureBox1.Image == null) {
    Button1.Enabled = false;
    //else if textbox length is longer than 0 characters and picturebox1.image is something then enable
    //when the textbox is filled and then all characters backspaced this check fails, i don't know why because this checks for all possible characters?
    } else if (!string.IsNullOrWhiteSpace(TextBox1.Text.Trim) & (PictureBox1.Image != null)) {
    Button1.Enabled = true;
    }
    }
    
    private void Timer1_Tick(System.Object sender, System.EventArgs e)
    {
    //make sure your timer is enabled
    disablecheck();
    }
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    #10 FreeStyler, Aug 1, 2012
    Last edited by a moderator: Apr 20, 2017
    (OP)
    I am using NET 2.x , so String.IsNullOrWhiteSpace() is not available, i replaced it with String.IsNullOrEmpty(), same backspace problems occurs, quick an dirty fix for that issue, just add this at the top of disablecheck()

    Code:
                if (textBox1.Text.Trim().Length == 0)
                {
                    button5.Enabled = false;
                }
     
  11. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    #11 Alphawaves, Aug 1, 2012
    Last edited by a moderator: Apr 20, 2017
    How about:
    Code:
    if (pictureBox1.BackgroundImage != null && !String.IsNullOrEmpty(textBox1.Text) && textBox1.Text.Trim().Length != 0)
                {
                    button1.Enabled = true;
                }
                else
                {
                   button1.Enabled = false;
                }
    May need to change BackgroundImage to Image if using Image instead of BackgroundImage.

    By the way your project looks nice.. ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. FreeStyler

    FreeStyler MDL Guru

    Jun 23, 2007
    3,502
    3,611
    120
    if (pictureBox1.BackgroundImage != null && !String.IsNullOrEmpty(textBox1.Text.Trim())) catches the white spaces too, textBox1.Text.Trim().Length != 0 can be left out
     
  13. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    yep just make sure u add the pic box check 2 with that, i tried the length 2 but it didnt work for me?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    #14 Alphawaves, Aug 1, 2012
    Last edited by a moderator: Apr 20, 2017
    You dont need the length, as freestyler noticed, you only need this:
    Code:
    if (pictureBox1.BackgroundImage != null && !String.IsNullOrEmpty(textBox1.Text.Trim()))
    There was no need to add the extra check.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #15 stevemk14ebr, Aug 1, 2012
    Last edited: Aug 1, 2012
    oops posted without noticing the second page, so i didn't see his post, glad it works and nice project

    why did my original code not work though i used the string.isnullorwhitespace which should catch all the whitespaces 2 right?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    isnullorwhitespace is not compatible in .NET 2.0
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    i know that i ment that when i used that in .net 4 it didnt detect that the textbox was emtpy when you would type letters in then backspace them all-i used isnullorwhitespace in my code because i didnt know he was using .net 2
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    #18 Alphawaves, Aug 2, 2012
    Last edited by a moderator: Apr 20, 2017
    Maybe create own
    Code:
     public static bool IsNullOrWhiteSpace(string text)
                {
                    if (text != null)
                    {
                        for (int i = 0; i < text.Length; i++)
                        {
                            if (!char.IsWhiteSpace(text))
                            {
                                return false;
                            }
                        }
                    }
                    return true;
                }


    Then IsNullOrWhiteSpace works, pretty logical when you think about it :)
    :eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    what you just said confuses me but when i use isnullorwhitespace it didn't detect that the textbox was empty after backspacing everything out, it very simply didnt work
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,873
    20,137
    180
    It does work bro :) how are you using it ? ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...