Collect the recently clicked 5 buttons in Word with VSTO C# - c#

Does anyone know how to collect the recently clicked 5 buttons, and save them to a new group in the Hometab for reusing? Using C# in VSTO.
It seems a simple thing, however, I find now way to dynamicly monitor the control event in the ribbon and get the ID.
Have searched for several weeks.
Thanks a lot if anyone can help.

Hmm I don't think it's possible or at least I don't know about any way how to do that.
First there is no way how to easily monitor which button was pressed by any API Microsoft provides. You know, there is no command there is called for every button where you can hook your code and listen. I know that out there are amazing tools that can help you with things I originally thought are impossible RubberDuck, Watch Dog, MZ Tools but first, they are mainly for VBA, second it's probably not easy solution that you are looking for.
You would probably have to - somehow - mimic Office ribbon by your own ribbon => way too much work, use one callback, monitor it and determine the last 5 buttons.
Then you would have to change the Home tab by changing the ribbon XML which has two drawbacks
1, I believe it's not possible adding/removing buttons dynamically (you can use callback to change visibility but for adding/removing there is probably nothing)
2, you would have to restart the Office application to see your changes
As you see I'm not entirely sure it's impossible but I do see it as way too much work.
Anyway I'd love to hear if there is a way how to do that, so please if you find any way do let me know. Thanks

Related

Is it possible to write a shell extensions that add a button in the windows file explorer? [duplicate]

As example, I want make simple resizer, where you can select image in explorer and set new dimensions.
It is not possible to modify the Windows Explorer 8 ribbon.
However, add-ins will not be able to plug into the ribbon UI. This was
a difficult engineering choice for us and we expect that many of you
will read this and suggest we add the capability--of course if we
could get it right this time around we would have done that. A big
part of this blog is sharing these choices--tradeoffs--between new
features and adding everything we can dream up and finishing. We also
think the customization we provide and the improvements are worthwhile
this time around.
From here.

What technology to use to write a modular C# desktop program?

Question:
Is there some effective way to hide some portions of the WinForm/WPF desktop program based on user settings/permissions?
Why I need this?
I'm starting a big accounting project which will contain hundreds of forms/dialogs.
The program is going to launch a main window which shows 1 to 4 divisions. The user selects each of those and it will then launch the a window which contains a sidebar with a bunch of buttons on sidebar (something like Microsoft Outlook). Now, when the user clicks on each of these buttons, it will open that section of the program and the user will work with that part. Based on the user permissions/settings, there's a need to sometimes hide some of these buttons though. For instance suppose I have 4 main divisions A, B, C and D. When you launch A, you'll get a sidebar containing A1, A2, ..., A100. A user might opt to see only A1 & A50!
Our initial approach was to use WinForms for this because the team was very familiar with it. I suspect that for doing so, we have to build some sort of model which contains information about user preferences and write lines of code like btnA1.Visible = false; a lot.
Frankly just thinking about doing that disgusts me. That's why I'm looking for a better way to achieve such result. I've searched around and found PRISM.
I'm not sure just yet but I think to use PRISM I need to make each of those buttons or their dialog a module and load them after I decide which of them is needed for the user.
It seems like a nice way to do this but considering the fact that this project is very urgent and we don't need to load different modules for different users (we just need to load them - ideally on demand - and sometimes hide some), I have some concerns:
My team might need some time to learn WPF
All of us don't know much about Unity and PRISM.
This might be overly complex, i.e. there might be a more simple way to achieve this without going into such lengths.
Also, I'm watching Prism & Silverlight Series and PRISM5 for WPF from Channel9.
a window which contains a sidebar with a bunch of buttons on sidebar (something like Microsoft Outlook). Now, when the user clicks on each of these buttons, it will open that section of the program and the user will work with that part.
That sounds to me like a TabControl. You'd rather not try to reinvent the wheel as it's already been invented.
The only difference between that example and your requirement is that instead of hard coding the tabs you're going to bind to a collection of ViewModels, like this, and then have each instance of TabViewModel toggle it's own IsVisible property depending on user permissions / user selections.
Simple as that. No need for complex MVVM frameworks. No need for silly obsolete useless winforms stuff.

Selecting an item from pop-up menu

I'm trying to make an application that will test some features of an existing app and I wanted it not to be window-size dependent and not to require focusing the window or etc.
I've already figured out how to get window handles for different controls in the tested app so I can click buttons, enter text to textboxes etc. with Send/Post Message but still got a few unsolved problems.
The first is selecting an item from a pop-up menu that can be triggered by button click (TAdvGlowMenuButton class) or right click somewhere- I can't even see any messages related to it in Spy++ so I have no idea how to do it, is it possible to select an item by name? as I don't have it's id
The second thing is clicking next to something, for example 10 pixels to the right of a button.
I have the button handle so I can get it's size and it's parent but I still don't know how to get it's position inside the parent - any ideas?:)
And also a quick one but I don't believe it is possible - can I somehow get position of a label in the tested app? I can't even see it in Spy++ .
I hope you can help me to find it out ;)
Edit: I forgot about the most important thing:P , I'd like to achieve it with Send/Post Message if only it is possible.
My recommendation would be to abandon the message sending/posting model altogether and instead use UI Automation. Automated testing tools is exactly what the UI Automation APIs were designed for, and they are much more capable than SendMessage/PostMessage.
Yes, I realize that this is exactly the opposite of the answer you were looking for. But you will have no end of trouble getting messages to do what you want. A fair number of them rely on the application having the focus, and it is completely reasonable for your code to make this assumption when you receive e.g. a WM_KEYDOWN message. A testing tool should not flag that as a bug.
I notice you've tagged this question with the C# and .NET tags. In that case, you may be interested to learn that the UI Automation APIs have been wrapped in the .NET Framework.

Click anywhere to type

I am interested in creating my very own control from scratch. (Yes, I know...) - here's what I was thinking, I'll only choose one of the following, but depending on the complexity, I think I am going to go with a TextBox or ComboBox:
TextBox
ComboBox
FormTyper
I made the third name up. FormTyper is simply a "way" of being able to click absolutely anywhere on the Form and just start typing, and the letters/numbers etc will appear as if you were typing in a textbox. This would be my ideal new project, I would love to do this, but I haven't seen it done before, and I'm not sure how to start.
Does anyone have any advice, suggestions, or really good, in-depth (but simple :P) tutorials/articles/code I can read up on/play around with?
Any help at all will be greatly appreciated.
Thanks :)
Jase
You picked the wrong kind of control to get started with. Making your own text editor from scratch is unreasonably hard. Seemingly simple things like displaying a caret requires pinvoking obscure api functions. Calculating where to show it inside of a string is very hard.
Pick an easier one to get started with. A calendar for example. Essential skills you'll learn is how to write your own OnPaint() method to give a control a visual appearance, how to do mouse hit testing and how to pick the right kind of events and properties to make the control useful in a program.

How can I create my own form designer?

I'm starting my first C# project, and I want to make a "form designer" (like the one in VS).
The idea is, there will be a visual form designer with a limited toolbox, which will generate Python code (later more) to create the same form.
Problem is, I have no idea how to even get started. First of all, I have the form designer in VS: how do I make a "form-within-a-form?"
Next... I have no idea how complicated this is going to be. I suppose I could just make little boxes appear beside each control created on the form when it is clicked, for resizing, and make a textbox appear on it when double clicked or something, to change the text in it... Things like this.
So another thing I would like to know is this:
I do have programming experience in C and C++, I've done PHP for a number of years and am starting with Python as of recently. I've generated forms dynamically in VB6. Given this experience, am I in way over my head with this project?
this looks like a really good place to start. It has a pretty good example to get you started. You can even download his source (registration required).
It sounds like you're aware it's non-trivial for a C# first-timer. If you keep it pretty simple, it sounds like you're heading in the right direction (although a web-based form designer might be easier).
SharpDevelop would be an example of a full-featured IDE that can be re-purposed, but that's way over the top.
Good luck!
For most people starting out in C#, this project would be too much. With your VB6 background, you may be able to pull it off, though.
Here's a hint: the Visual Studio Windows Forms designer draws controls on its surface - by asking the controls to draw themselves.

Categories

Resources