Button Images Not Showing When Using XP Style Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terrance

    Button Images Not Showing When Using XP Style Forms

    Good Afternoon:
    I was hoping if someone could share some light on a problem that I'm facing.
    When I create a Visual Basic.Net program and I use the XP style for my Window
    Forms and buttons; if I add images to my menu buttons they don't show when
    the form is created. But, if I don't use the XP style the images show on my
    buttons correctly. Can someone please explain to me what the problem is and
    how to get around it? Here is how I'm calling my forms:
    Public Sub Main()

    Dim frmSplash As New fclsSplash
    Dim mainForm As New fclsMain

    System.Windows. Forms.Applicati on.EnableVisual Styles()
    System.Windows. Forms.Applicati on.Run(frmSplas h)

    Select Case vfClass.fdispla y
    Case 0
    System.Windows. Forms.Applicati on.Run(SqlLogin )
    Case 1
    System.Windows. Forms.Applicati on.Run(mainForm )
    End Select

    It's my mainForm that holds the menu buttons with the images. Do anyone
    know what's going on? Thanks.
    --
    TC
  • Mattias Sjögren

    #2
    Re: Button Images Not Showing When Using XP Style Forms

    [color=blue]
    > It's my mainForm that holds the menu buttons with the images. Do anyone
    >know what's going on?[/color]

    Just like the documentation says, when you set the button's FlatStyle
    property to System the Image isn't displayed.




    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Mick Doherty

      #3
      Re: Button Images Not Showing When Using XP Style Forms

      What type of button is a MenuButton?

      If it's a toolbar button then you need to add Application.DoE vents after
      Application.Ena bleVisualStyles , or supply a manifest file instead of calling
      Application.Ena bleVisualStyles .

      If it's a standard Button, then System Buttons do not show an Image. I
      modified the Button class to get around this and you will find the source
      for this button on my site. Note that when set to Flatsyle.System the button
      still wont show an Image, but Visual Styles will be applied to
      Flatstyle.Stand ard buttons.


      --
      Mick Doherty



      "Terrance" <Terrance@discu ssions.microsof t.com> wrote in message
      news:792B2D2B-467C-41E6-95BD-E8420AB3B719@mi crosoft.com...[color=blue]
      > Good Afternoon:
      > I was hoping if someone could share some light on a problem that I'm
      > facing.
      > When I create a Visual Basic.Net program and I use the XP style for my
      > Window
      > Forms and buttons; if I add images to my menu buttons they don't show when
      > the form is created. But, if I don't use the XP style the images show on
      > my
      > buttons correctly. Can someone please explain to me what the problem is
      > and
      > how to get around it? Here is how I'm calling my forms:
      > Public Sub Main()
      >
      > Dim frmSplash As New fclsSplash
      > Dim mainForm As New fclsMain
      >
      > System.Windows. Forms.Applicati on.EnableVisual Styles()
      > System.Windows. Forms.Applicati on.Run(frmSplas h)
      >
      > Select Case vfClass.fdispla y
      > Case 0
      > System.Windows. Forms.Applicati on.Run(SqlLogin )
      > Case 1
      > System.Windows. Forms.Applicati on.Run(mainForm )
      > End Select
      >
      > It's my mainForm that holds the menu buttons with the images. Do anyone
      > know what's going on? Thanks.
      > --
      > TC[/color]


      Comment

      • Dave Green

        #4
        Re: Button Images Not Showing When Using XP Style Forms

        Mick,

        I have the same problem in VB.net. I can see the image in the design window
        on the toolbar button. But, when I build and run the application the image
        doesn't show up. I don't know where the Application.Ena bleVisualStyles
        statement is.

        Can you help?


        Thanks.

        Dave Green
        dcgreen@dcgreen .com

        "Mick Doherty" wrote:
        [color=blue]
        > What type of button is a MenuButton?
        >
        > If it's a toolbar button then you need to add Application.DoE vents after
        > Application.Ena bleVisualStyles , or supply a manifest file instead of calling
        > Application.Ena bleVisualStyles .
        >
        > If it's a standard Button, then System Buttons do not show an Image. I
        > modified the Button class to get around this and you will find the source
        > for this button on my site. Note that when set to Flatsyle.System the button
        > still wont show an Image, but Visual Styles will be applied to
        > Flatstyle.Stand ard buttons.
        > http://dotnetrix.co.uk/buttons.html
        >
        > --
        > Mick Doherty
        > http://dotnetrix.co.uk/nothing.html
        >
        >
        > "Terrance" <Terrance@discu ssions.microsof t.com> wrote in message
        > news:792B2D2B-467C-41E6-95BD-E8420AB3B719@mi crosoft.com...[color=green]
        > > Good Afternoon:
        > > I was hoping if someone could share some light on a problem that I'm
        > > facing.
        > > When I create a Visual Basic.Net program and I use the XP style for my
        > > Window
        > > Forms and buttons; if I add images to my menu buttons they don't show when
        > > the form is created. But, if I don't use the XP style the images show on
        > > my
        > > buttons correctly. Can someone please explain to me what the problem is
        > > and
        > > how to get around it? Here is how I'm calling my forms:
        > > Public Sub Main()
        > >
        > > Dim frmSplash As New fclsSplash
        > > Dim mainForm As New fclsMain
        > >
        > > System.Windows. Forms.Applicati on.EnableVisual Styles()
        > > System.Windows. Forms.Applicati on.Run(frmSplas h)
        > >
        > > Select Case vfClass.fdispla y
        > > Case 0
        > > System.Windows. Forms.Applicati on.Run(SqlLogin )
        > > Case 1
        > > System.Windows. Forms.Applicati on.Run(mainForm )
        > > End Select
        > >
        > > It's my mainForm that holds the menu buttons with the images. Do anyone
        > > know what's going on? Thanks.
        > > --
        > > TC[/color]
        >
        >
        >[/color]

        Comment

        • Dave

          #5
          Re: Button Images Not Showing When Using XP Style Forms

          I'm sorry I no longer have the reference to an article on MSDN a few weeks ago that states there is a bug using image buttons in
          VS.NET due to the serialization order of code.

          The fix, if I remember correctly, was to go into the hidden area of code that the designer serializes and move any code that adjusts
          the buttons bounds or location to appear before the image property is set.

          The problem with this "quick fix" is that designer changes may revert back to the error-producing code. At this time I don't
          believe there is a fix for the latest version of NET. Maybe 2005 will have fixed that issue.

          --
          Dave Sexton
          dave@www..jwaon line..com
          -----------------------------------------------------------------------
          "Dave Green" <Dave Green@discussio ns.microsoft.co m> wrote in message news:A6E15F34-891D-4F85-8A43-4EA1D6CD3F27@mi crosoft.com...[color=blue]
          > Mick,
          >
          > I have the same problem in VB.net. I can see the image in the design window
          > on the toolbar button. But, when I build and run the application the image
          > doesn't show up. I don't know where the Application.Ena bleVisualStyles
          > statement is.
          >
          > Can you help?
          >
          >
          > Thanks.
          >
          > Dave Green
          > dcgreen@dcgreen .com
          >
          > "Mick Doherty" wrote:
          >[color=green]
          >> What type of button is a MenuButton?
          >>
          >> If it's a toolbar button then you need to add Application.DoE vents after
          >> Application.Ena bleVisualStyles , or supply a manifest file instead of calling
          >> Application.Ena bleVisualStyles .
          >>
          >> If it's a standard Button, then System Buttons do not show an Image. I
          >> modified the Button class to get around this and you will find the source
          >> for this button on my site. Note that when set to Flatsyle.System the button
          >> still wont show an Image, but Visual Styles will be applied to
          >> Flatstyle.Stand ard buttons.
          >> http://dotnetrix.co.uk/buttons.html
          >>
          >> --
          >> Mick Doherty
          >> http://dotnetrix.co.uk/nothing.html
          >>
          >>
          >> "Terrance" <Terrance@discu ssions.microsof t.com> wrote in message
          >> news:792B2D2B-467C-41E6-95BD-E8420AB3B719@mi crosoft.com...[color=darkred]
          >> > Good Afternoon:
          >> > I was hoping if someone could share some light on a problem that I'm
          >> > facing.
          >> > When I create a Visual Basic.Net program and I use the XP style for my
          >> > Window
          >> > Forms and buttons; if I add images to my menu buttons they don't show when
          >> > the form is created. But, if I don't use the XP style the images show on
          >> > my
          >> > buttons correctly. Can someone please explain to me what the problem is
          >> > and
          >> > how to get around it? Here is how I'm calling my forms:
          >> > Public Sub Main()
          >> >
          >> > Dim frmSplash As New fclsSplash
          >> > Dim mainForm As New fclsMain
          >> >
          >> > System.Windows. Forms.Applicati on.EnableVisual Styles()
          >> > System.Windows. Forms.Applicati on.Run(frmSplas h)
          >> >
          >> > Select Case vfClass.fdispla y
          >> > Case 0
          >> > System.Windows. Forms.Applicati on.Run(SqlLogin )
          >> > Case 1
          >> > System.Windows. Forms.Applicati on.Run(mainForm )
          >> > End Select
          >> >
          >> > It's my mainForm that holds the menu buttons with the images. Do anyone
          >> > know what's going on? Thanks.
          >> > --
          >> > TC[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          • Mick Doherty

            #6
            Re: Button Images Not Showing When Using XP Style Forms

            Assuming your startup form is called Form1 add the following code to the
            form.

            Shared Sub main()
            Application.Ena bleVisualStyles
            Application.DoE vents
            Application.Run (New Form1)
            End Sub

            --
            Mick Doherty



            "Dave Green" <Dave Green@discussio ns.microsoft.co m> wrote in message
            news:A6E15F34-891D-4F85-8A43-4EA1D6CD3F27@mi crosoft.com...[color=blue]
            > Mick,
            >
            > I have the same problem in VB.net. I can see the image in the design
            > window
            > on the toolbar button. But, when I build and run the application the image
            > doesn't show up. I don't know where the Application.Ena bleVisualStyles
            > statement is.
            >
            > Can you help?
            >
            >
            > Thanks.
            >
            > Dave Green
            > dcgreen@dcgreen .com
            >
            > "Mick Doherty" wrote:
            >[color=green]
            >> What type of button is a MenuButton?
            >>
            >> If it's a toolbar button then you need to add Application.DoE vents after
            >> Application.Ena bleVisualStyles , or supply a manifest file instead of
            >> calling
            >> Application.Ena bleVisualStyles .
            >>
            >> If it's a standard Button, then System Buttons do not show an Image. I
            >> modified the Button class to get around this and you will find the source
            >> for this button on my site. Note that when set to Flatsyle.System the
            >> button
            >> still wont show an Image, but Visual Styles will be applied to
            >> Flatstyle.Stand ard buttons.
            >> http://dotnetrix.co.uk/buttons.html
            >>
            >> --
            >> Mick Doherty
            >> http://dotnetrix.co.uk/nothing.html
            >>
            >>
            >> "Terrance" <Terrance@discu ssions.microsof t.com> wrote in message
            >> news:792B2D2B-467C-41E6-95BD-E8420AB3B719@mi crosoft.com...[color=darkred]
            >> > Good Afternoon:
            >> > I was hoping if someone could share some light on a problem that I'm
            >> > facing.
            >> > When I create a Visual Basic.Net program and I use the XP style for my
            >> > Window
            >> > Forms and buttons; if I add images to my menu buttons they don't show
            >> > when
            >> > the form is created. But, if I don't use the XP style the images show
            >> > on
            >> > my
            >> > buttons correctly. Can someone please explain to me what the problem is
            >> > and
            >> > how to get around it? Here is how I'm calling my forms:
            >> > Public Sub Main()
            >> >
            >> > Dim frmSplash As New fclsSplash
            >> > Dim mainForm As New fclsMain
            >> >
            >> > System.Windows. Forms.Applicati on.EnableVisual Styles()
            >> > System.Windows. Forms.Applicati on.Run(frmSplas h)
            >> >
            >> > Select Case vfClass.fdispla y
            >> > Case 0
            >> > System.Windows. Forms.Applicati on.Run(SqlLogin )
            >> > Case 1
            >> > System.Windows. Forms.Applicati on.Run(mainForm )
            >> > End Select
            >> >
            >> > It's my mainForm that holds the menu buttons with the images. Do anyone
            >> > know what's going on? Thanks.
            >> > --
            >> > TC[/color]
            >>
            >>
            >>[/color][/color]


            Comment

            • dave green

              #7
              Re: Button Images Not Showing When Using XP Style Forms

              Thanks Mick. Unfortunately, this form is not the startup form. I'm not sure
              if that is why it doesn't work. Should that make a difference?


              Dave

              "Mick Doherty" wrote:
              [color=blue]
              > Assuming your startup form is called Form1 add the following code to the
              > form.
              >
              > Shared Sub main()
              > Application.Ena bleVisualStyles
              > Application.DoE vents
              > Application.Run (New Form1)
              > End Sub
              >
              > --
              > Mick Doherty
              > http://dotnetrix.co.uk/nothing.html
              >
              >
              > "Dave Green" <Dave Green@discussio ns.microsoft.co m> wrote in message
              > news:A6E15F34-891D-4F85-8A43-4EA1D6CD3F27@mi crosoft.com...[color=green]
              > > Mick,
              > >
              > > I have the same problem in VB.net. I can see the image in the design
              > > window
              > > on the toolbar button. But, when I build and run the application the image
              > > doesn't show up. I don't know where the Application.Ena bleVisualStyles
              > > statement is.
              > >
              > > Can you help?
              > >
              > >
              > > Thanks.
              > >
              > > Dave Green
              > > dcgreen@dcgreen .com
              > >
              > > "Mick Doherty" wrote:
              > >[color=darkred]
              > >> What type of button is a MenuButton?
              > >>
              > >> If it's a toolbar button then you need to add Application.DoE vents after
              > >> Application.Ena bleVisualStyles , or supply a manifest file instead of
              > >> calling
              > >> Application.Ena bleVisualStyles .
              > >>
              > >> If it's a standard Button, then System Buttons do not show an Image. I
              > >> modified the Button class to get around this and you will find the source
              > >> for this button on my site. Note that when set to Flatsyle.System the
              > >> button
              > >> still wont show an Image, but Visual Styles will be applied to
              > >> Flatstyle.Stand ard buttons.
              > >> http://dotnetrix.co.uk/buttons.html
              > >>
              > >> --
              > >> Mick Doherty
              > >> http://dotnetrix.co.uk/nothing.html
              > >>
              > >>
              > >> "Terrance" <Terrance@discu ssions.microsof t.com> wrote in message
              > >> news:792B2D2B-467C-41E6-95BD-E8420AB3B719@mi crosoft.com...
              > >> > Good Afternoon:
              > >> > I was hoping if someone could share some light on a problem that I'm
              > >> > facing.
              > >> > When I create a Visual Basic.Net program and I use the XP style for my
              > >> > Window
              > >> > Forms and buttons; if I add images to my menu buttons they don't show
              > >> > when
              > >> > the form is created. But, if I don't use the XP style the images show
              > >> > on
              > >> > my
              > >> > buttons correctly. Can someone please explain to me what the problem is
              > >> > and
              > >> > how to get around it? Here is how I'm calling my forms:
              > >> > Public Sub Main()
              > >> >
              > >> > Dim frmSplash As New fclsSplash
              > >> > Dim mainForm As New fclsMain
              > >> >
              > >> > System.Windows. Forms.Applicati on.EnableVisual Styles()
              > >> > System.Windows. Forms.Applicati on.Run(frmSplas h)
              > >> >
              > >> > Select Case vfClass.fdispla y
              > >> > Case 0
              > >> > System.Windows. Forms.Applicati on.Run(SqlLogin )
              > >> > Case 1
              > >> > System.Windows. Forms.Applicati on.Run(mainForm )
              > >> > End Select
              > >> >
              > >> > It's my mainForm that holds the menu buttons with the images. Do anyone
              > >> > know what's going on? Thanks.
              > >> > --
              > >> > TC
              > >>
              > >>
              > >>[/color][/color]
              >
              >
              >[/color]

              Comment

              • Mick Doherty

                #8
                Re: Button Images Not Showing When Using XP Style Forms

                Actually, I'm not entirely sure what the cause of your problem is, I
                answered a bit too quickly earlier.
                Since you didn't know where EnableVisualSty les was called I should assume
                that this is not a WinXP issue.

                I've seen several variations of this problem and the most difficult to sort
                out, was in an app that started without a GUI, but displayed a dialog box
                with a toolbar at specified events. I've never seen this issue on a non
                Visual Styles Enabled app, but that does not mean it doesn't happen.

                Can you recreate the problem in a small project, or give the steps required
                to reproduce it?

                --
                Mick Doherty



                "dave green" <dave green@discussio ns.microsoft.co m> wrote in message
                news:882E6D10-EC73-46FD-876B-C6A280604E86@mi crosoft.com...[color=blue]
                > Thanks Mick. Unfortunately, this form is not the startup form. I'm not
                > sure
                > if that is why it doesn't work. Should that make a difference?
                >
                >
                > Dave[/color]


                Comment

                • Dave

                  #9
                  Re: Button Images Not Showing When Using XP Style Forms

                  Did you attempt to try the fix I posted previously on this thread?

                  Locate the designer-serialized code in your code-behind. It will probably be in a #region block named, "Windows Form Designer
                  generated code".

                  In the region, find the method named, "InitializeComp onent".

                  In the method there will be a declartion for your control. Find the area of the method that sets the properties on your control
                  (The appropriate section should be marked with a comment).

                  Cut and Paste the line of code that sets the image of the button as the last line of the section.

                  See if that does it.

                  Like I said, the article states that this is a bug. No sense driving yourself crazy over this if you can identify the problem as a
                  bug early on.

                  --
                  Dave Sexton
                  dave@www..jwaon line..com
                  -----------------------------------------------------------------------
                  "Mick Doherty" <EXCHANGE#WITH@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in message
                  news:eMaVxg1RFH A.2932@TK2MSFTN GP09.phx.gbl...[color=blue]
                  > Actually, I'm not entirely sure what the cause of your problem is, I answered a bit too quickly earlier.
                  > Since you didn't know where EnableVisualSty les was called I should assume that this is not a WinXP issue.
                  >
                  > I've seen several variations of this problem and the most difficult to sort out, was in an app that started without a GUI, but
                  > displayed a dialog box with a toolbar at specified events. I've never seen this issue on a non Visual Styles Enabled app, but that
                  > does not mean it doesn't happen.
                  >
                  > Can you recreate the problem in a small project, or give the steps required to reproduce it?
                  >
                  > --
                  > Mick Doherty
                  > http://dotnetrix.co.uk/nothing.html
                  >
                  >
                  > "dave green" <dave green@discussio ns.microsoft.co m> wrote in message news:882E6D10-EC73-46FD-876B-C6A280604E86@mi crosoft.com...[color=green]
                  >> Thanks Mick. Unfortunately, this form is not the startup form. I'm not sure
                  >> if that is why it doesn't work. Should that make a difference?
                  >>
                  >>
                  >> Dave[/color]
                  >
                  >[/color]


                  Comment

                  • Mick Doherty

                    #10
                    Re: Button Images Not Showing When Using XP Style Forms

                    If that is the problem, then the code could be cut from the
                    InitializeCompo nent() method and pasted to Sub New() after the
                    InitializeCompo nent() call. That way the designer is not going to mess with
                    it every time you rebuild the project.

                    --
                    Mick Doherty



                    "Dave" <NOSPAM-dave@dotcomdata solutions.com> wrote in message
                    news:OqUTztUSFH A.4028@tk2msftn gp13.phx.gbl...[color=blue]
                    > Did you attempt to try the fix I posted previously on this thread?
                    >
                    > Locate the designer-serialized code in your code-behind. It will probably
                    > be in a #region block named, "Windows Form Designer generated code".
                    >
                    > In the region, find the method named, "InitializeComp onent".
                    >
                    > In the method there will be a declartion for your control. Find the area
                    > of the method that sets the properties on your control (The appropriate
                    > section should be marked with a comment).
                    >
                    > Cut and Paste the line of code that sets the image of the button as the
                    > last line of the section.
                    >
                    > See if that does it.
                    >
                    > Like I said, the article states that this is a bug. No sense driving
                    > yourself crazy over this if you can identify the problem as a bug early
                    > on.
                    >
                    > --
                    > Dave Sexton
                    > dave@www..jwaon line..com[/color]


                    Comment

                    Working...