Available class events C# - c#

in c# how can I get the available events of a class in order to begin programming code inside of it. I know that in form or usercontrol you can select the control and click the events button and click on the selected event to begin coding, but I mean a derived class which I want to code its methods or events.
Thanks!

The simplest way is to look in the documentation, to be honest.
If you're within the designer, your approach of using the properties window will work for other controls (buttons, textboxes etc) as well... and if you're in the IDE, you can type this. from any instance context (e.g. the constructor) and get a list of members up, including the events.
I would still suggest reading the documentation though - MSDN allows you to look at all members, or just the events (or methods, or whatever) at any one time. It's not terribly hard to peruse the list that way - and you can then check the details of the event so you can make sure you're using it properly, rather than just by guessing based on the name.
EDIT: As Aren mentions, there's also the Object Browser. Not my personal preference, but it's an option.

The events are listed in the IntelliSense popup window you'll get when you type the class reference variable name followed by a dot. They have a lightning bolt icon.
Many more organized ways to know what a class can do. You could read its documentation. Or browse its source code. Or use Reflector if there isn't any.

in Visual Studio 2010, they have got this new Help Library Manager where you can check for MSDN updates and download any updates or go to online directly. (you can also install Vendor API docs quite easily as well)

Related

How to programmatically add buttons to a window after Instantiation à la Revit API's TaskDialog class

I apologize if the question isn't as accurate to what I want, but I'm fairly new to coding any type of window/form without a visual element or robust IDE (currently don't have access to Visual Studio, but want to begin work on a GUI while I wait as I have a bulk of the driving code done). I've had a difficult time finding out if/how this is possible due to the wording of my queries so far being too similar to other topics, like enabling/disabling buttons.
What I want is to emulate the programmatic functionality of adding buttons to a window present in the Revit API TaskDialog class. For those unfamiliar, this is a sample of how one creates a TaskDialog with a basic message and two buttons in C#:
TaskDialog dialog = new TaskDialog("Sample");
dialog.MainContent = "This is an example of how a TaskDialog is coded in the Revit API";
dialog.CommonButtons = TaskDialogCommonButtons.OK | TaskDialogCommonButtons.Close;
dialog.DefaultButton = TaskDialogResult.Close; // optional, will default to first button in box if unassigned
TaskDialogResult response = test.Show();
This type of framework would then be used on a window/form/user control that's used by multiple different modules, each with slightly different UI needs. Most modules will need a list box and Confirm/OK and Cancel buttons as a basis, but some will need additional buttons for additional functionality within the window.
If this functionality is better done in WinForms, I'm open to moving my GUI to that platform, I have interacted with both in the past and am somewhat familiar with the flow of each, just not the more advanced topics yet. This said, the data binding is an important feature for me, so wpf is preferred.
Any input would be greatly appreciated!
Edit
So, after some more digging around, I think I have a better understanding of how to ask my question:
What I want is the ability to programmatically add buttons (not RadioButtons like in this solution) to a window (wpf or winforms) by setting a variable in using the constructed window instance in the main code, passing it values from an enum with [Flags]. I want to have defined, common buttons (e.g. OK, Cancel, Close, etc) whose information and enum for adding to my window are in a module. I can then access these buttons through their enum, as Revit API allows with the TaskDialogCommonButtons enum, and assign them to a property of the window (in my example that would be the TaskDialog.CommonButtons property). This would then tell the window to show these buttons and none of the other buttons contained within the enum.
Unfortunately, the only results I get are how to data bind RadioButtons (not regular Buttons) that are then explicitly created within, or hard coded into, the xaml or codebehind of a window class and not dynamically added after the custom window class has been instantiated from the main code. This is clearly possible, otherwise the Revit API would not work in the way it does, but I can't seem to find anything relating to how or why it works and how to duplicate it.
Is simply a matter of including all of these buttons as hidden in the window class and using the enum to set the window instance's button visibility to show/true, thereby granting UI access? Or is it actually possible to add buttons programmatically from the driving code (not the codebehind of the window) using an enum?

Add custom editor windows to Visual Studio window panes

My Problem
I'm trying to build an extension to Visual Studio that allows code to be edited on a per-function basis, rather than a per-file basis. I'm basically attempting to display code in a similar fashion to Microsoft Debugger Canvas.
I'm wondering how to host multiple Visual Studio editors within a single window (I believe the windows are implementing IVsWindowFrame). The functionality I'm after can be seen below:
Each editor window retains typical functionality and interacts with third-party extensions as expected. (For example, VsVim functions correctly within these windows).
What I've Tried
I've spent almost two weeks researching and trying this stuff and I'm having a lot of trouble figuring out which services, interfaces and classes I'm going to be using.
Reading through MSDN
First off, most of the documentation discusses how to edit a single editor window and add adornments, tags, margins etc. It doesn't discuss the possibility of spawning multiple editors within a window pane.
I've looked through the documentation on a vast number of interfaces of interest to me including IVsTextBuffer, IVsTextView and IVsInvisibleEditor. Unfortunately I can't get some of these interfaces to play nicely together.
On top this, the usually excellent MSDN is extremely lacking in this area. Many of the interfaces contain only a list of members without even a basic remark on intended use and functional. (IComponentModel, for example).
Many of the interfaces make reference to a set of Editor Samples but the code cannot be read or downloaded on MSDN. Apparently it shipped with Visual Studio 2005, but I don't have this version of Visual Studio, nor can I find it.
Interacting with IVsUIShell
I can get access to all WindowFrames open using IVsUIShell.GetDocumentWindowEnum();
I see there is an IVsUiShell.CreateDocumentWindow() method, but I'm completely unfamiliar with the parameters it accepts, or if this is the correct path to go down.
What I need to do
Programatically create a dockable window pane
Programatically add editors to this window pane. (And ensure they're correctly registered within Visual Studio, the running document table, etc.)
Edit:
I'm sorry, I should have expanded on my steps. When I said I needed to register with the running document table and Visual Studio, it's because I want to actually edit the original document in my custom editor. Below is a short example of the functionality available in Debugger Canvas that I'm trying to recreate:
http://i.imgur.com/aYm8A5E.gif (I can't embed a .gif)
Alternatively:
If anyone knows where I can find the editor samples included with Visual Studio 2005 such as the Basic Editor Sample I'm sure I could figure this stuff out. The MSDN documentation has no code samples regarding these interfaces, which has made my job extremely difficult.
The Git Source Control Provider is an open source extension includes a tool pane that embeds a standard editor as a control within a custom WPF tool window. I would use this code as a reference for any Visual Studio 2010+ extension where I wanted to host an editor window in some custom location.
PendingChangesView.xaml includes a ContentControl named DiffEditor, the content of which will be the editor.
PendingChangesView.xaml.cs includes a method ShowFile, which calls a method to create the editor control and assigns the result as the content of DiffEditor.
ToolWindowWithEditor.cs includes a method SetDisplayedFile which returns a Tuple<Control, IVsTextView> interface, which provides access to a Control that can be added to a ContentControl as well as the IVsTextView for the text view. The heavy lifting is in this method.
Note that the SetDisplayedFile method includes several lines with the following form:
textViewHost.TextView.Options.SetOptionValue({name}, {value});
These lines perform key functionality for the Git Source Control Provider such as removing margins and making the window read only. There are many options available, so you'll want to review the documentation for DefaultTextViewOptions and DefaultTextViewHostOptions to apply the ones appropriate for your particular extension.
I haven't actually looked at the files that #280Z28 (why this username?) posted. I used to work on the Visual Studio editor and what you are trying to do has multiple facets to it that you should tackle independently:
Hosting multiple command targets inside a single IVsWindowFrame (this means that you'll have different elements inside the same pane from the point of view of Visual Studio's shell, and each of them need to have their own command handling. Consider the case where you put your caret in one of the mini-editors and want to undo using Ctrl+Z, moments later, you then place your caret into another mini-editor and do the same. Even though the WPF and Win32 focus have remained inside the same window frame (from the point of view of the Visual Studio Shell), the commands need to be routed to different components.
Using editor's that are displaying parts of another document. The mechanisms here that will be your friend are in the projection namespace. Projection essentially allows you to project a piece of buffer (or buffers) into a view. Ellision buffers are special case projection buffers that project from one source buffer into a target view while hiding areas of the buffer (this is most likely what you want). An example of a projection buffer is what happens inside a cshtml file. In that case, there is one buffer containing all the C# code, one buffer containing all the javascript, and one buffer containing the html and each compiler works off of that buffer, but the end user sees a projection of all these buffers into the editor's view with only relevant parts displayed (for example C# import statements are elided even though they exist in the real C# buffer.)
Managing the running document so that when an edit is made in a mini-editor, the real document is dirtied. You need to handle cases where the parent file is already open in the RDT in which case you want to dirty the same document when changes are made, and also cases where the document is not open, in which case you need to create a new entry in the RDT.
Also, please post to the Visual Studio forums, there are people who regularly check the forums and route the questions to corresponding devs.
Generally speaking, when it comes to the editor, avoid any traditional interfaces (anything that does not use MEF), so samples from Visual Studio 2005 should not be used as a reference point.
If you care enough and are in Seattle, you can try to go to campus as an MVP. There are days where you come to campus, and members of varying team will grab a laptop and come to your conference room and you can debug code together or hack away (while having access to debugging symbols and what not).
Last but not least, contact the code canvas guys, I'm sure they've solved many of the problems you are facing.
You need to register a tool window with your package extension; this can be done via the ProvideToolWindow attribute. The following article contains all the required information on how an editor can be hosted in a tool window: http://bit.ly/9VWxPR
Take a look at the WpfTextViewHost class; the article explains that this type is actually an UIElement, so I imagine that it´s possible to host multiple instances of it...

Visual studio 2010 showing available events from code behind

In work and in home I have VS2010 installed. But in work I have this one cool feature. On the code behind file I have two drop downs. When I select some object in the left one lets say a testButton or Default2 (a page class), on the right one I get all available events for that object and when I select an event Visual Studio autogenerates it in my code-behind file. In my home VS I actually have does 2 drop downs but they work different. I have available objects on the right one but when I select for example the testButton it shows me the aspx page and points this button :/ Should I set sommething in the VS configuration or maybe in work I have some addon which I'm not aware of? Any ideas?
This is not a VB-exclusive feature.
What you're looking for is called a navigation bar. In Visual Studio options, open Text Editor → C# → General, and you'll see an option called Navigation Bar. Enable it and click OK.
However, I believe this bar works a bit differently in VB and in C#. In C#, it only lists the existing classes and their methods; in VB, it will list all your controls and their events even if those don't exist yet.
Ok I think I've found the answer. It seems that this feature is only available when the current file is in VB.Net. In my opinion this suks :/
You need to go the design view, in the Properties box, click on Events (lighting bolt) and double click on the events you want to code behind:
(source: byte.net)
#shin is correct, this is a VB.NET only feature; Microsoft only had feedback reports dating back to 2004 mentioning this feature, so I have opened a new bug request with Microsoft regarding this; and also added feedback to Visual Studios account on UserVoice...
https://connect.microsoft.com/VisualStudio/feedback/details/688175/vs2010-c-add-page-event-handlers-to-asp-net-using-codebehind-navigation-bar-the-same-way-as-in-vb-net
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2244558-allow-c-to-add-event-handlers-to-classes-using-co
I encourage everyone who this issue effects to go and vote up & confirm this issue with them.
I dislike that C# doesn't provide such a useful time-saving function.
Up to Visual Studio 2010, only Vb.net has this feature: on code-behind page, the code panel upper-left drop down shows a control's name, and the right drop down shows this control's available events. When clicking this event we can get the code-block for this event. This feature is not available in C#.
Without above feature, we can still get a control's available events for both C# and Vb.net: We must select the control on the aspx page and choose the design view at the lower left corner, then on the Properties panel click the Event button (the lighting sign), then available actions will be shown, double-click the name of the event you want, the event code will be generated in code-behind.
It is most certainly is a VB only feature and has been reported on numerous occassions to Microsoft.
It is possible to see all the available Events in C# & Asp.net too, but not inside code window as possible in VB. But you can see all Events of any selected Control in its Property Window. Open Properties, then Click Events.
This and the feature to generate event handlers without having to switch to Design view for C# is finally coming in Visual Studio 2012. It was about time.
Even the 2012 feature is not enough. You still have to guess for Page level events (Init, PreRender, etc) and also files that haven't already been filled out for you like Global.asax, which depending on the template you started with may or may not have all the event handlers already specified.
Agreed that Event Handlers is one of the things VB has for years and years and years handled way better than C#. I can't count the number of times I've had to remind a fellow C# developer that some events do, in fact, exist.

Getting the right window of "CtrlNotifySink"

I tried to get a hold on the icons of any folder, by going down this window tree:
CabinetWClass
ShellTabWindowClass
DUIViewWndClassName
DirectUIHWND
CtrlNotifySink
SHELLDLL_DefView
DirectUIHWND
however, I am stuck in DirectUIHWND, because there are more than one child with the class name "CtrlNotifySink".
I need to get a hold on a specific "CtrlNotifySink".. the one that have the child "SHELLDLL_DefView".
how can I do it?
Thanks,
Aviad S.
You might be going about this the wrong way.
If you want to find out what folder windows the user has open, and look at the items within them, take a look at the scriptable shell objects. The examples on MSDN are mainly in VB and Javascript, but the approach applies to C# as well.

C# UserControl Inheritance

Working with VS.NET 2008, output type Class Library, Target Framework .NET 2.0
I've come up with a simplified scenario to ask this question.
I have a Button user control, its a simple panel with a single big button on it.
I want to create a RedButton control that extends Button, and similarly, a GreenButton.e.g. Class RedButton : Button
Ideally, when I open up RedButton's designer I will see the button that I created in Button and be able to modify it, for example make it Red, or change font, etc.
I've tried to do this once, but when I open up the RedButton's designer I just get a bunch of errors.
In this case, doing all this work programatically isn't an option for us, as in the real case this would be a pain.
Could someone shed some light on this?
Thanks Very Much.
Truthfully, your example should work just fine. Just ensure that you provide a default constructor for your derived class. Also ensure that you do not use generic controls as the designer will have no clue how to create an instance of it.
Is your assembly setup to be delay signed? Look for the delay signing attribute as well as the checkbox in project properties. I've seen delay signing cause this sort of problem with VS2005 perhaps its still a problem in VS2008.
I had to deal with this problem for years at an old company. I researched it a little back then. I don't think that there is a solution for this.
I don't know how much you want to extend the base class in your real example, but the changes you mentioned in your example would be trivial. Just something like
btnTheButton.BackGround=Color.Red;
In reality, probably whatever changes you need to make to button could be done in a few minutes. It is unfortunate that this will be a few minutes everytime you need to inherit a new control, but I think it's the only option
If the control you inherit from is from a DLL and not just another class in the solution, then your designer will render the inherited control properly. My guess is that the VS Design View needs the DLL to draw the control. There may be other ways around this as well.
Since VS.NET 2008 the root designer is able to present "bunch of errors" as you mentioned. In general the described scenario should “just work”.
What kind of errors are you facing?
Follow this example if you aren't already:
public class RedButton : Button
then in the XAML instead of
<UserControl></UserControl>
Start/end your XAML file with
<Button></Button>
Note that it is okay to inherit from something in another namespace even though you didn't define the namespace yet. Example:
<radDock:RadPane ...
xmlns:radDock="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking"
...
Title="{Binding Path=StudyTitle}"...

Categories