Is it possible to add custom buttons (or) User defined buttons inside Message Box in Visual Studio Windows Forms application ?
Here's a quick guide to making a custom dialog box, which is going to be the ideal solution for you in this scenario, in my opinion.
The simple answer is: no it's not.
The long answer is that it's not possible using the managed API but it may be possible using the Win32 API. Here's a good tutorial on using Windows Hooks to customize the operating system message box dialog.
The .net MessageBox class does not offer such functionality. However, the native Win32 API does so through the TaskDialog API. The main advantage of this approach, as opposed to writing a custom dialog, is that you will be using a native system component and so your dialog will feel at home on the platform.
A very simple example of the task dialog looks like this:
And there is lots of scope for much more complexity, as is explained in the link above.
You'll need to p/invoke to this function. It's one of the more messy functions to call so expect a little work before you have a working solution. You can find some C# code to wrap it up here, but I can't say that I personally have experience of this.
Related
I want to make a menubar like window taskbar in C# but I'm wondering how can I make the form stay on the top of the screen and other program will not taped over it just like the window taskbar and when the mouse hover on a icon it will show a form like this:
I have made it like this:
And This is what I want
Windows has a facility for this, allowing you to basically create pseudo-taskbars that dock to the side of the screen and are always visible. It was used by the Office team (possibly publically documented for the Office team?) a long, long time ago to create a desktop toolbar.
Anyway, they are called Application Desktop Toolbars (or "AppBars"), and the documentation is here. To register one, you call the SHAppBarMessage function with the ABM_NEW message. Complete sample code is available in the linked documentation, unfortunately it is in C++.
To use this from a C# application, you will have to P/Invoke. As far as I know, it is not wrapped by the .NET Framework anywhere, probably because it never gets used by anyone anymore. This CodeProject article appears to have the necessary P/Invoke definitions written out. I can't vouch for their correctness, but armed with the documentation and that as an example, you should be able to cook up a working demo.
There is another CodeProject article here, written by Arik Poznanski as part of a series on using shell features from C#. It looks much more thorough, probably more than you need.
Set the property Form.TopMost unless you have other programs creating topmost windows. Doh!
At a broader level, I'm converting a MFC application (MFC 6.0) into Windows Forms application (Visual Studio 2013). I read certain blogs that describes that this conversion is possible. By this conversion I can re-use code written in MFC, only I will need to create UI. However I will need to understand the previous code and may need to re-write it a bit.
I got the motivation from here and here.
I have performed following steps so far.
Opened Visual C++ 6.0 project in Visual Studio 2013.
Build it successfully.
Then added CLR support to it, and fixed errors.
Added a Windows form, and added controls to it. As mentioned here.
Added functionality and build it successfully.
Now when I run this application, then it still point to old MFC window.
I'm missing certain settings which will change the rendering window from MFC to WindowsForm. What am I missing here?
Addition to that, I see problem with this approach as described by #Roger in comments, and I understand that. So, I wanted to know for any tool/utility which may convert legacy code into C#. Does such utility available?
TIA.
The code you are referring to seems suitable for amending a MFC application with a few forms as child windows to make use of .NET features. However, the main window is another story. You wrote the application is huge, so I suppose you don't want a simple form as your main window and rather have some kind of MDI interface in mind. If you replace the CMainFrame in the legacy MFC application, it just doesn't make sense to maintain an old CWinApp class. Anyway, if you are hell-bent on going down that path, you may want to have a look at an old CodeProject articel (.NET1.x, .NET2.x) to get a better grasp at the whole concept.
But as Roger already suggested, it would be a wise choice to find a nice GUI framework, perhaps even WPF instead of WindowsForms, and do a GUI rewrite -- especially if one part of the motivation for the conversion is to move to newer UI concepts. If your C++ program logic is well separated in your MFC project, put it in a COM server and make use of interoperability.
I have this WPF app and I want to have there function of getting a directory path from the user. I would like to use some folder browser dialog but I don't want to implement it from System.Windows.Forms or use some huge script inside. Is there some path getting dialog in WPF already implemented?
I have read answers to similar questions here but it was full of System.Windows.Forms..
I haven't found anything like that in the Toolbox and I'm starting with WPF so I could use some help.
Thank you in advance :]
See my answer to Select folder dialog WPF. Basically the Windows Presentation Foundation 4.5 Cookbook recommends that you use the Windows® API Code Pack for Microsoft® .NET Framework if you need a folder browser.
we use Ookii Dialogs in our projects. They have the windows-look and feel and the typical options for filtering etc.
There are no standard native WPF dialogs for what you are looking for, simply because the System.Windows.Forms dialogs are nothing more than wrappers to the system ones. So creating a WPF wrapper makes no sense and will only add to the confusion.
The Ookii Dialogs for WPF library has a VistaFolderBrowserDialog class that provides a complete implementation of a folder browser dialog for WPF.
https://github.com/augustoproiete/ookii-dialogs-wpf
There's also a version compatible with Windows Forms apps
I want to access the objects and their properties in a similar way to how automation tools access them in their "UI Map" functionality. I'm assuming there's an assembly reference that will give access to running processes and whatever objects exist for that process.
Specifically, I need to access a few label control text properties in another running application.
Also, sorry if this is a duplicate - I looked around, but I'm not sure what keywords would get me to what I need.
This is not a common practice in C#. The term that you are looking for is to "spy" another window/application/process. There are several resources here in StackOverflow talking about this. For example:
How can I get functionality similar to Spy++ in my C# app?
To access a control in another Win32 form you need to look for the handle of that element.
For WPF applications, the UI Automation libraries present in .NET 4.5 make this way simpler: http://msdn.microsoft.com/en-us/library/ms747327.aspx
For older winforms applications, you'll have to actually utilize pInvoke on the User32 API. The example link Pete gave you in the comment on your question will help guide you in that direction: http://www.pinvoke.net/default.aspx/user32.enumwindows
How does Visual Studio and other similar programs display a form in their IDE?
Is it possible to achieve the same or a similar effect using C# or VB.NET?
Please see the picture below to get what I mean.
If you are talking about hosting a Winforms editor in your code, it is entirely possible and is actually built in to the .NET framework!
The Essence is the IDesignerHost interface. The whole system is complicated, but can be done (I have done it in production code for runtime layout configuration editing). There is a sample of code from Microsoft here.
I'm sure if you search fir 'IDesignerHost' you'll find enough reference material to figure it out.
Are you speaking about UI creating tools?
Refer to http://www.icsharpcode.net/opensource/sd/ - SharpDevelop for deep dive. It's open sourse, so you'll be able to find out more details.
I believe what you want is a multiple document interface (MDI) see http://msdn.microsoft.com/en-us/library/ms973874.aspx for more info.