473,583 Members | 3,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing image on picturebox in user control runtime

hi All,
This problem is for C# windows application.
I have a user control whcih contains one picture box along with other
controls.
Depending on certain conditions I want to change images on the picturebox.
But at the same time I want to refer only assembly of the user control in
other solution.
If I am using method System.Drawing. Image.FromFile( "filename") I have to put
gif files containing those images in bin directory of solution in whcih I am
using user control.
But I don't want that.
I want that only assebly needs to be referenced.
Is there any way for this.
If yes please send code snipet.
Thanks
Shailaja
Nov 15 '05 #1
3 29930
You can save your images as embedded resources and put them into the
picturebox by loading them from a resource stream.

Put your images in the solution, set their build action to "Embedded
resource" and then to load them use;

picBox.Image=Im age.FromStream( this.GetType(). Assembly.GetMan ifestResourceSt r
eam("<nameofass embly>.<nameofi mage>");

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Shailaja Kulkarni" <cr*********@ho tpop.com> wrote in message
news:Og******** ******@TK2MSFTN GP10.phx.gbl...
hi All,
This problem is for C# windows application.
I have a user control whcih contains one picture box along with other
controls.
Depending on certain conditions I want to change images on the picturebox.
But at the same time I want to refer only assembly of the user control in
other solution.
If I am using method System.Drawing. Image.FromFile( "filename") I have to put gif files containing those images in bin directory of solution in whcih I am using user control.
But I don't want that.
I want that only assebly needs to be referenced.
Is there any way for this.
If yes please send code snipet.
Thanks
Shailaja

Nov 15 '05 #2
Hi Bob,
thanks for your input, I tried this way but still I could not get the
desired result.
While I am trying to compile the project getting this exception message
" An exception occurred while trying to create an instance of
ShapeLibrary.Ba seShape. The exception was "'null' is not a valid value for
'stream'.".
Whereas "ShapeLibra ry" is name of assembly containing Embedded resources.
BaseShape is the user control in this Library in which I am putting image
from this perticular code above.
Have I missed anything?
Regards
Shailaja
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:Ok******** ******@TK2MSFTN GP10.phx.gbl...
You can save your images as embedded resources and put them into the
picturebox by loading them from a resource stream.

Put your images in the solution, set their build action to "Embedded
resource" and then to load them use;

picBox.Image=Im age.FromStream( this.GetType(). Assembly.GetMan ifestResourceSt r eam("<nameofass embly>.<nameofi mage>");

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Shailaja Kulkarni" <cr*********@ho tpop.com> wrote in message
news:Og******** ******@TK2MSFTN GP10.phx.gbl...
hi All,
This problem is for C# windows application.
I have a user control whcih contains one picture box along with other
controls.
Depending on certain conditions I want to change images on the picturebox. But at the same time I want to refer only assembly of the user control in other solution.
If I am using method System.Drawing. Image.FromFile( "filename") I have to put
gif files containing those images in bin directory of solution in whcih

I am
using user control.
But I don't want that.
I want that only assebly needs to be referenced.
Is there any way for this.
If yes please send code snipet.
Thanks
Shailaja


Nov 15 '05 #3
You have to ensure that you use the fully qualified name for the resource.
This will depend on your solution structure.

The resource name is probably something like "MyApplication. MyImage.bmp"

If you can't devine the resource name add a bit of temporary code to the
constructor...

public MyClass
{
InitializeCompo nent();

//tempororary code
string[] names=this.GetT ype().Assembly. GetManifestReso urceNames();
foreach(string s in names)
System.diagnost ics.Trace.Write Line(s);
//temporary code
}

This will dump all the names to the output pane and you can see how they're
named. Once you know, delete the temporary code.
--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Shailaja Kulkarni" <cr*********@ho tpop.com> wrote in message
news:Ou******** ******@TK2MSFTN GP10.phx.gbl...
Hi Bob,
thanks for your input, I tried this way but still I could not get the
desired result.
While I am trying to compile the project getting this exception message
" An exception occurred while trying to create an instance of
ShapeLibrary.Ba seShape. The exception was "'null' is not a valid value for
'stream'.".
Whereas "ShapeLibra ry" is name of assembly containing Embedded resources.
BaseShape is the user control in this Library in which I am putting image
from this perticular code above.
Have I missed anything?
Regards
Shailaja
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:Ok******** ******@TK2MSFTN GP10.phx.gbl...
You can save your images as embedded resources and put them into the
picturebox by loading them from a resource stream.

Put your images in the solution, set their build action to "Embedded
resource" and then to load them use;

picBox.Image=Im age.FromStream( this.GetType(). Assembly.GetMan ifestResourceSt r
eam("<nameofass embly>.<nameofi mage>");

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Shailaja Kulkarni" <cr*********@ho tpop.com> wrote in message
news:Og******** ******@TK2MSFTN GP10.phx.gbl...
hi All,
This problem is for C# windows application.
I have a user control whcih contains one picture box along with other
controls.
Depending on certain conditions I want to change images on the picturebox. But at the same time I want to refer only assembly of the user control in other solution.
If I am using method System.Drawing. Image.FromFile( "filename") I have
to put
gif files containing those images in bin directory of solution in

whcih I
am
using user control.
But I don't want that.
I want that only assebly needs to be referenced.
Is there any way for this.
If yes please send code snipet.
Thanks
Shailaja



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2111
by: CoreyMas | last post by:
Hello All, Here is what I would like to do I am creating a game program that displays a map (preferably in hexes but that is another matter) and whenever the user is over the "map" I want to know the x,y coords (in pixels) of where he is pointing to. Here is what I have done
4
28169
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image (at design-time). Why? Why can't I find PictureBox in VBA within MS Access? And most importantly...why can't I put either in a Report within MS...
15
31785
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and help. Regards
5
3139
by: Jeff | last post by:
I've seen a couple of posts on the Internet with others having this problem, however, no one seems to have a good answer. I am working on a C# Smart Device application and have been able to browse for a PictureBox image and insert in the Visual Studio .NET 2003 PictureBox1 properties pane. Now for some reason I can't - it's grayed out. I...
1
3305
by: M West | last post by:
continuation of my previous post, thanks to all those that contributed with answers I am creating a control that will take an image and make parts of it transparent, this is done by creating and then applying a region to the control. The control inherits from picturebox and works fine when loading the image into the control, the problem...
3
63339
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the...
7
11608
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an...
1
12430
by: Filippo Bettinaglio | last post by:
Hi, I have a PictureBox with the border set to BorderStyle = FixedSingle and it comes up with a nice Black border. How can I change it at runtime? I use VS2005 (net2 framework)
7
6002
by: kebalex | last post by:
Hi, I have an app (written in .NET 2.0) which updates a picturebox according to some user input (a slider control). when the user makes a change i loop through all of the pixels, do a calculation and update the picture. i currently use the GDI SetPixel method on each pixel of the Pictureboxes image. This is proving far to slow, about 1.5...
0
7821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8190
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.