Component vs. Control - winforms

In the world of WinForms .Net controls
What is the difference between Component and Control?
Can a Control contains any Component?
Can a Component contains any Control?

A Control has all the plumbing required to act as a window. The ability to respond to Window messages (WndProc) and having a Handle being foremost. Component is missing all that. It is really rather simple, it has design time support to set properties and it can be disposed, that's all.
Components still can have a runtime representation, OpenFileDialog being the best example. But that is actually a dialog built into Windows, not Windows Forms.

A Component is just a representation of an object/sub API. eg. ImageList is a component which is invisible and is just an API into a set of images. The fact you can drag and drop them onto forms is just sugar in the designer.
A Control is intended to be visible/interactable/nestable.

In response to your comment, the Component and Control can be seen in the Object browser as being from different object hierarchies. A Component cannot be added within a Control, as the Controls collection only accepts objects with base type of Control.
A Component cannot contain Controls.

A component is basically a class (it can be a dll, Activex Object).
It does not have User Interface capabilities that's why you cannot see a visual representation.
It is portable and not specific to any language.
While on the other hand control is component which provides User Interface capabilities.
Since control has UI, you can see its visual representation.
It is language specific and not portable.

Related

Why WPF renders differently on different versions of Windows?

I read that WPF uses DirectX under the hood to perform its rendering, that it doesn't rely on the dinosaurian libraries that WinForms uses to render controls.
So I made my Presentation layer with WPF and it looks the way it should under Win8.
Then I deployed the project to Windows Server 2003... to find out that my nice little custom message box looks awfully WinForms-like and somewhat clunky; the button controls are VERY similar to the WinForms ones, the expander control is no longer shown as a circled ^ arrow and looks like it was drawn in 1998 (picture the ^ arrow on an ugly square flat button that pops up when your mouse hovers over it).
From the Pro WPF in C# 2010 Bible:
Part of the promise of WPF is that you don't need to worry about the details and idiosyncrasies of specific hardware. WPF is intelligent enough to use hardware optimizations where possible, but it has a software fallback for everything. So if you run a WPF application on a computer with a legacy video card, the interface will still appear the way you designed it.
So, is this a lie? To me it is, because it doesn't appear the way I designed it.
If not, then why/how doesn't the thing render identically regardless of the machine that's running it? Is the software fallback somehow designed to mimick Win32/GDI rendering? Is there a way to get my little custom message box to look identical on Win8 and WinServer2K3?
That has NOTHING to do with DirectX / Rendering / video card / any of that.
and EVERYTHING to do with WPF taking the DEFAULT appearance of ALL UI Elements from the Windows Theme.
If you don't want this behavior, you'll have to provide Styles and Templates for ALL UI element types, or otherwise find a way to include PresentationFramework.Aero.dll in your application and use that as the default theme library.
Take a look at this answer

Design Time Extension Properties In Winforms

I have built out a couple of keyboards for a touch aware app we are building in work. Since we use a controller that is aware of when the app is in touch screen mode I thought it would be nice if, in design mode, we could associate a control with a keyboard type and have the controller look after the calling of the keyboard.
One of the things I do not want to do is to sub class each type of control just to add this property as I feel it is a very heavy for small gain. I had thought of using the tag property but it is not available in all controls due to use.
I was wondering if there is a way of attaching a property to a control on design time for the purpose of adding this meta data. So to recap I would like to be able to give each control a value that would be read by the controller to decide what keyboard to show.
Yes, the designer supports this. Good examples of existing components that do this are ErrorProvider and HelpProvider. Note how they add properties to existing control types.
You'll want to implement your own component, it needs to implement the IExtenderProvider interface. The MSDN Library article for it has a good example that should help you getting it right.

WPF application with context sensitive toolbar

I want to design an application much like Visual studio where the toolbars are context sensitive to the workspace area and their are common toolbars which have context sensitive functionality like cut, copy, paste (for these I can have application commands), comment selected (custom commands).
I want to keep the workspace unaware of toolbar controls.
I tried using custom routed commands but it only works on parents in the visual tree (bubble routing strategy) however my toolbar and workspace are on the same level in the shell.
Are their specific patterns (I am sure there must be) for designing such an application in WPF?
I implemented a simple version of what you described, where a toolbar had options that were context sensitive and were simply shown or hidden. The application used the MVVM pattern, so my toolbar had a view model. I leverage the message bus (sometimes called event aggregator) to publish messages which the toolbar's view model could react to.

Custom Message Box in WPF - What project type?

I have a WPF Composite application and I want to create a customized messagebox, I wondered what project type I should use to create it?
A usercontrol
A WPF Application
A Class Library
I have to then be able to use this MessageBox in other places in my application.
I have to then be able to use this
MessageBox in other places in my
application.
Since you want to share and reuse the component, you should probably not use an application project; it is technically possible to reference an application project from another project, but it's not very idiomatic. So you want a library project instead. In Visual Studio, the Class Library, WPF Custom Control Library and WPF User Control project types are all library projects: the only difference is which system DLL references are set up for you, the initial files generated, and what VS puts on the Add Item menu.
So any of these three options will be fine, but my recommendation would be either WPF User Control Library or WPF Custom Control Library since that will:
automatically include references to
the WPF DLLs; and
set up the Add Item menu to make it easier for
you to add actual controls to the
library in future (since you are
bound to come up with some reusable
controls as well as your message
box, and you may as well stick them
in the same project).
I have implemented a WPF MessageBox fully customizable via standard WPF control templates:
http://blogs.microsoft.co.il/blogs/arik/archive/2011/05/26/a-customizable-wpf-messagebox.aspx
Features
The class WPFMessageBox has the exact same interface as the current WPF MessageBox class.
Implemented as a custom control, thus fully customizable via standard WPF control templates.
Has a default control template which looks like the standard MessageBox.
Supports all the common types of message boxes: Error, Warning, Question and Information.
Has the same “Beep” sounds as when opening a standard MessageBox.
Supports the same behavior when pressing the Escape button as the standard MessageBox.
Provides the same system menu as the standard MessageBox, including disabling the Close button when the message box is in Yes-No mode.
Handles right-aligned and right-to-left operating systems, same as the standard MessageBox.
Provides support for setting the owner window as a WinForms Form control.

Best Way to show Busy Bar In WPF Application

I have WPF Application where I have One main form and other user controls are shown in the main form as child form. I have to show Busy bar when I make Async call to data base. What is the best way to declare Busy bar object and then used in every child user control. Should I need to declare busy bar object in the main Form and then Used it the child user control or The App file is best, or is there any good way.
It depends on whether your "busy bar" is a control that appears inside other controls or windows, or a popup window in its own right.
If it's a control, you cannot (easily) use a single control instance in multiple places in the application. A WPF control instance is part of a visual and logical tree. It cannot be part of two visual trees. You can create a BusyBar control class, and declare multiple instances of that in the various places you need it: to do this, use the User Control (WPF) or Custom Control (WPF) template in Visual Studio.
If it's a window, you can create it during application startup but leave it hidden. Then you can show it from code when required (using the Show or ShowDialog method). That said, it's not clear why you'd need this to be a singleton anyway. Creating windows is cheap, especially compared to calls across a network to a database. Again, declaring a class, and creating and showing instances of the class when required, would be the more usual approach. You could easily create a static method to encapsulate the "create-bind-show-wait-hide" cycle so as not to pollute your app code with the details.

Resources