bogus component being added to WinForm - c#

Many times when I edit a WinForm in my (inherited*) project an instance of a particular component is added -- and I'm not intentionally doing anything to add it. What could trigger the form designer to always think that a component needs to be added?
inherited project: meaning that I didn't design/implement most of it. There may be components or tools in use that I am not aware of. It does use DotNetBar; but the component being auto-added is not from this library.

Related

Design time events in WPF?

I am using Autofac with my WPF project.
At design time for some controls, I set the data context of these controls to a designer-specific view model. This view model then injects some services in through its constructor.
That's all fine. But how can I manage lifetime scoping for this? Is there any way to hook up to an event and dispose my Autofac container when the design-time phase is done?
You've said in comments:
The problem is that some of my services (for instance a hotkey service) is using the RegisterHotkey API. For that service, it's important that it is unregistered when Visual Studio is done rendering my design.
In general, those should not even get registered first when your component is in DesignTime. Designtime if for previewing the layout and inspecting view modes/states, not really for testing (though it's very tempting sometimes).
When in designtime, all interactivity of the component should be disabled. VisualStudio tries to do that, you will notice that many interactivity events/triggers are not invoked or passed to your component. However, it sometimes fails badly at this, like in case of Popups (and therefore Dropdowns, Comboboxes, etc) you can sometimes force to actually open in design-time and it yields very strange/unstable/otsafe results.
This is why you shouldn't fully trust VS and the design-time mode to "just work". You probably already know well that poorly written component can, in desing-mode, try for example to connect to a database. It shouldn't happen. Usually.
I'd say, refactor that hotkey-registering bits out into some service and stub/nullify/disable it when you detect designtime mode.
I doubt they worked in designtime, but if you needed these hotkeys to flip some switches in VM on and off, or to invoke some behavior, bind that switches or behavior to a few new properties, and instead of pressing hotkeys, set them in the designer or by designtimedata to check the effect.
Just FYI - I never researched this for WPF/XAML, but for WinForms, each component could come with a special "designer" component. VisualStudio used that 'designer' component for preparing, mantaining, rendering, editing and serializing the edited component. You could actually write a designer for your custom control, and that designer could display extra windows with custom editors, and so on. Toolkits like DevExpress heavily relied on that. I'm not sure if that there is a similar framework for XAML components. I doubt it's the same, but there may be some similar concepts kept. Anyways, I wouldn't dig into this on your place, not for such things. It's not worth it unless you really want to start extending the Designer with your custom plugins.

easy way to replace components in visual studio C#

I made a GUI using C# for my project using default buttons, graphs and other components available in visual studio. Now I have installed DotNetBar for cool components like tabs buttons etc and want to replace them with the old ones. Is there an easy way to do that so that just replacing (for example a button) associates the code with the newly added button...?
Thanks in advance
No, as much as I know there is no easy way unless the producer of the new controls provides an automated tool for the job.
The main reason lies in the difference in property names, methods name and above all the event handler signature between the standard controls and the new ones. You could be lucky if the third party controls have the same properties, methods and events of the standard one, but usually they have implemented new functionality and extendend the base one and this usually causes broad incompatibility.
Then there is the need to manually edit every project file to substitute the references from the standard controls to the new ones and this is also a complex work that only the producer of the control could resolve

Microsoft Kinect SDK 1.6 missing KinectSensorChooser component?

I am currently following this tutorial
http://channel9.msdn.com/Series/KinectQuickstart/Setting-up-your-Development-Environment
But at around 9:50 he uses a component called KinectSensorChooser which is not available anymore in the latest SDK 1.6 version because i read Microsoft's SDK History log that states
"We’ve taken KinectSensorChooser, formerly part of the WpfViewers and split the logic and UI into two different classes: KinectSensorChooser and KinectSensorChooserUI in Microsoft.Kinect.Toolkit.dll.
KinectSensorChooser could be used in non-WPF scenarios as it is logic only, no UI."
Source: http://www.windows7download.com/win7-kinect-sdk/history-lxqvgakz.html
Since the Microsoft.Kinect does not include the KinectSensorChooser component i added the Microsoft.Kinect.Toolkit reusable component which does include the KinectSensorChooser but the component is not showing up in the toolbox, i tried adding it manually by right clicking on the toolbox and selecting choose items then WPF components then locating it but it imports as a UI (KinectSensorChooserUI) and if i drag it onto the form the component disappears from the toolbox, i am using Visual Studio 2012 Ultimate on Windows 8
I've never added the KinectSensorChooserUI control to the toolbox in Visual Studio. The need to do so really isn't there.
If you feel obligated to do so, I found a Adding Your WPF Control To The Toolbox blog post that might be of use. Haven't tried it myself, so I can not promise it will work.
I personally do not use the UI component of the KinectSensorChooser. Unless you really plan to be turning the Kinect on/off or switching between multiple Kinects manually, it doesn't really serve much of a purpose. It does provide some feedback, but that can done in other more aesthetically pleasing ways.
To use the KinectSensorChooser you simple need the following in your main class:
private readonly KinectSensorChooser _sensorChooser = new KinectSensorChooser();
public MainViewModel()
{
// other initialization here
_sensorChooser.Start();
// more initialization here
}
You now have an active KinectSensorChooser, just minus the UI.
If you are dedicated to using the UI component, forgo trying to add it to the toolbox and just do the following:
Add the Toolkit project or a reference to the .dll.
Add the namespace to your Xaml so that you can reference the controls in your markup. xmlns:kt="clr-namespace:Microsoft.Kinect.Toolkit;assembly=Microsoft.Kinect.Toolkit"
Add the control to your visual tree
<kt:KinectSensorChooserUI x:Name="SensorChooserUI" />
Your code behind would declare the namespace, initialize the KinectSensorChooser and set up any events you want.
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
private readonly KinectSensorChooser _sensorChooser = new KinectSensorChooser();
// somewhere in your constructor, or other init function
this.SensorChooserUI.KinectSensorChooser = _sensorChooser;
_sensorChooser.Start();

Why does my class suddenly have a 'designer'?

I just finished adding and removing different database models (I was trying to figure out which one I should be using for this project) then after playing around for a while I noticed one of my classes's icon changed from what is shows beside my Calculations.cs class in the first image to the Balance.cs icon.
The Balance.cs now has this Designer component so when I double click on it I see my second screen shot. This seems to be allowing me to add components from the toolbox to my class. There are actually two classes within my Balance.cs. This Designer thing is only affecting/interacting with one of them (it inherits from SerialPort).
I don't really know what changed or what I did to make this happen and ctrl+z is not being my friend here. How do I change Balance.cs back to a regular class with no designer component?
Thanks
If any of the classes in a source file inherit - either directly or indirectly - from System.ComponentModel.Component (such as SerialPort), Visual Studio will provide design-time support to you. This is sometimes unwanted behaviour, and you can safely ignore it in most cases.
If it really bothers you, you can decorate your class with the [DesignerCategory] attribute (set the category to an empty string).

Extending UI Component Class in C#/VS2010

I've only just started using C#/VS this past week and wondered how to do something which, I think, should be quite simple:
What I want to do is extend the class used by a UI component and therefore implement my own methods in it - just for one instance of a UI component though. If I was using xcode/objective c I would normally just change the class name of the component in interface builder and it would become an instance of that class which would in turn extend the original UI class.
How do I do something comparable using C#/Visual Studio?
You can take any component class in Windows Forms and subclass it. Visual controls all derive from the Control class and you can do so as well.
If your component is a User Control (i.e., it derives from System.Windows.Forms.UserControl), it should automatically appear in the Toolbox after you build the project. For other components, you can add them to the Toolbox by right-clicking on the Toolbox and select Customize Toolbox, selecting the .NET Framework Components tab, clicking the Browse button, and selecting the DLL with the control.
Remember that all (or most) UI components are classes, so they can be "extended" just like any other class.
Some will have virtual members you can override to take special actions. In all cases, you can add properties, methods, and events to the components.
Once you've created and built them, you can use them from the Toolbox, just as though they were the "built-in" .NET components.

Categories

Resources