Results 1 to 9 of 9

Thread: [RESOLVED] there must be another way (ToolStripDropDownButton)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Resolved [RESOLVED] there must be another way (ToolStripDropDownButton)

    Hi

    I have a

    • StatusStrip with a ToolStripDropDownButton
    • ToolStripDownButton Property is set to "Image and Text"
    • Resourcefile with to pictures (Pic1 and Pic2)


    assign during designmode a Image from the resource file called Pic1 to the property Image

    during the run this Image has to be changed so i did

    VB Code:
    1. if (dropdownbutton.Image.Equals(Resources.Pic1))
    2. {
    3. [INDENT]dropdownbutton.Image = Resources.Pic2;[/INDENT]
    4. }
    5. else
    6. {
    7. [INDENT]dropdownbutton.Image = Resources.Pic1;[/INDENT]
    8. }

    does not work.

    i am using now this methode
    the Tag Property of the ToolStripDropDownButton becomes during design time the value "0"

    VB Code:
    1. if (dropdownbutton.Tag.Equals("1"))
    2. {
    3. [INDENT]dropdownbutton.Tag = "2";[/INDENT]
    4. [INDENT]dropdownbutton.Image = Resources.Pic2;[/INDENT]
    5. }
    6. else
    7. {
    8. [INDENT]dropdownbutton.Tag = "1";[/INDENT]
    9. [INDENT]dropdownbutton.Image = Resources.Pic1;[/INDENT]
    10. }

    There must be a better way ???

    thx
    Last edited by Bongo; Nov 15th, 2006 at 07:10 AM. Reason: Changing Resolved Icon

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: there must be another way (ToolStripDropDownButton)

    It is working right now? You just want it better? Better how? Shorter? No IF?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: there must be another way (ToolStripDropDownButton)

    no i thing if an object has the methode equal (which i thing is to compare) there should be a way to say Image.Equal(image) should work. It works with other objects.

    So i believe if did a workaround but i did not solve the real issue.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: there must be another way (ToolStripDropDownButton)

    Or lets rephrase

    WHY does
    if(TooStripDropDownButton.Image.Equal(Resources.Image))
    not work???

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: there must be another way (ToolStripDropDownButton)

    Quote Originally Posted by Bongo
    Or lets rephrase

    WHY does
    if(TooStripDropDownButton.Image.Equal(Resources.Image))
    not work???
    Because each time you get that property from your resources you get a new Image object. If you get the property twice then your creating two distinct Image objects so they are not equal. You should only be getting each resource once each. Assign them to variables and compare to those variables.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: there must be another way (ToolStripDropDownButton)

    Because each time you get that property from your resources you get a new Image object. If you get the property twice then your creating two distinct Image objects so they are not equal. You should only be getting each resource once each. Assign them to variables and compare to those variables.
    Hi jmcilhinney,

    so if i would write

    Image img1 = TooStripDropDownButton.Image;
    Image img2 = Resources.Pic1;

    if (img1.Equal(img2))

    it should work. (cant try it in the moment - not an a developing comp)

    If it works it would look better then the thingi with the tag.

    thx
    Last edited by Bongo; Nov 14th, 2006 at 02:21 AM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: there must be another way (ToolStripDropDownButton)

    Quote Originally Posted by Bongo
    Image img1 = TooStripDropDownButton.Image;
    Image img2 = Resources.Pic1;

    if (img1.Equal(img2))
    Tryed it - did not work

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: there must be another way (ToolStripDropDownButton)

    Declare two class-level Image variables. Get your resource images once only and assign them to those variables. Now you ONLY set the Image property of your button from those variables and you ONLY compare the Image property of your button to those variables. Also, just use the '==' operator to compare two reference type objects.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: there must be another way (ToolStripDropDownButton)

    @jmcilhinney

    many thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width