I am developing a paint like application. I want to change cursor at some instance. So, how can I use the custom cursor in metro app ?
I have found this
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Custom, uint id);
In above method, there is one enum for "Custom" cursor and the second argument is for resource ID. So how can I get that ?
The basic route to doing this:
Create your custom cursor and package it in a .res using a C++ Metro DLL
Take a note of your resource id by peeking into the resource.h file in the C++ project
In my project the resource number was 101 and I didn't adjust.
Add the .res to a CSharp XAML Metro project
Open your .csproj using a text editor
Inside the first property group add a section that points to your .res file
Switch out the cursor to the custom cursor using the function call you referenced, and the resource number you found by peeking at resource.h.
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Custom, 101);
I realize this is a lot. I posted a detailed step by step walk through on my blog at http://blogs.msdn.com/b/devfish/archive/2012/08/02/customcursors-in-windows-8-csharp-metro-applications.aspx . Hope this helps.
Related
This question already has answers here:
WPF - Import image as resource
(3 answers)
Closed 7 years ago.
I'm using VS2013. .NetFramework 3 . I'm writing a simple project like as image gallery.
I'm trying to add an JPEG image into Image Control. First I'm adding the test.jpg image as resource. Then I'm adding an Image Control on to Window. In the next step I'm selecting the image in "Source" property. The image displaying into design mode. All is ok. But when I'm running the project nothing displaying.
I searched in google and youtube. I founded some solutions but I haven't solution for my problem
(Sorry for ENG)
Here the code line
<Image Source="pack://siteoforigin:,,,/Resources/1.JPG" ... />
In order to simply display the image in WPF app, do the following:
1). In XAML, add:
<Image Name="imgName" Source="/ProjAssemblyName;component/RelativePathToImageFile" />
2). In Visual Studio IDE, select the image file and check its properties:
Build Action: Resources
Copy to Output Directory: Do Not Copy
Note: in most typical case the project Assembly name is the same as Default Namespace; check it in application property dialog. Also useful info pertinent to your case is included in the Microsoft reference (as pointed out by member #Clemens): https://msdn.microsoft.com/en-us/library/aa970069%28v=vs.110%29.aspx#Resource_File_Pack_URIs___Local_Assembly.).
Another option is to set the image Build Action property to EmbeddedResource and get the BitmapImage object corresponding to the image file programmatically like the following:
BitmapImage _bmpImage = new BitmapImage();
_bmpImage.BeginInit();
_bmpImage.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(String.Concat(ProjAssemblyName, ImgFile));
_bmpImage.EndInit();
This technique is useful if further image processing is considered.
Hope this may help. Kind regards,
I have a ListView that contains all images of the .jpg format from a given directory. It's filled by the codebehind using the following code:
DirectoryInfo folder = new DirectoryInfo(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + App.putanjaSlika);
FileInfo[] images = folder.GetFiles("*.jpg");
for (int i = 0; i<images.Length; ++i)
{
FileInfo img = images[i];
Thumbnails.Items.Add(new BitmapImage(new Uri(img.FullName)));
}
This works marvelously, but as you can see, the path is pretty much set in stone. What I need is some sort of a BrowseDirectoryDialog that can allow me to "open" a given directory, and use the located path as the argument for the first line of the above code.
I've found this question Open directory dialog and I like the Ookii.Dialogs solution, but perhaps even more the solution under the second answer. However, seeing as how that thread is 3.5 years old, I wanted to ask if a better solution came out, since I wasn't able to find any.
I published this folder browser dialog for WPF in 2011:
http://wpffolderbrowser.codeplex.com/
It is based on an MSDN example and full source code is provided, so you can adapt it as needed. I like it better than the solution mentioned in the linked post, because it displays the "new style" open folder dialog with Vista / Windows 7 look and feel, as opposed to the WinForms dialog which seems to be the same as in Windows 95.
Unfortunately there is no dialogs of WPF. So you have to use Winforms.
I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (in C#): add a small CheckBox to ask if the user wants to use the first or second set of tools.But I'm still not able to change the icons on the ApplicationBar. I tried removing the old ones, first with ApplicationBar.MenuItems.Remove(Button1); and then with ApplicationBar.Buttons.Remove(Button1);
but neither worked. I tried changing the .IconUri property of the button, but that gave me a NullReferenceException.
I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:
firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
firstAppBarButton.Text = "New Text";
firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.
You can't refer to the application buttons by name. Try:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?
The syntax above gave me a compile error. With some additional research, I got this to work for me:
ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);
I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (in C#): add a small CheckBox to ask if the user wants to use the first or second set of tools.But I'm still not able to change the icons on the ApplicationBar. I tried removing the old ones, first with ApplicationBar.MenuItems.Remove(Button1); and then with ApplicationBar.Buttons.Remove(Button1);
but neither worked. I tried changing the .IconUri property of the button, but that gave me a NullReferenceException.
I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:
firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
firstAppBarButton.Text = "New Text";
firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.
You can't refer to the application buttons by name. Try:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?
The syntax above gave me a compile error. With some additional research, I got this to work for me:
ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);
An existing process uses the Adobe Acrobat COM object AFormAutLib to open and fill form items. There are over 500 forms, and they all have a form field of type Button at the top. The method AFormAutLib.setButtonIcon is used to set the path of another PDF file to be used as the image on the button.
I am looking for an alternative. I have looked at iTextSharp, activePDF Tookit, and others, but have been unable to find anything that can replace this functionality.
Thanks in advance.
The solution was to use activePDF Toolkit in a different way...
APToolkitNET.FieldInfo myFI = aTK.FieldInfo(x.Key.ToString(),1);
aTK.PrintImage(logoPath, myFI.Left, myFI.Bottom, myFI.Width, myFI.Height, true, 1);
aTK.DeleteFormField(x.Key.ToString());
The button had the right location and dimensions, so the FieldInfo class is used to get those values. Then PrintImage is called with the path to the image and the locations, before the button is deleted.