0% found this document useful (0 votes)
9 views

(Ebook) GDI+ Application Custom Controls with Visual C# 2005: A fast-paced example-driven tutorial to building custom controls using Visual C# 2005 Express Edition and .NET 2.0 by Adam Ward, Dragos Brezoi, Iulian Serban, Tiberiu Radu ISBN 9781904811602, 1904811604 instant download

The document is a tutorial ebook titled 'GDI+ Application Custom Controls with Visual C# 2005' that teaches intermediate C# developers how to create custom controls using Visual C# 2005 Express Edition and .NET 2.0. It includes practical examples, a case study on developing a PieChart control, and covers essential topics like GDI+, drawing techniques, and user interface design. The book is published by Packt Publishing and is available for purchase online.

Uploaded by

mericmatell9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

(Ebook) GDI+ Application Custom Controls with Visual C# 2005: A fast-paced example-driven tutorial to building custom controls using Visual C# 2005 Express Edition and .NET 2.0 by Adam Ward, Dragos Brezoi, Iulian Serban, Tiberiu Radu ISBN 9781904811602, 1904811604 instant download

The document is a tutorial ebook titled 'GDI+ Application Custom Controls with Visual C# 2005' that teaches intermediate C# developers how to create custom controls using Visual C# 2005 Express Edition and .NET 2.0. It includes practical examples, a case study on developing a PieChart control, and covers essential topics like GDI+, drawing techniques, and user interface design. The book is published by Packt Publishing and is available for purchase online.

Uploaded by

mericmatell9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

(Ebook) GDI+ Application Custom Controls with

Visual C# 2005: A fast-paced example-driven


tutorial to building custom controls using
Visual C# 2005 Express Edition and .NET 2.0 by
Adam Ward, Dragos Brezoi, Iulian Serban, Tiberiu
Raduhttps://ebooknice.com/product/gdi-application-custom-controls-
ISBN 9781904811602, 1904811604 download
with-visual-c-2005-a-fast-paced-example-driven-tutorial-to-
building-custom-controls-using-visual-c-2005-express-edition-and-
net-2-0-5475940

Explore and download more ebooks at ebooknice.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

(Ebook) Professional Web Parts and Custom Controls with ASP.NET 2.0 by
Peter Vogel ISBN 9780764578601, 076457860X

https://ebooknice.com/product/professional-web-parts-and-custom-
controls-with-asp-net-2-0-2503200

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans


Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

(Ebook) Microsoft Visual C# 2005 Express Edition: Build a Program Now!


by Patrice Pelland ISBN 9780735622296, 0735622299

https://ebooknice.com/product/microsoft-visual-c-2005-express-edition-
build-a-program-now-980930
(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success)
by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018

(Ebook) Wrox’s Visual C#® 2005 Express Edition Starter Kit by F. Scott
Barker ISBN 9780764589553, 0764589555

https://ebooknice.com/product/wroxs-visual-c-2005-express-edition-
starter-kit-973072

(Ebook) Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition
Starter Kit by David Sussman, Alex Homer ISBN 9780764588075,
0764588079

https://ebooknice.com/product/wrox-s-asp-net-2-0-visual-web-
developer-2005-express-edition-starter-kit-923640

(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study:


the United States, 1919-41 2nd Edition by Benjamin Harrison ISBN
9781398375147, 9781398375048, 1398375144, 1398375047

https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044

(Ebook) User Interfaces in C#: Windows Forms and Custom Controls by


Matthew MacDonald (auth.) ISBN 9781430208372, 9781590590454,
1430208376, 1590590457

https://ebooknice.com/product/user-interfaces-in-c-windows-forms-and-
custom-controls-4592362
GDI+ Custom Controls
with Visual C# 2005
GDI+ Custom Controls with
Visual C# 2005

If you want to build custom controls with C# but you don’t know where to start, or you are
intimidated by the huge amount of information that needs to be absorbed, then this book is for
you. This friendly tutorial is based on numerous examples with real-world applicability, and includes
a case study featuring the development of a fully functional PieChart control.

Showing you how to use the free Visual C# 2005 Express Edition environment to develop your
controls, Building Custom Controls with Visual C# 2005 will teach you how to create professional,
reusable custom controls for your desktop applications in no time.

What you will learn from this book


• Understand the basics of custom controls
• Use GDI+ to draw your own controls
• Implement double buffering to speed up your forms F r o m T e c h n o l o g i e s t o S o l u t i o n s
• Add printing functionality to your custom controls
• Handle the mouse events to improve the user experience

Tiberiu Radu
Iulian Serban
GDI+ Custom Controls
• Offer design-time support for programmers using your control
• Design intuitive interfaces for your users

Who this book is written for


This book has been written with the intermediate C# developer in mind. Assuming a working
with Visual C# 2005
knowledge of C#, the book teaches you how to implement custom controls using Visual C# 2005

Dragos Brezoi
Adam Ward
Express Edition, and GDI+.

A fast-paced example-driven tutorial to building custom


controls using Visual C# 2005 Express Edition and .NET 2.0
$ 34.99 US Packt Publishing
£ 22.99 UK Birmingham - Mumbai
€ 32.99 EU www.packtpub.com

Prices do not include


local sales tax or VAT
where applicable Iulian Serban Dragos Brezoi
Tiberiu Radu Adam Ward
www.it-ebooks.info
GDI+ Custom Controls with
Visual C# 2005

A fast-paced example-driven tutorial to building


custom controls using Visual C# 2005 Express Edition
and .NET 2.0

Iulian Serban
Dragos Brezoi
Tiberiu Radu
Adam Ward

BIRMINGHAM - MUMBAI

www.it-ebooks.info
GDI+ Custom Controls with Visual C# 2005

Copyright © 2006 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without warranty,
either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will
be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing
cannot guarantee the accuracy of this information.

First published: July 2006

Production Reference: 1220706

Published by Packt Publishing Ltd.


32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 1-904811-60-4
www.packtpub.com

Cover Image by www.visionwt.com

www.it-ebooks.info
Credits

Authors Development Editor


Iulian Serban Cristian Darie
Dragos Brezoi
Tiberiu Radu Indexer
Adam Ward Niranjan Jahagirdar

Reviewer Proofreader
Cosmin Oprea Chris Smith

Technical Editor Layouts and Illustrations


Mithil Kulkarni Shantanu Zagade

Editorial Manager Cover Designer


Dipali Chittar Shantanu Zagade

www.it-ebooks.info
About the Authors

Iulian Serban is a software architect who started programming at a very young age. He evolved
through a lot of programming languages including Pascal, Delphi, C++ Builder, Visual C++ with
MFC and finally .NET and C #. By the age of 17 he started working for Syncfusion, one of the
largest .NET control builders in the US, writing code for professional custom controls. Nowadays
he devotes most of his spare time to his own IT business, which is set to release significant software
projects soon.
I'm using this opportunity to thank the Syncfusion team for their continued support, and for their
professionalism.
Dragos Brezoi started programming to create an application for processing and adding extra
effects to his guitar's sound. Several years after, he got a Masters Degree in Computer Science from
the Politehnica University of Bucharest, and is now researching for a Ph.D. in Advanced Automatics.
Dragos currently works as a programmer for Mikon Systems, developing industrial software. His
skills cover a wide area of specialization from PLC and DSP programming to SCADA, OPC, and
DCS solutions. At this moment he is creating professional human-machine interfaces, with a focus
on developing advanced custom controls with C#.
My big thanks go to my son, Matei, who was a wonderful and cooperative baby and let me work
on this book.
Tiberiu Radu has been working with computers for over 10 years now, programming in a wide
range of languages including Pascal, C/C++, Visual Basic, Delphi, and C#. As a Microsoft Student
Partner in the Microsoft Academic Program, he's devoting a lot of time to many .NET-related
technologies. Tiberiu is in the last year of studies with the Automatic Control and Computers Faculty
of the Politehnica University of Bucharest. While researching for his own IT security business, he
developed skills in embedded programming and new web technologies, and is seeking new and
innovating networking security solutions.
Adam Ward works for a communications technology company in Derby, England. Adam excels
in experimental programming techniques and has a particular interest in high-speed algorithms and
graphical methods. His professional work is based in a varied Research and Development environment
and he thrives on tasks requiring innovation, skill, and fine-tuning. He has also been involved in
experimental coding collaborations showcasing the power of C#. Away from work, Adam is
turning his attentions to Linux systems and especially cross-platform programming under
.NET-compatible systems.

www.it-ebooks.info
About the Reviewer

Cosmin Oprea is a veteran in the software industry, having written code in languages ranging
from C/C++ to VB6 and C#. His experience with GDI started when working with the Win32 API
on Windows 95, and nowadays he's using GDI+ to give a final touch and better look and feel to
his Windows Forms interfaces.
Cosmin is a big fan of agile methodologies (such as Extreme Programming), which he has successfully
applied when developing various enterprise-class applications based on .NET technologies. Microsoft
Romania has recently awarded Cosmin in recognition of his influence as a .NET evangelist, and
for his contribution to the Romanian .NET User Association (RONUA).

www.it-ebooks.info
Table of Contents

Preface 1
Chapter 1: Introduction to Custom Controls 5
What Are Controls? 5
Introducing Custom Controls 7
Categories of User Controls 9
Preparing Your Environment 9
What Are Custom Controls Made Of? 9
Private Fields 10
Properties 11
Indexers 13
Events and Delegates 14
Handling Events 16
Collections 17
Enums 19
Building TinyNoiseMaker 20
Time for Action—Creating the TinyNoiseMaker Custom Control 20
Extending TinyNoiseMaker 27
Time for Action—Adding Public Functionality 27
Time for Action—Using the Control's Public Interface 31
Summary 33
Chapter 2: Introduction to GDI+ 35
Understanding Control Drawing 35
Understanding GDI+ 36
The Graphics Object 36
The Control.Paint Event 37
Invalidation 37
Simple Drawing on a Form 38
Time for Action—Creating the Application 38
Drawing Inside a Panel Object 41
Time for Action—Creating the Application 41

www.it-ebooks.info
Table of Contents

Drawing Inside a Control 42


Time for Action—Creating the Application 43
Summary 45
Chapter 3: Basic Drawing 47
The GDI+ Coordinate System 47
Drawing with GDI+ 49
Using the Color Object 49
Drawing Using the Pen Object 50
Filling Surfaces Using the Brush Object 51
Drawing Text Using the Font Object 52
Improving Drawing Quality 53
Building the GradientLabel Control 54
Time for Action—Creating the GradientLabel Custom Control 54
Summary 56
Chapter 4: Drawing Complex Shapes and Using Transformations 57
Drawing Complex Shapes 57
The GraphicsPath Object 58
The Region Object 62
Clipping Drawing Using Region Objects 65
Keeping Drawing Inside a Region 65
Keeping Drawing Outside a Region 66
Graphics Transformations 67
Translation 68
Rotation 69
Scaling 70
Creating the Clock Control 71
Time for Action—Creating the Clock Control 71
Time for Action—Updating the Clock to Use Transformations 77
Summary 78
Chapter 5: Drawing Control Parts, Borders, and Adornments 79
Rendering Common Control Parts 79
Drawing Buttons 80
Drawing Caption Buttons 81
Drawing Checkboxes 82

ii

www.it-ebooks.info
Table of Contents

Drawing Drop-Down Buttons 83


Drawing Radio Buttons 83
Drawing Scroll Buttons 84
Rendering Borders and Frames 85
Rendering Button Borders 85
Rendering 3D Borders 86
Rendering Control Adornments 87
Creating Multiple Controls that Reuse the Same Functionality 88
Creating a Base Class for Two or More Controls 89
Time for Action—Creating the ControlPart Base Class 89
Creating Derived Controls 91
Time for Action—Creating the ScrollArrowButton Control 91
Time for Action—Creating the CheckButton Control 93
Extending Existing Controls 94
Time for Action—Creating the BorderGradientPanel Control 94
Time for Action—Implementing the GradientButton Control 96
Summary 98
Chapter 6: Working with Images 99
Drawing Images 100
Using the Image Class 100
Using the Bitmap Class 101
Displaying Images 103
Time for Action—Displaying Images 103
Image Effects 105
Skewing, Rotation, and Scaling 107
Building the ImageWarper Class 108
Time for Action—Creating the ImageWarper Class 109
The ImageWarperControl 113
Time for Action—Creating the ImageWarperApp and the Image WarperControl 113
Summary 120
Chapter 7: Printing 121
.NET Printing Explained 121
Using the PrintDocument Class 122
Your First Print Job 123
Time for Action—Creating the "Hello Printer!" Application 123

iii

www.it-ebooks.info
Table of Contents

The SimpleReportPrinter 126


Building the SimpleReportPrinter and TextDispenser Classes 126
Time for Action—Building the TextDispenser Class 128
Time for Action—Building the SimpleReportPrinter Class 130
User Involvement 134
Our Responsibilities as Programmers 137
Printing Custom Controls 137
Time for Action—Creating the PrintableRichTextBox 138
Summary 141
Chapter 8: Collections 143
Collections in the .NET Framework 144
ArrayList 144
Queue 145
Stack 146
SortedList 148
Generics 150
Building the Font Picker 152
Time for Action—Building Font Picker 152
Summary 163
Chapter 9: Double Buffering 165
Introduction to Double Buffering 165
The Scroll Bar 166
Scroll that Text! 168
Time for Action—Building FlickerFree Control 169
Summary 175
Chapter 10: Handling Mouse Events 177
Handling Mouse Events 178
Working with Coordinates 179
Dragging and Dropping 179
Dragging 180
Time for Action—Dragging 181
Dragging and Dropping 188
Time for Action—Dragging and Dropping 188
Summary 193

iv

www.it-ebooks.info
Table of Contents

Chapter 11: Implementing Design-Time Support 195


Building Designer-Friendly Controls 196
Attributes 196
Designers 197
Type Converters 197
UI Type Editors 198
Property Editors 199
Creating Property Editors 200
Time for Action—Adding Design-Time Support 200
Summary 203
Chapter 12: Designing Intuitive Interfaces 205
The Relationship between User and Computer 205
Communicating with Users 206
Requests, Input Parsing, Fault Tolerance, and Feedback 206
Examining the Sketcher Control 208
Looking Further Into Input Parsing 212
How Can We Use Regex to Our Advantage? 212
Time for Action—Creating the Regex Application 213
Our Regex Pattern in Detail 215
Optimization and Coding Conventions 215
Summary 216
Chapter 13: The PieChart Control 217
Creating the PieChart Control 218
Time for Action—Creating the PieChart Control 218
Adding Slice Names and Delimiters 224
Time for Action—Improving the PieChart Control 225
PieChart Legend 229
Time for Action—Creating the PieChart Legend 229
Printing the PieChart 232
Time for Action—The Printable PieChart 233
Adding and Removing Slices 238
Time for Action—Add Application Support for PieChart Slice Add/Remove Operations 238
Summary 243

www.it-ebooks.info
Table of Contents

Appendix A: Distributing Custom Controls 245


Creating a Control Library Using Visual Studio 2005 246
Creating a Control Library Using Visual C# Express 2005 248
Using a Custom Control Library 250
Index 255

vi

www.it-ebooks.info
Preface

The amount of built-in functionality included in the .NET Framework is amazing. One could create
complex applications with lots of functionality by simply assembling the pieces you're offered for
free. Among those pieces you'll find lots of powerful, flexible, and configurable controls. Who
would ever need to build their own controls, right?
While some can get away without ever needing to build a custom control, many don't, or don't want
to. Sometimes building a custom control is a necessity, because what you want to achieve doesn't
exist, or is too expensive to buy. This is particularly true for controls with customized shapes,
which need to be drawn instead of reusing other existing controls.
In some other cases, developers build custom controls as part of their architecture, allowing them
to reuse more efficiently common functionality (and code) that they trust and like. There are many
circumstances where building a custom control can make a programmer's life easier.
Unfortunately, programmers frequently avoided learning how to build custom controls because
learning all the complexities consume lots of time and energy. Comprehensive and advanced
books on the subject well exceed 1,000 pages, and the excessive amount of information can indeed
be intimidating.
This book takes a lighter approach, guiding you step by step into building your first custom controls,
and writing quality code. You'll build a new example in each chapter, and in the end you'll build a
completely functional custom control where you'll apply most of what you've learned in the book.

What This Book Covers


Chapter 1: Introduction to Custom Controls will be your introduction to the world of .NET
custom controls. You'll learn what controls are, why they are useful, what they are made of, and
towards the end of the chapter you'll also create a simple yet functional custom control called
TinyNoiseMaker.
Chapter 2: Introduction to GDI+ introduces you to the basics of drawing with GDI+. You will
meet a few namespaces, classes, and events that form the foundations of drawing with .NET, and
you'll see how to paint the surface of a custom control.
Chapter 3: Basic Drawing teaches you more about the coordinate system of GDI+, drawing lines
and polygons using pens, brushes, and colors, and guides you to build a control named GradientLabel.
Chapter 4: Drawing Complex Shapes and Using Transformations teaches you how to use graphics
paths, regions, and transformations to build complex shapes. You'll then use the theory to build a
Clock control.
Chapter 5: Drawing Control Parts, Borders, and Adornments explores using the ControlPaint
class to implement common functionality and adds finishing touches to your control. To demonstrate
the theory you'll build a simple custom control named GradientButton.

www.it-ebooks.info
Preface

Chapter 6: Working with Images covers common techniques for manipulating images. You'll build
a control called ImageWarper that scales, skews, and rotates an image.
Chapter 7: Printing introduces this very important area of GDI+. In many circumstances you'll
want to add printing support to your controls, and you'll see exactly how to do so by creating the
PrintableRichTextBox control.
Chapter 8: Collections teaches more details about .NET collections, including the new .NET 2.0
generics. Collections are very useful when building custom controls, and as an example you'll
build a Font Picker control.
Chapter 9: Double Buffering introduces this advanced technique that can make a big difference in
improving the speed and responsiveness of your control. Scrolling is one such area where double
buffering could make a difference, and you'll end the chapter by implementing a control that
displays a scrolling text.
Chapter 10: Handling Mouse Events deals with a very important topic for any desktop application
you'll ever write. Luckily enough, all controls that ship with .NET have integrated mouse support,
but at times you'll need to customize the features. In this chapter, you'll implement two applications:
one will allow you to drag an image inside a delimited area, and the second lets you drag pictures
from your Windows system into your form.
Chapter 11: Implementing Design-Time Support shows you how to make your user controls designer
friendly. This way, your control will be friendly not only to the end users working with it but also
to developers as well.
Chapter 12: Designing Intuitive Interfaces is a high-level overview of some human interface aspects
that, handled correctly, can help you build controls and applications that are easier and more fun
to use.
Chapter 13: The PieChart Control is a comprehensive case study, showing you how to develop
a complete custom control in several stages, each time adding features, fixing bugs, and
improving functionality.
Appendix A: Distributing Custom Controls shows you how to compile a custom control into a
separate DLL file, which can be reused later in other projects. You'll be shown how to do this
with both Visual Studio 2005 and Visual C# 2005 Express Edition, which offers different
built-in features.

Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles, and an explanation of their meaning.
There are three styles for code. Code words in text are shown as follows: "We can include other
contexts through the use of the include directive."

www.it-ebooks.info
Preface

A block of code will be set as follows:


private void SetValues()
{
totalCount = 0;
if (mySlices != null)
{
foreach (Slice slice in mySlices)
totalCount += slice.GetSliceRange();
}
// mySlicesPercent.Clear();
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or
items will be made bold:
private void SetValues()
{
totalCount = 0;
if (mySlices != null)
{
foreach (Slice slice in mySlices)
totalCount += slice.GetSliceRange();
}
// mySlicesPercent.Clear();
}

New terms and important words are introduced in a bold-type font. Words that you see on the
screen, in menus or dialog boxes for example, appear in our text like this: "clicking the Next
button moves you to the next screen".

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader Feedback
Feedback from our readers is always welcome. Let us know what you think about this book, what
you liked or may have disliked. Reader feedback is important for us to develop titles that you
really get the most out of.
To send us general feedback, simply drop an email to [email protected], making sure to
mention the book title in the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the
SUGGEST A TITLE form on www.packtpub.com or email [email protected].
If there is a topic that you have expertise in and you are interested in either writing or contributing
to a book, see our author guide on www.packtpub.com/authors.

www.it-ebooks.info
Preface

Customer Support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get
the most from your purchase.

Downloading the Example Code for the Book


Visit http://www.packtpub.com/support, and select this book from the list of titles to download
any example code or extra resources for this book. The files available for download will then
be displayed.

The downloadable files contain instructions on how to use them.

Errata
Although we have taken every care to ensure the accuracy of our contents, mistakes do happen.
If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful
if you would report this to us. By doing this you can save other readers from frustration, and help
to improve subsequent versions of this book. If you find any errata, report them by visiting
http://www.packtpub.com/support, selecting your book, clicking on the Submit Errata link, and
entering the details of your errata. Once your errata have been verified, your submission will be
accepted and the errata added to the list of existing errata. The existing errata can be viewed by
selecting your title from http://www.packtpub.com/support.

Questions
You can contact us at [email protected] if you are having a problem with some aspect of
the book, and we will do our best to address it

www.it-ebooks.info
1
Introduction to Custom Controls

Welcome to the world of Custom Controls! This book will guide you through creating custom
controls, from simple to complex ones. First, we will see what controls are, and how implementing
custom controls helps saving time and money. After reading this book, you will know how to
build different kinds of controls in a professional way.
This book not only presents the theory needed to understand how to build custom controls, but it
also shows how to implement the theory in practice by creating functional custom controls. The
theory is kept short and to the point because the purpose of the book is to teach building professional
custom controls quickly and easily, through practice. After each block of theory, you'll be taken
through an exercise that guides you to implement that theory in a functional control.
In this chapter, we'll have a quick overview of .NET custom controls, and also create a functional
custom control towards the end of the chapter. Understanding their architecture is an important
prerequisite before starting to create your own controls. More specifically, in this chapter you will:
• Learn what custom controls are, and why are they so useful
• Understand what custom controls are made of
• Build your first custom control using other controls and components

What Are Controls?


Controls are reusable pieces of user interface functionality. In the Windows world, controls
represent the way the user interacts with the application. They allow the user to enter data and
manipulate it, to perform certain actions on the application, input data, and display data in a way
friendly to the human eye. An application's interface is made up of controls and its functionality is
based on the interaction between these controls and the underlying code.
Let's take a look at the next few pictures and you will recognize some of today's most popular
controls. You must be familiar with the ways in which using these controls makes programming
much easier than it would have been to recreate the functionality by hand.

www.it-ebooks.info
Introduction to Custom Controls

The Button

The Checkbox

The Label

The Progress Bar

The Radio Button

Every software application has an invisible part, which does the actual work, and a visible part,
which provides the user interface. Controls are complete software elements that contain both: they
are represented on the screen in a graphical way, and they contain code to sustain this interface.
Controls have two major functions:
• To listen to the user's commands and send them to the application
• To display the results from the application in a way that the user will understand
This way you can change the background color by using a color picker control, you can execute a
certain operation just by pressing a button, or you can see the playing status of a movie just by
looking at a progress bar. A particular kind of control is the indicator, which exposes data in a
graphical way but doesn't let the user change that data. The label is the best example of such
a control.
It's interesting to know that the whole idea of the controls has its roots in the development of
personal computers. The developers had to emulate some real controls that offered a good look
and feel to the application. Let's take the example of a common button. A real button has different
forms and sizes and can be of multiple states, can be pushed and may revert if released, or can
make a sound when pressed. In order to reproduce the characteristics of a real control many tricks
have been used.
Back in the old days, it used to be harmony between the controls' look and feel, and the development
of personal computers, operating systems, and development systems. Twenty years ago the common
button had one color background, one single font text and when pressed, it didn't have a very
inspiring animation (if it had one at all). Today, when you think about a button, you have in mind
a rounded corner, gradient color border, bitmap, and multiple font and size animated button.
Things have changed, and the requirements for building new controls have increased.

www.it-ebooks.info
Chapter 1

Introducing Custom Controls


The term custom is pretty expressive. While in many of your development tasks you can make use
only of the default controls provided by your development environment (.NET in our case), in
many other cases you'll need to build your own.
Custom-made controls are named, not very surprisingly, custom controls. A custom control is a
control designed and programmed by you, and it may make use of other existing controls.
Sometimes custom controls are called third-party controls, named by their origin.
Here are a few controls that we'll develop over the course of this book:

Sound player control

Gradient control

Clock control

Gradient button control

The case has been made: creating custom controls can be a necessity when the basic classes
provided by the .NET Framework or the ones you can buy from third parties aren't enough, or are
too expensive.
The improved coding efficiency you can gain by implementing functionality as a custom control,
when it makes sense to do so, can be easily described using an example. If you have to use a pie
chart with different elements in it in your application that will present some results in an elegant
graphical way, there are two ways to implement this solution.
• You can write the code directly in the form. First, you will have to draw a pie chart
with different elements in it, at a certain position. Second, you will have to override
the mouse event handler of the form to get events for the chart. Third, assuming that

www.it-ebooks.info
Introduction to Custom Controls

this chart has some functionality, you will have to implement the desired model by
attaching the code directly to the form code.
Now if you want to have multiple pie charts in an application, you need to follow the
three steps mentioned above for each of them. Afterwards, even changing some
simple functionality, such as moving a certain action from left button to right button,
will need to be done three times. Your code will contain lots of duplicate functionality
and will be hard to read, understand, debug, and extend. Not to mention that every
time you modify the chart, you will have to rebuild your entire application.
• You can build a custom control. You will create a pie chart custom control that
draws itself and has its own events and event handler mechanisms. It will expose
different properties and methods necessary in the form. This custom control's
position can then be easily changed inside the forms that use it by simply setting its
coordinates. Also, once this custom control is created you will gain precious time,
because the time you will spend making changes, adding extra features, and
debugging the custom control will be shorter and code modification will happen in
one place—the control code.
Packing functionality in the form of user controls brings a number of important benefits:
• Building custom controls facilitates code reusability because the same control can be
used in any number of forms or tabs (or even other custom controls), without having
to write the same code over and over again. This saves a lot of time in application
development and untangles application code.
• It encourages functionality reusability, under OOP's "black box" principle. You
don't need to know how the control works inside; all you need to know is the public
interface it exposes. For example, think about one of the simplest controls available:
the Label control. When working with labels in a Windows Forms project, you know
that you need to set the label's Text property to the text you want displayed. You
never care how the label works internally, and how it actually paints that text on the
screen (it may not be obvious at the first sight, but work needs to be done even for
such a simple task as painting some text on the form). Extrapolating from this simple
example, you can get a feeling about how the black box concept applies to the more
complex controls.
• It keeps application code simple. Let's say you need that your application, among
other things, knows how to play sounds. Using a custom control to implement the
functionality for playing sounds minimizes the code written in the application form.
Instead of creating buttons and components, and adding and handling their events
in the application code, you can simply create a custom control (such as the
TinyNoiseMaker you'll build at the end of this chapter) that implements this
functionality, and exposes it through a public interface that the application can use.
Using custom controls keeps application code simple because the functionality is
implemented inside the control and not in the application's form. In the extreme case,
a form could be built exclusively of controls that are interacting with each other, and
have no functionality implemented in it.

www.it-ebooks.info
Exploring the Variety of Random
Documents with Different Content
decided by the Railway and Canal Commission in 1895, the fact that
foreign produce was being carried at lower rates by the London and
South-Western Railway Company from Southampton to London than
were being charged for English produce was not disputed; but it was
successfully argued (1) that lower rates might reasonably be granted
for train-loads of produce capable of being loaded into the waggons
at the docks and carried through, under the best transport
conditions, direct to London than for small consignments, picked up
at wayside stations, and loaded and carried under far less favourable
traffic conditions; (2) that there was no real detriment to local
producers, since the towns concerned were importing more than
they were sending away; and (3) that in no respect were the
circumstances "the same or similar." There was, said Sir Frederick
Peel, one of the Commissioners, "no concurrence between the two
classes of traffic, and the greater economy of transport in the dock
traffic justified the lower rate."

The principle here involved disposes of, probably, most of the


complaints which have been made from time to time on the subject
of undue preference; but as these complaints were especially rife in
1904, a Departmental Committee, presided over by Lord Jersey, was
appointed by the Board of Trade to inquire whether or not the
railway companies were according preferential treatment to foreign
and colonial farm, dairy and market-garden produce from ports to
urban centres as compared with home produce. The Committee
declared in their report "that the evidence tendered has failed to
show that the railway companies are giving undue preferential
treatment to foreign and colonial produce as compared with home
produce contrary to the intention and effect of existing legislation."
They found that some of the traders who complained had compared
rates which did not include terminal services with rates that did; had
quite wrongly divided what were, in effect, "through" rates, first
subtracting the full charge of the shipping company and then
assuming that the remainder could be compared with the rate from
the first; or had omitted to take into account differences in regard to
bulk of consignments, packing, etc.

In effect, no British railway rate may give a preference to foreign as


distinct from British produce so far as quantities, conditions and
circumstances are the same. The rates are to be available for like
consignments whatever the source of their origin. Where the home
producer has been unable to provide the same quantities, under the
same conditions and circumstances as the foreigner, he has equally
been unable to avail himself of a rate open to all the world. He has
had the disadvantage of the retail trader as compared with the
wholesale trader. The principle involved is practically the same as
that in operation on Continental State railways, where the traders
who can provide the biggest loads get the advantage of the most
favourable rates. On the Belgian State railways, for instance, there
are special rates for 50, for 100 and even for 300-ton consignments
which can obviously be taken advantage of by only a limited number
of traders. But while the retail man cannot expect to get the same
terms as the wholesale man, there is no adequate reason why the
wholesale man should be kept to the same level as the retail man,
and be refused the lower rates for his consignments to which he is
entitled on account of their greater bulk or better loading. The
question is certainly complicated by the fact that the wholesale man
here in question is generally a foreigner; but the railway companies
could not be required to discriminate against him, and to penalise
him on account of his nationality. The matters at issue must needs
be looked at from the point of view of a business proposition rather
than from that of expecting the railway companies to usurp the
functions of the State in carrying out a policy of Protection.

Of late years far less has been heard, in the agricultural world, at
least, of these allegations of undue preference. The whole position
has been changed through the praiseworthy efforts of the
Agricultural Organisation Society in spreading among the agricultural
community a practical appreciation of the advantages of
combination, as adopted by their foreign competitors, included in
such advantages being the lower rates which the railways already
offer for grouped or other large consignments. The excellent work
carried on by the society is calculated to confer, in many different
directions, much more benefit on market gardeners, dairy farmers
and agriculturists in general than would be gained by them simply
from seeking to persuade, or even to force, the railway companies to
carry at wholly unremunerative rates the small consignments of non-
associated producers, forwarded under the least favourable
conditions in respect to economical transport.

As regards the machinery provided by Parliament for dealing with


traders' grievances, there is, in the first place, the Railway and Canal
Commission, which, taking the place of the earlier Railway
Commissioners, was made a permanent body under the Act of 1888.
The Court consists of two Commissioners appointed by the Board of
Trade, and three ex-officio members, chosen from the judges of the
High Court, and nominated by the Lord Chancellor, the Lord
President of the Court of Session and the Lord Chancellor of Ireland
for England, Scotland and Ireland respectively; though in practice
only one of the three takes part in the proceedings in connection
with any case brought before the Court. The jurisdiction of the
Commissioners includes powers to enforce obligations under special
Acts, and to deal with questions of traffic facilities, private sidings,
undue preference, through rates, etc.

Whether or not procedure before this body is too costly for other
than wealthy litigants to take advantage of is a question which need
not be discussed here; but traders have the further advantage of
what is known as the Conciliation Clause of the Act of 1888, which
provides that "(1) Whenever any person receiving, or sending, or
desiring to send goods by any railway is of opinion that the railway
company is charging him an unfair or an unreasonable rate of
charge, or is in any other respect treating him in an oppressive or
unreasonable manner, such person may complain to the Board of
Trade. (2) The Board of Trade, if they think that there is reasonable
ground for complaint, may thereupon call upon the railway company
for an explanation, and endeavour to settle amicably the differences
between the complainant and the railway company." A resort to this
expedient by aggrieved parties involves the payment of no fees or
costs.

The eleventh report by the Board of Trade of their proceedings under


the Conciliation Clause shows that during 1908 and 1909 the number
of complaints made to them was 280—a total insignificant in
comparison with the many millions of separate transactions in which
the traders and the railway companies must have been concerned
during the two years in question. The 280 complaints are classified
as follows: Rates unreasonable or excessive in themselves, 39;
undue preference, 65; rates unreasonably increased, 22;
classification, 30; delay in transit, 27; owner's risk, 17; rebates, 23,
through rates, 15; miscellaneous, 42. Settlement or partial
settlement was effected in 91 cases; in 62 the complaints were not
proceeded with; in 122 an amicable settlement could not be arrived
at; and in five the proceedings had not been completed. "In certain
of the cases," the report further states, "in which an amicable
settlement was not reached, it seemed clear to the Board of Trade
that the complainants had no real ground for complaint."

Boyle and Waghorn are of opinion that in matters more or less


personal to the applicant, or of comparatively minor importance, the
procedure under this Conciliation Clause has saved much litigation;
though when questions of general principles are at issue the Board
of Trade, as a rule, prefer to remit the determination of them to the
Railway Commission. They further say: "The principal cause of the
comparative absence of litigation lies in the fact that a law of railway
traffic is being gradually evolved, reasonably considerate of the rights
of both parties, and adapted to the actual circumstances of the
traffic. In the early days of railways this was very far from being the
case." ("The Law Relating to Railway and Canal Traffic.")
Much of the adverse criticism of railway rates and charges which has
been indulged in of late years, without even any resort to an
inexpensive complaint to the Board of Trade, has been due to
comparisons with railway conditions in other countries.

At one time the comparison specially favoured was between English


and American railway rates; and this was persisted in until it was
conclusively shown that there was, and could be, no basis of
comparison between huge consignments, carried long distances, on
comparatively inexpensive lines, and small average consignments,
carried short distances, on the most costly railway system in the
world. The element of "the same or similar circumstances" was
obviously lacking.

Comparisons were then made with railway conditions in Continental


countries, and various tables of comparative rates were published
from time to time, in support of railway nationalisation theories or
otherwise. But many of these comparisons have been wholly
untrustworthy because, once more, they have not compared traffic
carried under the same or similar circumstances. Exceptional rates
granted, say, by the Prussian Government in the special interests of
their commercial policy, but (1) applying to large consignments sent
to a port for shipment, the rates being substantially higher when the
commodities do not go further than the port, (2) granted in
competition with routes passing through adjoining countries, and (3)
being simply haulage rates, which include no additional services
whatever, have been compared with English "domestic" rates for
smaller quantities of traffic, or, it may be, with "paper" rates for
traffic that is practically non-existent, and, therefore, has not called
for special rates, while the English rates may also include a variety of
supplementary services by the railway company (loading, unloading,
collection, delivery, warehousing, etc.), which the Continental trader
would either have to perform himself or pay for as extras.
The comparisons may thus be wholly misleading; but, assuming that
complete equality of conditions could be assured, or allowed for, and
assuming that the Continental rates were then found to be lower
than the really corresponding English ones, it would still be
necessary to remember that in this country there have been, from
the earliest period of railway development, many circumstances and
conditions, due to State policy or to other causes, which have tended
to swell to abnormal proportions the capital expenditure that the
revenue based on rates and charges must needs cover if any
reasonable return at all is to be made to the investors. There would,
in fact, be no cause for surprise if rates and charges on British
railways could be proved to be higher than those in force on the
Continent, where the conditions attendant on railway construction
and operation have differed so materially from our own. The wonder
is, rather, in view of all that I have said as to the past history of our
railway system, that British railway rates and charges should,
generally speaking, be as low as they are.
CHAPTER XXVI

THE RAILWAY SYSTEM TO-DAY

Whatever the difficulties which have attended the development of


British railways, the lines themselves have been spread throughout
the three kingdoms to such an extent that there are now very few
districts not within easy reach of a railway; while though the different
lines are still owned by, altogether, a considerable number of
companies, the physical connections between them and the
arrangements of the leading companies, not only for through
bookings but for through trains, supplemented by the operations of
the Railway Clearing House, have brought about as close an
approach to a really national network of railways, connecting all the
different sections of the country one with another, as could well be
expected in view of the lack of co-ordination when the lines were
first called into being.

At the end of 1910, according to the Railway Returns issued by the


Board of Trade, the "length of line" of the railways in the United
Kingdom was 23,387 miles. By itself, however, this figure does not
give an adequate idea of the extent of the railway system. This is
better realised by taking the figures for track mileage and sidings. A
far greater proportion of the railways in England and Wales than in
any other country consists of double, treble or other multiple track,
so that for one mile in length of line there may be two, three or more
miles of separate pairs of rails, increasing the transport facilities in
proportion. The percentage of single track to total length of line in
various countries is shown by the following figures:—

PER CENTAGE OF
COUNTRY. SINGLE TRACK.
England and Wales 33.0
Scotland 59.0
Ireland 80.2
United Kingdom 44.2
Prussian State railways 57.3
Germany (the entire system) 61.7
France (main line system) 57.0

"Track mileage" in the United Kingdom is shown in the Board of


Trade Returns for 1910 as under:—

TRACK. MILES. TRACK. MILES.


First 23,389 Ninth 24
Second 13,189 Tenth 14
Third 1,517 Eleventh 10
Fourth 1,192 Twelfth 7
Fifth 236 Thirteenth 5
Sixth 143 Fourteenth 4
Seventh 70 Fifteenth 3
Eighth 44 Sixteenth—nineteenth 1 each

Corresponding figures for the United States of America, taken from


an abstract issued in July, 1911, by the Interstate Commerce
Commission, give the following classification of track mileage,
excluding yard track and sidings:—

TRACK. MILES. TRACK. MILES.


First 240,831 Third 2,206
Second 21,659 Fourth 1,489

It will be seen from the figures relating to track mileage in the United
Kingdom that there is at least one mile of railway in the United
Kingdom which really consists of nineteen pairs of rails alongside one
another, though counting, in length of line, as only a single mile. In
the United States there seems to be no suggestion of any railroad
having more than four tracks.
The length of track in the United Kingdom is 39,851 miles. To this
must be added a further 14,460 miles, the length of sidings reduced
to single track, giving a total, including sidings, of 54,311 miles.

Rolling stock was owned in 1910 by the different railway companies


throughout the United Kingdom as follows: Locomotives, 22,840;
carriages used for conveyance of passengers only, but including rail
motor carriages, 52,725; other vehicles attached to passenger trains,
20,090; waggons of all kinds used for the conveyance of live stock,
minerals or general merchandise, 745,369; any other carriages or
waggons used on the railway, 21,360; total number of vehicles,
excluding locomotives, 839,544. These figures are exclusive of about
600,000 waggons owned by private traders.[54]

The total weight of goods and minerals conveyed in 1910 was


514,428,806 tons, and the total number of passengers carried
(exclusive of 752,663 season-ticket holders) was 1,306,728,583. The
miles travelled were—by passenger trains, 266,851,217; by goods
trains, 154,555,559; by mixed trains, 1,814,762, giving a total of
423,221,538 miles. It is difficult to grasp the real significance of
these figures; but, taking the train mileage alone the total distance
run by trains in the United Kingdom in 1910 was equal to nearly
17,000 journeys round the world, and to four and a half journeys to
the sun.

The total amount of railway capital returned as paid-up at the end of


1910 was £1,318,500,000, of which about £197,000,000, or
approximately fifteen per cent, was due to nominal additions on the
consolidation, conversion and division of stocks, showing a net
investment of £1,120,500,000. The gross receipts of the companies
during 1909 were as follows:—

PROPORTION TO
SOURCE. £ TOTAL RECEIPTS.
Passenger traffic 52,758,489 42.57
Goods 61,478,643 49.61
Miscellaneous[55] 9,688,433 7.82
————— ———
Totals 123,925,565 100.00

The working expenditure in the same period amounted to


£76,569,676, a proportion to total receipts of 62 per cent. The net
receipts, therefore, were £47,355,889, the proportion of which to
paid-up capital was 3.59 per cent.

The average rates of dividend or interest alike on ordinary and on all


classes of capital paid in the years from 1900 to 1909, were as
follows:—

YEAR. ORDINARY. ALL CLASSES.


1900 3.34 3.45
1901 3.05 3.33
1902 3.32 3.45
1903 3.30 3.44
1904 3.26 3.42
1905 3.29 3.43
1906 3.35 3.46
1907 3.31 3.45
1908 2.99 3.32
1909 3.15 3.39
1910 3.48 3.53

It is pointed out in the Returns, however, that on account of the


nominal additions made to the capital of the companies the rates of
dividend or interest given in the tables are lower than they would
otherwise be. Thus the average rates of dividend or interest for the
United Kingdom in 1910 calculated on capital exclusive of nominal
additions would show: Ordinary, 4.28 per cent (instead of 3.48 as
above), and "all classes" 4.15 (instead of 3.53) per cent.
These averages, nevertheless, allow for a large amount of capital on
which the dividend or interest paid is either nil or substantially below
the averages stated.

The rates of dividend on ordinary capital in 1910 were as follows:—

ORDINARY.
RATES OF DIVIDEND OR INTEREST. Amount of Per cent of
Capital. Total.
Nil £67,358,262 13.7
Not above 1 per cent 29,427,057 6.0
Above 1 and not above 2 per cent 18,072,847 3.7
" 2 " 3 " 87,676,759 17.8
" 3 " 4 " 109,788,247 22.3
" 4 " 5 " 38,193,955 7.7
" 5 " 6 " 85,503,721 17.4
" 6 " 7 " 54,962,066 11.2
" 7 " 8 " 362,000 0.1
" 8 " 9 " 40,000 0.0
" 9 per cent 694,907 0.1
————— ———
Total 492,079,821 100.0

The various classes of capital on which the rates of dividend or


interest paid in 1910 were either nil or not above three per cent may
be shown thus:—

RATES OF DIVIDEND OR INTEREST.


Above
1 per cent Above
and not 2 per cent
DESCRIPTION OF Not above above and not above
CAPITAL. Nil. 1 per cent. 2 per cent. 3 per cent.
£ £ £ £
Ordinary 67,358,262 29,427,057 18,072,847 87,676,759
Preferential 16,607,907 631,967 2,296,250 103,019,553
Guaranteed — — 101,180 23,318,760
Loans and
Debenture
Stock 558,782 676,789 4,666 189,122,426
———— ———— ———— ————
Totals 84,524,951 30,735,813 20,474,943 403,137,498

£538,873,205

There are those who regard railway shareholders as "capitalists," and


consider that the keeping of railway dividends at a low level,
together with any depreciation in the value of railway stock that may
result therefrom, are matters only likely to affect a comparatively few
wealthy men, and not, therefore, of material concern to the country
so long as the railways give the best possible service at the lowest
possible rates. In the United Kingdom, however, the ownership of the
railways is distributed among a far greater number of persons than is
the case in the United States, where the control and the dividends of
a great railway system may alike be in the hands mainly of a few
financiers. That by far the larger number of shareholders in British
railways have comparatively small holdings was well shown by a
table published a few years ago giving the percentage of holdings of
£500 or under by shareholders, exclusive of debenture-holders, in
thirty-nine leading railways of the United Kingdom. An analysis of this
table gives the following results:—

Number of Percentage of Holdings of


Companies. £500 or under.
2 32 to 40 per cent.
10 41 " 50 "
8 51 " 60 "
9 61 " 70 "
7 71 " 80 "
3 81 " 90 "
It is true that many of the shareholders here in question might have
invested in several companies, so that their £500 or less would not
represent the full extent of their railway holdings. On the other hand,
there is the fact that many of the single investments are those of
friendly societies, trade unions, or other organisations representing
the interests and dealing with the savings of a large number of
members of the artisan class.

In any case, whether the railway shareholder be a capitalist large or


small or only an ordinary thrifty middle-class person who has saved a
little money which he seeks to put into something both safe and
remunerative, the fact remains that since the advent of the railway
era he is the person who, though supplying the means by which this
huge system of inland communication has been brought into
existence, has had the least consideration of all. The trader, the
passenger and the railway servant have all been the subject of much
legislative effort for the protection or the furtherance of their own
interests, whereas the railway shareholder has been too often
regarded with an absolute lack of sympathy, and treated as a person
who must be severely restrained from becoming unduly wealthy at
the expense of these other interests, and should be thankful that he
is not deprived of his property altogether.

It has really seemed as though the aim alike of the State and of local
governing authorities has been less to ensure to the railway
shareholders, who have undertaken a great public work at their own
risk and expense, a fair return on their enterprise than to extract
from the railway system huge sums in the way of taxation.

What the railway companies have paid in the way of "rates and
taxes" since 1894 is shown by the following table, which I compile
from the Board of Trade Returns for 1903 and 1910:

YEAR. AMOUNTS PAID FOR INCREASE(+) or


RATES AND TAXES.
DECREASE (-) as
compared with
previous year.
£ £
1894 2,816,000 —
1895 3,011,000 (+) 195,000
1896 3,149,000 (+) 138,000
1897 3,249,000 (+) 145,000
1898 3,425,000 (+) 131,000
1899 3,582,000 (+) 157,000
1900 3,757,000 (+) 175,000
1901 3,980,000 (+) 223,000
1902 4,228,000 (+) 248,000
1903 4,493,000 (+) 265,000
1904 4,736,000 (+) 243,000
1905 4,933,000 (+) 197,000
1906 4,965,000 (+) 32,000
1907 4,863,000 (-) 102,000
1908 4,884,000 (+) 21,000
1909 5,010,000 (+) 126,000
1910 5,102,000 (+) 92,000

These figures show a continuous increase since 1894, with the


exception only of the year 1907, when there was a decrease of
£102,000 as compared with 1906, due to the activity of the railway
companies in appealing against excessive assessments. The advance
in the total paid in 1910 over the total for 1894 was no less than
£2,286,000, or 77.9 per cent.

It should be remembered, also, that the figures given relate to sums


paid for rates and taxes, and do not include the expenses incurred by
the railway companies in respect both to their rates and taxes
departments (conducted by highly skilled officers) and to litigation
arising on their appeals against assessments they consider unfair.
The total expenditure under these two heads has been estimated at
over £80,000 per annum.
Since comparisons are frequently made between English and German
railway rates, with a view to showing that the former are higher than
the latter, it may be of interest to compare, also, the amount paid for
taxation by the railways of the United Kingdom with the
corresponding payments of the Prussian State railways. The length of
line of the two systems is approximately the same; yet while the
taxation of the British system comes to £5,000,000 a year, that of
the Prussian State railways is only £750,000 a year. Naturally, when a
Government owns the railways, it is much more interested in
checking excessive taxation of the lines by the local authorities than
when the railways are owned by commercial companies; and one of
the questions to which proposals in regard to the nationalisation of
the British railways gives rise is whether, when the Government
owned the railways, they would be willing to continue the payment
from the railway revenues of all the taxation which local authorities
are now able to exact from the railway companies. Presumably not;
and in that case the trader, whether or not he got lower railway rates
from the State, would probably have to pay higher local rates in
order to make up for the tolls no longer levied, or levied only to a
much less extent, on the railway traffic.

The growth in the payments made by individual companies for rates


and taxes between 1902 and 1910 may be illustrated by giving the
figures for the London and North-Western, the Great Western and
the Midland Companies respectively:—

LONDON AND
YEAR. NORTH-WESTERN. GREAT WESTERN. MIDLAND.
£ £ £
1903 520,000 524,000 418,000
1904 572,000 558,000 435,000
1905 599,000 592,000 453,000
1906 603,000 621,000 475,000
1907 603,000 608,000 458,000
1908 610,000 638,000 436,000
1909 631,000 663,000 438,000
1910 638,000 669,000 456,000

In addition to the items coming under the head of "rates and taxes"
the railway companies still have to pay to the Government the
passenger duty of which I have spoken on page 263, their function
here, presumably, being that of honorary tax-gatherers who are
required to get the money from the British public in the interests of
the national exchequer, and save the Government the cost and the
trouble of collection. The passenger duty thus collected by them in
1910 came to £319,404, the total contributions of the railways to the
public finances for that year being thus increased to £5,421,715.
The amounts paid in 1910 by some of the leading companies under
the two heads in question may be shown thus:—

GOVT.
RATES PASSENGER
COMPANY. AND TAXES. DUTY. TOTAL.
£ £ £
Great Central 149,899 4,156 154,055
Great Eastern 322,894 14,296 337,190
Great Northern 223,254 13,099 236,353
Great Western 669,330 29,640 698,970
Lancashire and Yorkshire 261,734 18,141 279,875
London and North- 638,443 50,359 688,802
Western
London and South- 268,130 34,356 302,486
Western
London, Brighton and
South Coast 209,491 31,617 241,108
Midland 455,759 16,423 472,182
North-Eastern 467,404 12,982 480,386
South-Eastern and 278,505 53,015 331,520
Chatham
Caledonian 150,609 8,905 159,514
North British 129,486 8,721 138,207

The following table shows how the sum total of the payments both
for rates and taxes and for Government duty in the years from 1900
to 1910 work out (a) per train mile and (b) per mile of open
railway:—

PER TRAIN MILE. PER MILE OF RAILWAY.


Rates and Govt. Rates and Govt.
YEAR. Taxes. Duty. Taxes. Duty.
d. d. £ £
1900 2.24 .21 172 18
1901 2.39 .22 180 19
1902 2.53 .23 190 19
1903 2.73 .23 200 19
1904 2.86 .22 209 18
1905 2.95 .22 216 18
1906 2.87 .21 215 18
1907 2.72 .20 210 18
1908 2.77 .20 210 17
1909 2.86 .20 215 17
1910 2.89 .19 218 16

This question of the taxation of railways is a matter of material


concern as regards (1) the direct results thereof on (a) rates and
charges and (b) dividends paid—or not paid; and (2) the general
policy of the State towards the whole problem of internal
communication.

As in the case of cost of land, of expenditure on Parliamentary


procedure, of capital outlay on construction, and of any undue
increase in cost of operation, the payments in respect to rates, taxes
and Government duty can be met by the railway companies only by
one or other of two expedients: either by getting the money back
through the rates, charges and fares levied on the railway users (an
expedient necessarily curtailed both by legislative restriction and by
the economic necessity of not charging more than the traffic will
bear), or, alternatively, by leaving the railway investors with only an
inadequate return—if not, in respect to a large proportion of the
capital, with no return at all—on their investments.

The system of assessing railways for the purpose of local rating is


one of extreme complexity. It grew out of the earlier system of the
taxation of canals, and, had the railway companies fulfilled the
original expectation of being simply owners of their lines and not
themselves carriers, the principles on which the system was based
might have applied equally well to rail as to canal transport. But,
while rail transport underwent a complete change, there was no
corresponding adaptation of local rating to the new conditions, and
the system actually in force is the outcome far less of statutory
authority than of custom, as sanctioned by the judges—who have
themselves had to assume the role of legislators—while the
machinery of railway valuation differs materially in England and
Wales, in Scotland, and in Ireland.[56]

In England and Wales there is a separate assessment of a railway for


each and every parish through which it passes. Such assessment is
divided into two parts: (1) station and buildings, and (2) railway line.
The former, arrived at by a per centage on the estimated capital
value of buildings and site, is a comparatively simple matter. It is in
regard to the latter that the complications arise. The main
consideration in each case is the amount of rent which a tenant
might reasonably be expected to pay for the property assessed; and
such presumptive amount is arrived at in regard to the lines by
calculating the amount of net earnings the railway is able to make
through its occupation of the particular length of line that passes
through the parish in question, and according to the actual value of
such length of line as an integral part of one concern.

The extent of these net earnings is ascertained, in effect, by first


taking the gross receipts on all the traffic that passes through the
parish, and then making a variety of deductions therefrom. The cost
of construction of the railway does not enter into consideration at all.
The calculations are on what is called the "parochial earnings
principle"—that is to say, the amount earned in the parish, and not
the amount received from traffic arising in the parish. The railway
company may have no station in the place, and the amount of traffic
derived from the parish may be practically nil; but the assessment of
the line, on the basis mentioned, is followed out, all the same.
The main principle is the same in Scotland and Ireland, but with this
important difference in detail: that in each of those countries a
railway is first valued as a whole, the total value being then
apportioned among the several rating areas.

It will be seen that the taxation of a railway line—as distinct from


that of railway buildings—is, to all intents and purposes, the
enforcement of a toll, on all traffic carried, for the privilege of
passing through the parish concerned; while there is no suggestion,
as there was in the case of turnpike roads, that those who collect
the toll confer an advantage on those by whom the toll is paid. The
turnpike trustees did provide a road, and they were, also, under an
obligation to keep it in order. The toll-payers thus got some return
for their money, and, though the trade of the district, or of the
country, was taxed, it was, also, directly facilitated by the toll-
receivers. The railway company, on the other hand, provide and
maintain their own road, without putting the parish to the slightest
expense, yet the parish is authorised to levy upon them what is, not
only a toll, but a supplementary Income Tax for local purposes,
based on the principle of the profits the company are supposed to
make in the parish, often only because, for geographical reasons, it
is necessary their lines should pass through it in going from one part
of the country to another.

On page 114 I have told how, in the early part of the sixteenth
century, the local authorities of Worcester, Gloucester and other
towns on the Severn sought to raise funds for their local exchequers
by taxing the traders who used the river for the transport of their
commodities; and I have further told how, in 1532, it was enacted
that any person attempting to enforce such toll or tax should be
fined forty shillings. But a practice held in the sixteenth century to be
unjust in itself as well as prejudicial to the interests of trade, and
penalised by the Legislature accordingly, is considered quite right
and proper, and receives express legislative sanction, in the
twentieth century, though the local authorities upon whom the toll-
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like