I'd like to basically control the name of the method that the Visual Studio form designer uses for putting it's generated code in. By default, this is named InitializeComponent. But often times I need to have different layouts for different types of screen resolutions/aspect ratios (see Designing forms to work on different resolutions and aspect ratios on Windows CE for more detail). That way, at runtime I can choose how to layout the form by calling the appropriate one.
I realize that there is likely no trivial way to do this. I assume I'll need to build a custom VS add-in and extend the existing forms designer and hook into the code generator and layout interpreter for this to work properly. Any ideas on where I could start looking to make this happen?
Can you not switch within InitializeComponent and call different layout logic methods according to what platform you are?
if(platform.IsCE)
{
CELayout();
}
else if (platform.Tablet)
{
TabletLayout();
}
Related
I'm trying to learn about Windows Forms Application. Now, as I was creating a DataSet, Binding source, Table adapters. I noticed they show up on a bottom section on the design view. My question is: What is that section, and what goes in there?
From MSDN:
Non-visual components added to the Windows Forms Designer are placed on the Component Tray, located below the design surface, so that they are easily accessible without cluttering the visual design space.
This section generally corresponds to nonvisual elements in a Form, but which are stil relevant to the Form, such as a Timer.
Since they're nonvisual, it doesn't make sense to put them in the designer with the visual elements, but they still need to be in the designer for the designer to be useful in setting their values.
The bottom part of the winforms designer is used for non-UI elements. Things that are created / generated just as fields in the class behind, and not added to the actual view.
I have been wondering from the first day, when I started to read, how does the .NET Framework work?
First it's really good to have an IDE like Visual Studio. While for example when I click and drop the textboxes, buttons, set their properties and so on, everything works fine.
But in the case of Java in most cases we as a programmers write coding to develop a Frame (window). But in case of .NET, Visual Studio make things easier, but how does work that, without writing a single line of code, all Windows, buttons, etc. are created?
And if I change the button name in the Form design area, where does this get stored, and more importantly how does it get displayed when we execute our program? Is this magic? Or there is a long process under the hood?
There is absolutely no magic behind this. The visual forms designer in Visual Studio generates C# code for you. Just chceck the Form1.designer.cs file.
The code in your .designer.cs is generated by serialization (objects -> code, code -> objects). Look at the CodeDomSerializer class if you wanna try understand better what is happening under the hood (with Reflector you might wanna check ControlCodeDomSerializer in System.Design.dll). And of course you can create your own serializer for custom controls and components.
I would like to make a support plug-ins in my program.
For example in my program there are several tabs in one tab is the editor in which the code is written also in that tab has a button run.
After pressing the button run occurs a compilation of source code and its execution.
The results of work are displayed in the other tab.
I would like to find such a component in which there are:
Syntax Highlighting, Debugger, Analogue of solution explorer
Thank you very much for your answers.
I would like to bring more of clarity to my question.
I want to do something similar to that is shown in the screenshots below
On a single tab there is the editor and at the other tab displays the results.
To write plug-ins I'd like to use C #.
I guess the best place to start is AvalonDock from CodePlex, specifically what you are trying to do is a Tabbed User Interface.
Keep in mind that even with a TabbedWindows framework build/debug and syntax highlighting are not for free and you will have to find icons and design the UI mostly yourself.
for code coloring there are also many components, also free, like Scintilla .NET
You obviously understand that Visual Studio is a very complex application, so rewriting portions of it will be difficult. There are components available to help you, like the ICSharpCode text editor. In fact, that whole project is probably quite valuable.
However, when thinking of plugins and actually writing code for it, I'd personally go down the MEF route. In fact, this is the very framework that VS.NET 2010 uses for extensibility. Provide your user/developer with a set of libraries to code against (like an SDK), and let them use a Visual Studio Express edition to write proper code :)
As source code editor you can use AvalonEdit (it is great, in some aspects even better than VS code editor), solution explorer is fairly easy to create and debugger is way too language-specific to be a reusable component (you didn't specify what language are you developing for!).
The whole thing can be packaged into AvalonDock, so you get the draggable and dockable panels - it even has VS 2010-like skin (and again - is very easy to implement even with only very basic WPF knowledge).
Or you can use the Visual Studio Isolated Shell - it allows you to use the Visual Studio interface in your program (the end users don't have to have VS installed!), but it requires extensive knowledge of VS API (if you ever developed VS extension you know what I am talking about). For example Civilization V used this approach for it's modding environment, but the result smells as stripped VS with custom splash screen, not as professional product. There are many buttons and config. options that don't work, some features that would be expected from such program (and easy to do in custom app) didn't get in because it would be nigh impossible to implant them into the VSIS etc...
EDIT: You may also eventually be interested in this.
I'm looking at producing a few versions of my app with restricted functionality, and I'd like to leave out the code that is not necessary in simpler versions. Being a WinForms app, the UI will have to change for each version - not displaying the restricted controls.
I made an attempt to annotate parts of the auto generated controls & layout code with conditional compilation statements, but I discovered VS throws out all my code as soon as I touch anything via the WinForms designer.
I would like to be able to conditionally compile some event handlers & UI controls. I could write the conditional UI code outside the designer file, but then I wouldn't be able to use the VS designer to edit my app.. Are there any suggestions to remedying this situation - i.e. conditionally compile UI controls & still have them display in the designer?
Thanks!
Not knowing how your UI forms look like perhaps you can create a base form that all versions share in functionality. Then subclass that with forms for the specific functionality. This way you can conditionally compile the sub forms rather than trying to turn on/off controls within the one form. However the subforms will typically extend the form downwards so weaving controls throughout the form might not work in this case.
Also if you use a presentation pattern (if you are not doing so already) such as MVC or MVP you can minimize the logic you have in the forms and push that to presenter/controller or even business classes that you can configure based on the version you are compiling against. These classes can get injected (DI) into the application based on some configuration.
Another option is not to compile out the form controls but hide them based on the version you are running but have the business classes compiled. This way the important 'intellectual' code is not in the app and you're not fighting with the winform designer.
This is a general question, but I'll explain my specific need at the moment:
I want to find the framework class that enables one to choose an image at design-time. I can find the editor that is used at run-time - its the Drawing.Design.ImageEditor. At design time, however, a different editor pops up which allows one to choose an image from resources.
I'm guessing I could run some kind of program, then open up the image editor, from the property grid, and see what new windows/classes have been created?
Thanks
Yes, you can see what's being used by using another instance of Visual Studio and use Tools + Attach to Process (managed) to look at the call stack. It is a Microsoft.VisualStudio.Windows.Forms.ResourcePickerDialog. That is not something you can use in your own code, the Visual Studio designer assemblies are not re-distributable. Nor would they be useful, they monkey with the design-time state of the project.
Making you own isn't that hard, just use Reflection to iterate the properties of Properties.Resources and find the ones that have the Bitmap or Icon type. Display them in a ListView to allow the user to pick one. Adding resources at runtime isn't an option.
A tool with similar functionality to what you mention is Spy++ which you can find in your Visual Studio folder on the start menu (under the sub menu Visual Studio Tools).
However, if I understand you correctly, I don't think the design time editor you're talking about is written in managed code and even if it was, I'm fairly sure it's not in the framework. It's just part of Visual Studio itself and as far as I know you can't get hold of the source code for that.