Sam Hobbs

Sam Hobbs

  • 51
  • 29.3k
  • 2.1m

WPF controls compared with Windows Forms controls

Jun 28 2011 9:54 PM
I am reading the book "Applied WPF 4 in Context" by Raffaele Garofalo published by Apress; the eBook ISBN is 978-1-4302- 3471-5. I have not gotten past chapter 1 yet but the guy obviously knows WPF.

He tries however to compare WPF to other technologies and I don't understand what he is saying. Perhaps someone here can explain things. I will summarize here what the book says and if necessary I will quote the book but hopefully this is close enough to what the book says. So the following is essentially what it says but this is my version of it:


The following is my version of what the book says:

CSS can be used to create a UI style for a TextBox for use throughout a web. That is impossible to do using the basic tools of client technologies such as Windows Forms and Java. In other words, it is not possible to define a style for a UI control for Windows Forms. Using Windows Forms, if we want to create a TextBox with a specific border color and shape then we must make a custom TextBox. Using WPF, it is possible to make a TextBox change it's background color when it gets the focus.

The preceding is my version of what the book says.


The book is saying that the basic tools of client technologies makes it difficult to do things like that. I do understand that a WPF TextBox has more capabilities than a Windows Forms TextBox. That however is not what the author is saying; he is saying that there is a basic difference that prevents a Windows Forms application from using a style throughout an application; something that is easy for WPF but not easy for Windows Forms.

First, note that it is totally possible to change a BackColor property of a Windows Forms's TextBox object when it receives and loses focus, correct? So that seems to be the same for WPF and Windows Forms. A Windows Forms application can derive a class from the TextBox class that changes the BackColor property in that manner and use the derived class throughout the application. So I don't understand the significance of that part of what the book says.

As I said, a WPF TextBox has more capabilities than a Windows Forms TextBox. The thing I am not sure of is which of the two that the book is saying is easier to do with WPF:
  • adding capabilities to a control that it does not already support and using that modification throughout an application
  • use a control with some of it's properties of existing capabilities set to specific values and use that throughout the application
So is there anything about WPF that makes either of those easier than Windows Forms? I suspect that the truth is that the only relevant difference is that WPF controls have more features than Windows Forms.

But wait, there is more. Using Windows Forms, it is easy to create a UserControl. It is entirely possible to create a UserControl with a TextBox in it and then draw a custom border around the TextBox, correct? And then a Windows Forms TextBox can have as much capabilities for a custom border as a WPF TextBox, correct? A Windows Forms UserControl can easily be used thoughout a Windows Forms application, correct?

Answers (5)