What is the difference between User Control, Custom Control and Component?

The main difference between User Control, Custom Control and Component is that they inherit from different levels in the inheritance tree: MyComponent |-> Component MyCustomControl |-> Control |-> Component MyUserControl |-> ContainerControl |-> ScrollableControl |-> Control |-> Component So, in short you get a different amount of pre-wired functionality with the different options. When would … Read more

What is Dependency Injection and Inversion of Control in Spring Framework?

Spring helps in the creation of loosely coupled applications because of Dependency Injection. In Spring, objects define their associations (dependencies) and do not worry about how they will get those dependencies. It is the responsibility of Spring to provide the required dependencies for creating objects. For example: Suppose we have an object Employee and it … Read more

WPF TextBox and Scroll behavior

The problem is that the parent elements are providing TextBox with as much space as it thinks it needs, and when more text is present it will expand instead of staying at the initial automatic size. One solution here is to make another auto-sized element and bind the TextBox.Width to it: <DockPanel> <TreeView Width=”150″ DockPanel.Dock=”Left”/> … Read more

Is it appropriate to extend Control to provide consistently safe Invoke/BeginInvoke functionality?

You should create Begin and End extension methods as well. And if you use generics, you can make the call look a little nicer. public static class ControlExtensions { public static void InvokeEx<T>(this T @this, Action<T> action) where T : Control { if (@this.InvokeRequired) { @this.Invoke(action, new object[] { @this }); } else { if … Read more

Differences between Excel’s Form Controls & ActiveX Controls

There is [eternal] confusion surrounding the two types of controls available to Excel — exacerbated by the contrasting terminology used by different online sources. This is only a general overview of the differences between Form Controls and ActiveX Controls (based on my old notes that helped me finally figure out the differences!) Visit the included … Read more

C# RichTextBox selection problem

There’s a silly bug in the AutoWordSelection property implementation. The workaround is equally silly. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form, replacing the existing RTB. using System; using System.Windows.Forms; public class FixedRichTextBox : RichTextBox { … Read more