Using F1 Help (CHM format) With WPF - c#

I've been working on a WPF application for a while, and the time has come to attach the CHM format help document to it.
But alas! HelpProvider, the standard way to show CHM files in Winforms, has magically vanished and has no counterpart in WPF. I've been trying to use WindowsFormsHost to spawn a new control so I can actually display the help, but essentially it just grabs control of the entire UI.
A little more detail: I've got a menu item that I want to, when clicked, open up the CHM file.
First I set up the WindowsFormsHost...
host = new System.Windows.Forms.Integration.WindowsFormsHost();
helpForm = new System.Windows.Forms.Control();
host.Child = helpForm;
host.Visibility = System.Windows.Visibility.Hidden;
this.grid1.Children.Add(host);
hp = new System.Windows.Forms.HelpProvider();
hp.HelpNamespace = "Somehelpfile.chm";
hp.SetHelpNavigator(helpForm, System.Windows.Forms.HelpNavigator.TableOfContents);
And then I say, voila, reveal yourself.
private void Help_Click(object sender, RoutedEventArgs e)
{
host.Visibility = Visibility.Visible;
helpForm.Show();
hp.SetShowHelp(helpForm, true);
}
I'm not really sure of where to proceed from here. When I show the helpForm, it obscures / overrides the existing UI and all I get is a gray, empty WPF window with no help file.
Any takers?

If you include System.Windows.Forms.dll you can also do:
System.Windows.Forms.Help.ShowHelp(null, #"help.chm");
Also, there's an article here about adding a context sensitive help system to WPF.

Call me crazy, but couldn't you just do:
System.Diagnostics.Process.Start(#"C:\path-to-chm-file.chm");

I am trying out Easy Help with WPF, which also addresses context sensitive help based on key words. So far it seems good. All I need to do is get cracking and write some decent help!

You can use http://www.pinvoke.net/default.aspx/hhctrl.HtmlHelp to open chm help at specified topic and to have more control of how chm window shown.

How about using the Help class instead of opening the file externally

Related

Is there a way to use an already existing Window as StartUp in WPF?

i'm relatively new to WPF and i was tasked to convert an old winforms project into a wpf project.
I am using the function App_Startup as the start for the App and i already created a mainwindow for my GUI. Normally you would just do this in the startup:
void App_Startup(object sender, StartupEventArgs e)
{
MainWindow main = new MainWindow();
main.Show();
}
but this does not work for me because it shows a completely new mainwindow and ignores the one i already made. I understand the issue is that App_Startup happens before the mainwindow and its components even get initialized but there has to be a way i can jump into the mainwindow let it initialize itself and its components and make that the window i start in App_Startup, but I just don't know how to do that.
I'm sorry if this is a really easy to solve problem, but i just don't know how to solve it.
Also i'm sorry if the English sucks it is not my first language.
Thank you very much for your answers and help in advance.
Greetings from Germany
Edit:
I found my mistake! I accidentally set the whole content to one string and it looked like it created a new Window but it was the same window with overwritten content. 🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️
Thank you all for trying to help me, but in the end the problem was very different from what I had written in this question.
First, open your App.xaml, then change StartupUri to what you need.
for changing the startup form in WPF projects, open the App.XML file and change the StartupUri String with your new Window.
That should be the trick.
Greetings from Austria ✌

Globalizing application dynamically

In My application I have 2 Resource dictionaries (Spanish and English) that contains all strings of the application. In the main window I have a combobox from where the user can select their desired language. What I wanted to do is, when the user clicks on a specified language it should change the language of the entire application, not just the current window. I have searched here for a simple solution but couldn't find any. Can anyone suggest a way to achieve this?
Currently I use this way to change the current form's language
on the combobox selection changed event
private void Language_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ResourceDictionary dictionary = new ResourceDictionary();
string lang = e.AddedItems[0].ToString();
dictionary.Source = new Uri(#"/Resources/Languages/"+lang+".xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(dictionary);
}
PS: I don't want to close and re open the window to the changes to be applied
The WPF Localization Extension provides on-the-fly language changing without restarting the application.
Please note, that this approach uses *.resx-files for localization and not WPF specific ResourceDictionaries.
You can follow the common guides on the link above. Additionally, you can read through this guide.

How to create navigation inside program Form

Warning! This is noob question probably! Sorry in advance.
I'm learning C# (using MS Studio 2013) and I'm having hard time creating some kind of decent navigation in simple desktop program.
Basically what I want is this: MenuStrip with options like "calculate something", "Calculate somethingelse"... and other (that I can easily add later - like dynamic menu on a webpage). If you click first option inside the Form connected with the StripMenu you will get some controls that allows you to do something(like inputs on a webpage). If you click the second all these options will disappear and you will get a fresh set of controls where you can do somethingelse (simply another webpage to play with).
What is the best way to do it (I find it amazing hard to find out :) ). Only way I figured out (more from experience in js then tutorials) is to use show/hide like in javascript/html.
ExamplePanel.Visible = false;
ExampleOtherPanel.Visible = true;
But this doesn't seem right - I think it would be impossible to manage in bigger program (not only in code, but visual designer too - you can only fit that much Panels inside Form).
Any advice? Or at least a link to material where I can find out?
EDIT:
Finaly I gave up and used multiple Forms as sugested in answer.
private void MenuStripExample_Click_1(object sender, EventArgs e)
{
SomeForm SomeForm = new SomeForm();
this.Hide(); //Hide the main form before showing the secondary
SomeForm.ShowDialog(); //Show secondary form, code execution stop until SomeForm is closed
//this.Show(); //You may uncomment this if you want to have the previous Form to get back after you close new one
}
You normaly don't hide and show panels with different layouts. This is not a good design.
If you have complete different navigations/control sets, then create a new Form which is responsible for the control set.
If you don't want to use new Forms take a look at the TabControl.
You may also want to take a look at MDI-Container. You can use a Form as a MDI-Container and display various other Forms as child-elements inside of this container.

How to hide textboxes, labels and buttons C# WPF

I would like to hide several textboxes, a label and a button as soon as a button is clicked... however, for some reason, my code doesn't seem to cause this effect. Nothing appears to happen. I'm using WPF.
Here is my code:
private void doSomething_Click(object sender, RoutedEventArgs e)
{
Name.Visibility = Visibility.Hidden;
}
This code doesn't seem to work.. any ideas?
I believe Visibility.Collapsed is what you need and not Visibility.Hidden.
EDIT: Did you try follow up this code with UpdateLayout() method of parent element/component?
Your code seems to work fine, the "Signing in..." label appears after everything else disappear. I suggest you to just copy all your code from the .xaml.cs file and the .xaml file into a new project, but make sure you don't copy the first line"<Window x:Class="..." because it could generate an error if the class name isn't the same in the new project.
For the xaml code I suggest you not think the same as you design windows forms applications. WPF has the layout system, which re-orientates or re-sizes its elements when re-sizing the window. So you should not specify exact numbers in the margin property as if they where coordinates. Create a grid, create rows or columns for each element and then just set the horizontal or vertical alignment or margins. Think different than the old windows forms way.
I've run your code... and it's working great for me. I've not changed anything (except the variable names) so I guess it's a bug from VS.
As said nikolamm94 try to add this.UpdateLayout(); at the end of connect_Click it might help. I tried and it is still working fine. Or maybe create a new VS projet, it already worked for me a few times.
Sorry my answer is not the most helpful, I wanted to put a comment instead but I don't have enough reputation :/
Please refer: https://msdn.microsoft.com/en-us/library/ms748821(v=vs.85).aspx
Set to Visible: tb1.Visibility = System.Windows.Visibility.Visible;
Set to Hide: tb1.Visibility = System.Windows.Visibility.Hidden;
You can hide a textbox by going to properties->appearance->visibility, then setting it to "hidden"

Responding to HTML hyperlink clicks in a C# application

Question:
How can I detect and handle clicks on hyperlinks in a Windows.Forms.WebBrowser control in C#?
Background:
My C# application does not carry a centralised help file. Instead, all the pieces that make up the app are allowed to display their own little help topic. This was done because the application is merely a framework, and it's hundreds of little plug-ins that actually make it useful.
Each class can implement an interface which registers it with the help UI. All my help topics are html strings (but I'm not particularly wedded to that), many of which are created programmatically at runtime.
The problem is that these topics are all isolated. I'd very much like to be able to include a "See also" section which will open other help topics. But how can I handle hyperlink-clicks in a Windows.Forms.WebBrowser?
Much obliged,
David
If I understand correctly, you would like to override your hyperlink-clicks with your own Form or UI. Well, if that's the case, you put your code on the OnNavigating event of Web Browser and make e.Cancel = true so that it will not navigate the URL specified by your hyperlink.
some snippet:
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
SeeAlsoFrm seeAlso = new SeeAlso();
seeAlso.showDialog();
}
that is based on my understanding. :)=)

Categories