Windows Develop Bookmark and Share   
 index > Windows Forms General > Windows Form only Displays part of a Graphic After Publish
 

Windows Form only Displays part of a Graphic After Publish

I have a windows form with a few buttons on it and I have a background graphic which is supposed to appear when the user clicks any of them. It works fine in visual studio however when I run the published version on the same computer it seems to only display the upper half of the graphic on each button. I cannot think of any explanation for this. Is there anything that would cause this to happen. I checked and all the graphic files are included int he publish.
Zero_gt  Thursday, July 30, 2009 4:52 AM
Hi Zero_gt ,

We can create the image in another way and set it to the button. This is the code snippet:
//Create a new image the size of which is the same as the button.
Image img = new Bitmap(Image.FromFile("button_highlight.png"),this.button1.Size);
//Set the image to the button.
this.button1.Image = img;

Let me know if this helps.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer byZero_gt Wednesday, August 05, 2009 8:47 PM
  •  
Aland Li  Friday, July 31, 2009 6:15 AM
You've provided too few details to make the call. Guessing: you are probably running this on a machine with a different video DPI or system font size. That rescales the controls but not the image. Be sure to use the Graphics.DrawImage(image, Rectangle) overload so you'll always fill the control.

Hans Passant.
nobugz  Thursday, July 30, 2009 11:51 AM
I wonder if maybe you could explain a little more on how I can use Graphics.DrawImage in my case. Currently I have a event handler so that when the user clicks the button this among other things happens:
Button1.Image = Image.FromFile("button_highlight.png");

-So is there someway I can replace my code with the code you are suggesting?
Zero_gt  Thursday, July 30, 2009 10:19 PM
Hmm, buttons are tricky. What is the ImageAlign property set to?
Hans Passant.
nobugz  Thursday, July 30, 2009 10:44 PM
Hi Zero_gt ,

We can create the image in another way and set it to the button. This is the code snippet:
//Create a new image the size of which is the same as the button.
Image img = new Bitmap(Image.FromFile("button_highlight.png"),this.button1.Size);
//Set the image to the button.
this.button1.Image = img;

Let me know if this helps.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Marked As Answer byZero_gt Wednesday, August 05, 2009 8:47 PM
  •  
Aland Li  Friday, July 31, 2009 6:15 AM

You can use google to search for other answers

Custom Search

More Threads

• How to Integrate MS Word Viewer in to the WinForm Application
• Tab button
• Autosize column listview and datagrid ?
• Help with StackOverFlowException..
• while writing a csv file from application, not able to write the zero padded numbers to file.
• problem to call a Dll function .NET
• regarding password protection
• XAMLPAD-too simple to be useful?
• Panel's border style
• Programatically pull Domain Name (Active Directory)