C# GUI access
-
Hi
I don’t know about you guys but I love to create new GUIs using windows forms and C#. I made my plugin GUI for NP++ using forms.
But what about the rest of the official GUI NP++ has, can it be accessed through C#? So you could fill the function list or use project window via C#.is it possible?
thx!
-
In general yes, all ui elements can be accessed via the SendMessage api, but most of the time I would say this is not a good idea if you want to be in sync with Npps view of these ui elements, as no official apis are available, meaning that any changes you make will, probably, not reach Npp which will surely lead to instability sooner or later.
-
ok so its not possible to edit the UI via C# classes but have to use SendMessage. maybe I just use the project view that way
-
In my experience, if Notepad++ doesn’t explicitly allow plugins to edit a GUI element via an
NPPM_*
notification, it is probably a bad idea to edit that GUI element.For example, it’s possible for plugins to add their menu to the Notepad++ main menu rather than being a submenu of the Plugins menu (using native Win32 APIs), but if you do that, the names of the main menu items will get messed up when you change your native language preference. On the other hand, Notepad++ gives a formal way to edit the status bar using
NPPM_SETSTATUSBAR
, so this can be edited safely without side effects.You might think “Why reinvent the wheel? The project panel looks like the kind of GUI I want to use, so I’ll just hack that!” But Notepad++ is going to expect that the project panel has a very specific structure, and you should not be surprised to get crashes or weird behavior if your modifications don’t conform to the expected structure. Get ready to spend a lot of time staring at the most arcane parts of the Notepad++ codebase.
Speaking as an active C# plugin maintainer, I believe that native C# code is faster, easier to debug, and less likely to cause unexpected errors in Notepad++, compared to code that attempts to hack the Notepad++ GUI with the Win32 API.
-
Hey,
I experimented with and adapted some plugins in C# back then and still use some of them today. e.g. ‘CSharpRegexTools4Npp’ (can be found on github).
maybe it will help you. -
@myGitAlex regex? sorry i dont follow
-
@myGitAlex regex? sorry i dont follow
@myGitAlex is probably talking about this: https://github.com/codingseb/CSharpRegexTools4Npp
Brand new users can’t post hyperlinks in the forum; it’s a privilege they have to earn.
-
@rdipardo I mean I dont understand what regex has to do with this topic but maybe i just don’t understand regex and N++ that well
-
My guess is that @myGitAlex thought that showing you another example of a GUI written in C# would be helpful – maybe assuming you were asking “how do I write any GUI for my plugin using C#”, not realizing you were asking for a very specific question about accessing specific parts of the native Notepad++ GUI from your plugin, even though they don’t have plugin API calls.