Windows Develop Bookmark and Share   
 index > Windows Forms Designer > create a System.Drawing.Image from an icon file (not embbeded) on run-time
 

create a System.Drawing.Image from an icon file (not embbeded) on run-time

Hi guys,

How do I create a System.Drawing.Image from an icon file (not embbeded) on run-time?
I want to read the path of the icon from the database, convert to Image and add it as Image of my DropDown menu item.

Thanks in advance,
Aldo.
Everything is possible, impossible just takes longer
ajliaks  Sunday, March 15, 2009 7:45 AM
I did it this way:
System.Drawing.ImageiconImage=null;
if(dr.ItemArray[8].ToString()!="")
{
stringimagePath=dr.ItemArray[8].ToString();
stringimageExtension=imagePath.Substring(imagePath.Length-4);
switch(imageExtension)
{
case".ico":
System.Drawing.IcontempIcon=newSystem.Drawing.Icon(rootDir+dr.ItemArray[8].ToString());
ImageListtempImageList=newImageList();
tempImageList.Images.Add(tempIcon);
iconImage=tempImageList.Images[0];
break;
case".jpg":
iconImage=System.Drawing.Image.FromFile(rootDir+dr.ItemArray[8].ToString());
break;
default:
break;
}
}

Everything is possible, impossible just takes longer
ajliaks  Sunday, March 15, 2009 1:49 PM
Hi,

There is an example showing add the image to the menu items.

How to: Configure MenuStrip Check Margins and Image Margins

Hoping that could help you.

If i misunderstood you, or you have other questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Marked As Answer byajliaks Sunday, March 22, 2009 6:29 PM
  •  
Ling Wang  Sunday, March 22, 2009 2:59 PM
I did it this way:
System.Drawing.ImageiconImage=null;
if(dr.ItemArray[8].ToString()!="")
{
stringimagePath=dr.ItemArray[8].ToString();
stringimageExtension=imagePath.Substring(imagePath.Length-4);
switch(imageExtension)
{
case".ico":
System.Drawing.IcontempIcon=newSystem.Drawing.Icon(rootDir+dr.ItemArray[8].ToString());
ImageListtempImageList=newImageList();
tempImageList.Images.Add(tempIcon);
iconImage=tempImageList.Images[0];
break;
case".jpg":
iconImage=System.Drawing.Image.FromFile(rootDir+dr.ItemArray[8].ToString());
break;
default:
break;
}
}

Everything is possible, impossible just takes longer
ajliaks  Sunday, March 15, 2009 1:49 PM
Hi,

There is an example showing add the image to the menu items.

How to: Configure MenuStrip Check Margins and Image Margins

Hoping that could help you.

If i misunderstood you, or you have other questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Marked As Answer byajliaks Sunday, March 22, 2009 6:29 PM
  •  
Ling Wang  Sunday, March 22, 2009 2:59 PM
Thanks.
Everything is possible, impossible just takes longer
ajliaks  Sunday, March 22, 2009 6:25 PM

You can use google to search for other answers

Custom Search

More Threads

• Insufficient memory to continue the execution of the program.
• Menu Button (outside of a toolbar)
• single event to trigger multiple dynamically created controls
• Use of Custom Editor at run time
• ToolStrip Disappears
• Help with Custom Form Design(NicePanel ) Problems
• Need help
• ParentControlDesigner.OnDragDrop: BehaviorDataObject?
• Showing the selected rectangle in the Designer
• BUG?! Visual Studio .NET 2003: Why is a Modal Dialog destroyed?