471,338 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

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.Application.EnableVisualStyle s()
System.Windows.Forms.Application.Run(frmSplash)

Select Case vfClass.fdisplay
Case 0
System.Windows.Forms.Application.Run(SqlLogin)
Case 1
System.Windows.Forms.Application.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
Jul 21 '05 #1
9 3324
It's my mainForm that holds the menu buttons with the images. Do anyone
know what's going on?


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.
Jul 21 '05 #2
What type of button is a MenuButton?

If it's a toolbar button then you need to add Application.DoEvents after
Application.EnableVisualStyles, or supply a manifest file instead of calling
Application.EnableVisualStyles.

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.Standard buttons.
http://dotnetrix.co.uk/buttons.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.Application.EnableVisualStyle s()
System.Windows.Forms.Application.Run(frmSplash)

Select Case vfClass.fdisplay
Case 0
System.Windows.Forms.Application.Run(SqlLogin)
Case 1
System.Windows.Forms.Application.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

Jul 21 '05 #3
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.EnableVisualStyles
statement is.

Can you help?
Thanks.

Dave Green
dc*****@dcgreen.com

"Mick Doherty" wrote:
What type of button is a MenuButton?

If it's a toolbar button then you need to add Application.DoEvents after
Application.EnableVisualStyles, or supply a manifest file instead of calling
Application.EnableVisualStyles.

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.Standard buttons.
http://dotnetrix.co.uk/buttons.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.Application.EnableVisualStyle s()
System.Windows.Forms.Application.Run(frmSplash)

Select Case vfClass.fdisplay
Case 0
System.Windows.Forms.Application.Run(SqlLogin)
Case 1
System.Windows.Forms.Application.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


Jul 21 '05 #4
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..jwaonline..com
-----------------------------------------------------------------------
"Dave Green" <Dave Gr***@discussions.microsoft.com> wrote in message news:A6**********************************@microsof t.com...
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.EnableVisualStyles
statement is.

Can you help?
Thanks.

Dave Green
dc*****@dcgreen.com

"Mick Doherty" wrote:
What type of button is a MenuButton?

If it's a toolbar button then you need to add Application.DoEvents after
Application.EnableVisualStyles, or supply a manifest file instead of calling
Application.EnableVisualStyles.

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.Standard buttons.
http://dotnetrix.co.uk/buttons.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.Application.EnableVisualStyle s()
> System.Windows.Forms.Application.Run(frmSplash)
>
> Select Case vfClass.fdisplay
> Case 0
> System.Windows.Forms.Application.Run(SqlLogin)
> Case 1
> System.Windows.Forms.Application.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


Jul 21 '05 #5
Assuming your startup form is called Form1 add the following code to the
form.

Shared Sub main()
Application.EnableVisualStyles
Application.DoEvents
Application.Run(New Form1)
End Sub

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Dave Green" <Dave Gr***@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
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.EnableVisualStyles
statement is.

Can you help?
Thanks.

Dave Green
dc*****@dcgreen.com

"Mick Doherty" wrote:
What type of button is a MenuButton?

If it's a toolbar button then you need to add Application.DoEvents after
Application.EnableVisualStyles, or supply a manifest file instead of
calling
Application.EnableVisualStyles.

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.Standard buttons.
http://dotnetrix.co.uk/buttons.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.Application.EnableVisualStyle s()
> System.Windows.Forms.Application.Run(frmSplash)
>
> Select Case vfClass.fdisplay
> Case 0
> System.Windows.Forms.Application.Run(SqlLogin)
> Case 1
> System.Windows.Forms.Application.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


Jul 21 '05 #6
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:
Assuming your startup form is called Form1 add the following code to the
form.

Shared Sub main()
Application.EnableVisualStyles
Application.DoEvents
Application.Run(New Form1)
End Sub

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Dave Green" <Dave Gr***@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
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.EnableVisualStyles
statement is.

Can you help?
Thanks.

Dave Green
dc*****@dcgreen.com

"Mick Doherty" wrote:
What type of button is a MenuButton?

If it's a toolbar button then you need to add Application.DoEvents after
Application.EnableVisualStyles, or supply a manifest file instead of
calling
Application.EnableVisualStyles.

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.Standard buttons.
http://dotnetrix.co.uk/buttons.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Terrance" <Te******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.Application.EnableVisualStyle s()
> System.Windows.Forms.Application.Run(frmSplash)
>
> Select Case vfClass.fdisplay
> Case 0
> System.Windows.Forms.Application.Run(SqlLogin)
> Case 1
> System.Windows.Forms.Application.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


Jul 21 '05 #7
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 EnableVisualStyles 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 gr***@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
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

Jul 21 '05 #8
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, "InitializeComponent".

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..jwaonline..com
-----------------------------------------------------------------------
"Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in message
news:eM**************@TK2MSFTNGP09.phx.gbl...
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 EnableVisualStyles 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 gr***@discussions.microsoft.com> wrote in message news:88**********************************@microsof t.com...
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


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

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...
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, "InitializeComponent".

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..jwaonline..com

Jul 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Marek Mänd | last post: by
10 posts views Thread by IkBenHet | last post: by
6 posts views Thread by meltedown | last post: by
5 posts views Thread by martinjeffreys | last post: by
1 post views Thread by Phil_Cam | last post: by
1 post views Thread by Peted | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.