Before going much further i'll mention I have tried solutions in following:
How do I set the icon for my application in visual studio 2008?
Set application icon from resources in VS 05
I am trying to set an icon for my application.
AFAIK, I need potentially 3 images?
1 image is the actual image in explorer when clicking on the .exe (thumbnail for the exe)
1 image (tiny) in the top left corner (16 x 16? Not entirely sure)
1 image in the start menu dock, to the left of the app (maybe 32x32? again not sure)
So thats fine.
Now I have selected an Icon. How do I use it in one of above situations?
I have tried adding it in resources, nothing seems to happen. Following that first SO solution,
"First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon."
The resource view is empty, and I cannot right click in this view.
If I right click on the solution > properties > resources > I can add the icon image, but it doesn't show in either of the locations listed above. (or anywhere that I can see)
1) How do I set the application icon for a WPF Application?
Assuming you use VS Express and C#.
The icon is set in the project properties page. To open it right click on the project name in the solution explorer. in the page that opens, there is an Application tab, in this tab you can set the icon.
#742's answer works pretty well, but as outlined in the comments when running from the VS debugger the generic icon is still shown.
If you want to have your icon even when you're pressing F5, you can add in the Main Window:
<Window x:Class="myClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="./Resources/Icon/myIcon.png">
where you indicate the path to your icon (the icon can be *.png, *.ico.)
(Note you will still need to set the Application Icon or it'll still be the default in Explorer).
Note: (replace file.ico with your actual icon filename)
Add the icon to the project with build action of "Resource".
In the Project Properties, set the Application Icon to file.ico
In the main Window XAML set: Icon=".\file.ico" on the Window
After getting a XamlParseException with message: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' with the given solutions, setting the icon programmatically worked for me. This is how I did it:
Put the icon in a folder <icon_path> in the project directory
Mimic the folder path <icon_path> in the solution
Add a new item (your icon) in the solution folder you created
Add the following code in the WPF window's code behind:
Icon = new BitmapImage(new Uri("<icon_path>", UriKind.Relative));
Please inform me if you have any difficulties implementing this solution so I can help.
You can try this also:
private void Page_Loaded_1(object sender, RoutedEventArgs e)
{
Uri iconUri = new Uri(#"C:\Apps\R&D\WPFNavigation\WPFNavigation\Images\airport.ico", UriKind.RelativeOrAbsolute);
(this.Parent as Window).Icon = BitmapFrame.Create(iconUri);
}
Related
I have an old legacy system that uses Winforms and is published with the built in One click,
I look after 3 different installs and each one has its own database it connects to, so its been set up that when a different system is click, it check isCompany1 and will set the Favicon accordingly
so when depoyment is done in the application window the Icon and Manifest is set to the correct ICO, when installed the .exe icon will be what is set there,
However i am trying to bring these all inline as when we debug a drop asks which database we would like to connect to, and depending on that it will set things up differently.
When running in VS the icons in the taskbar will change accoring to the dynamic Favicon however when its depolyed with this new selection it wont change, (it will change once on first load, then wont again)
The issue is some users need access to the different instances so would like different icons at the bottom, but its not changing the task menu, but everything else such as ALT-TAB and the control panel icon is changing,
all forms link into a baseform and call this :
if (App.IsCompany1)
{
this.Icon = new Icon("Resources\\Company1.ico");
}
else if (App.Company2)
{
this.Icon = new Icon("Resources\\Company2.ico");
}
else if (App.Company3)
{
this.Icon = new Icon("Resources\\Company3.ico");
}
AS i said this will change everything but not the Taskbar, but will from VS debugging,
I have made sure the .ico has all sizes, by writing their sizes on each one, and they display correctly the Taskbar and ALT-TAB both use 32x32
If it's any consolation, I couldn't reproduce your complaint.
I put 3 icons in resources, a single button on a form, this code:
private int iconum = 0;
private Icon[] icons = new[] { Properties.Resources.icon1, Properties.Resources.icon2, Properties.Resources.icon3 };
private void button1_Click(object sender, EventArgs e)
{
this.Icon = icons[iconum++ % icons.Length];
}
And it cycled through the icons in the main form title bar and the windows task bar over and over on every button click (made sure to run a release built exe too, not a debug start):
Note: the thing in the top right is my taskbar
I'm setting the HKEY_CLASSES_ROOT\.ext\DefaultIcon to the path of my application and it works...for the most part.
// create the HKEY_CLASSES_ROOT\extension
RegistryKey k = Registry.ClassesRoot.CreateSubKey(".spr");
k.SetValue("", "SpaceRead"); // set the default to the program name
RegistryKey di = k.CreateSubKey("DefaultIcon");
di.SetValue("", Application.ExecutablePath);
di.Close();
k.Close();
My problem is that my icon is showing up 'inside a white page' instead of only showing my icon (and losing the page)
here's an example. The first icon is mine, the second one is what I want.
My .ico file has all the standard resolutions in it, but I don't think that's the problem since even small icon views show the 'page' background.
Is there some custom icon rendering going on that I don't know about?
BTW, this is a Windows 7 x64 machine.
I created ContextMenuStrip for my tray icon, and i learned how to add new options there, how to add icons, how to mark them as checked, and how to change whole Context Background.
The thing is i dont know 2 things i would love to learn.
1.How to force newly created options to "continue" background of main Context menu, so they would show rest/same photo?
I created these marked items in code, when adding new folders in my program, folders names are added there as a groups.
2.How to change the look of ContextMenu completly. Is it possible in Visual Studio c#? Any tutorials? (i mean that program name on the left side of menu for example)
Example:
Image to example tray menu
EDIT: I use that do add items under "Grupy":
ToolStripItem item = (contextMenuStrip1.Items[2] as ToolStripMenuItem).DropDownItems.Add("" + Path.GetFileName(#"" + folderBrowserDialog1.SelectedPath));
item.Click += new EventHandler(item_Click);
Right now, my XAP file has become big and i need a solution to partition it into some smaller applications. MEF or PRISM might fix my problem
I read and watch online tutorial for them but still have no clue how i can apply them to my current project.
Let me explain my project:
-In the mainpage.xaml, it only has ONE menucontrol . However, that menucontrol will be built DYnamically basing on the data retrieved through the service call. You can see on my Menu picture
http://www.flickr.com/photos/31396433#N08/sets/72157627077751863/
-Everytime a user click on a menuItem, a window of that menuItem will be pop-up to let the user doing business work. You can see on my GeneralLedger_JournalPosting picture. The journalPosting menuItem belong to the GeneralLedger section.
http://www.flickr.com/photos/31396433#N08/sets/72157627077751863/
This is the code of showing how i show the pop-up menuItem window through the click event of the menuItem on the menuControl
private void MenuItemClick(object sender, RadRoutedEventArgs args)
{
RadMenuItem item = args.OriginalSource as RadMenuItem;
SFMenu sFMenu = item.Header as SFMenu;
OpenMenuItemScreenBy(sFMenu.Name);
}
private void OpenMenuItemScreenBy(string menuName)
{
if (menuName == "User Management")
{
var userManagement = new UserManagement();
//userManagement.WindowStartupLocation = WindowStartupLocation.Manual;
userManagement.Top = 50;
userManagement.Show();
}
//Testing area
else if (menuName == "Testing")
{
Testing t = new Testing();
t.Top = 50;
t.Show();
}
//
......
.......
That's all about my project. Basically, i just need to create different screen for each of my menuItem. Because the number of my menuItems continue to increase so the more corresponding window screen should be created. And that makes my XAP become bigger.
Solution:
I am thinking a way to seperate each of my Window MenuItem screen (such as the GeneralLedger_JournalPosting) into seperate XAP. And my main XAP file will only contains the menuControl.
However, I need to know a way how to load my corresponding menuItem XAP file on the fly if the user click on a menuItem(for example GeneralLedger / JournalPosting). And open the JournalPosting screen
But if the user click on that menuItem again, then no download needed. Just look at on the cache
(I watch MEF tutorial and know that i need to use the DeloymentCatalog for the feature. However, i don't see any example to let us manually access through code the usercontrol in the dynamic XAP file)
Secondly,
Because each of my menuItem window screen will use the same third-party dll (for example: the dll for the GridView, Navigation,...). So can you also tell me how to let me only download those dll ONE time . Because if i put those dll into each of my menuItem window screen XAP, then i think they will be redownloaded every time the corresponding XAP requested for downloading
thank you for your help.
have a look here: http://www.codeproject.com/KB/silverlight/MEFDynamicLoading.aspx. This project describes how to load xap's on demand and displaying them after downloading.
The interesting part for you is the MainPageModel.cs. There is the loading of the xap and putting the content into the panel.So if you ask the DeploymentCatalogService to "AddXap" and it is already loaded => call the callback or fire the event.
Regarding the dll's. You have to put them in your MainApp. In you downloaded app's you have to set the in the MainApp defined dll's to CopyLocal = false (It is found in the Properties of the dll (References))
I hope this helps!
BR,
TJ
I am developing an application called WeatherBar. Its main functionality is based on its interaction with the Windows 7 taskbar — it changes the icon depending on the weather conditions in a specific location.
The icons I am using in the application are all stored in a compiled native resource file (.res) — I am using it instead of the embedded resource manifest for icons only. By default, I modify the Icon property of the main form to change the icons accordingly and it works fine, as long as the icon is not pinned to the taskbar. When it gets pinned, the icon in the taskbar automatically switches to the default one for the executable (with index 0 in the resource file).
After doing a little bit of research, I figured that a way to change the icon would be changing the shortcut icon (as all pinned applications are actually shortcuts stored in the user folder). But it didn't work.
I assume that I need to change the icon for the executable, and therefore use UpdateResource, but I am not entirely sure about this. My executable is not digitally signed, so it shouldn't be an issue modifying it.
What would be the way to solve this issue?
If you want to do this programatically, I would start by looking at the Portable Executable file format (Wikipedia entry). The resources section (.rsrc, see section 6.9) should contain the icon. Using this information, you can write a tool to modify the icon.
If you just want to quickly change an icon in an existing file, you might be able to hack it up in the Visual Studio resource editor. I tested this with a file by deleting the old icon and adding a new one. The .exe icon changed in Explorer to the new icon, and the new icon appeared on the Start menu when I dragged it there.
-- Edit --
Yes, I agree that using UpdateResource is a good approach. Here is an example I found of using C++ functions to do so, and a P/Invoke signature for UpdateResource and FindResource.
private void button1_Click(object sender, EventArgs e)
{
String path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
String name = "test";
Shell32.Shell shl = new Shell32.ShellClass();
// Optional code to create the shortcut
System.IO.StreamWriter sw = new System.IO.StreamWriter(path + #"\" + name + ".lnk", false);
sw.Close();
// End optional code
Shell32.Folder dir = shl.NameSpace(path);
Shell32.FolderItem itm = dir.Items().Item(name + ".lnk");
Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
// Optional code to create the shortcut
lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System)
+ #"\notepad.exe";
lnk.Description = "nobugz was here";
lnk.Arguments = #"c:\sample.txt";
lnk.WorkingDirectory = #"c:\";
// End optional code
lnk.SetIconLocation(Environment.GetFolderPath(Environment.SpecialFolder.System)
+ "cmd.exe", 1);
lnk.Save(null);
}
This was taken from http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/9e23a82c-8bed-4b96-8b9a-4c2b6136a622/
It may help.
I decided to implement a workaround - the icon will change in the thumbnail for the window (it is possible in Windows 7). If the icon is unpinned, the user can see the icon changing. In case it is pinned, the thumbnail will change according to the current weather conditions.
Seems to me like the structure of pinned icons (being a shortcut, in fact) doesn't allow dynamic icon change. If I am wrong, I am open for comments and ideas on this.