|
-
Apr 6th, 2013, 01:16 AM
#1
Thread Starter
Frenzied Member
VS2012 Express Custom and User Control
There are a lot of uber-awesome software developers on this site that have created some spectacular and extremely helpful posts for the codebank. However, I have found that there are a lot of really simple questions that really don’t produce many search results, either on this site or Google. It’s not always a student or hobbyist that is looking to learn something new. Take my situation, for example. I started learning VB.NET back in 2003 with the .NET framework 1.1. It wasn’t until 2006 that I was actually employed in a position where I could use my VB skills professionally. In fact, if you look at my historical posts, you will find quite a few threads from 2006 and 2007 where I was asking some pretty basic questions about binding controls to a database.
Fast forward to 2013 and I have become quite proficient with MDI data driven applications. Recently I was given a project that is taking me far beyond my comfort zone with VB.NET. I find myself asking some very basic questions on a daily basis that you wouldn’t think someone with ten years of experience would be asking. With this in mind, while I am on this journey to learning new things and expanding my repertoire , any time I have difficulty finding good examples or solid explanations I will create a post in the codebank for anyone that might be looking for the same information.
Now for the task at hand; I’m sure some people may find this utterly appalling, but in the ten years that I have been writing VB.NET applications, I have never once had the need to create a custom or user control. My current project will require quite a few user controls, so it’s time to get my feet wet.
For clarification, I am using Visual Studio 2012 Express for Windows Desktop with .NET Framework 4.5.
For anyone that is new to this subject, there are two types of controls that you can create in Visual Studio: User Controls and Custom Controls.
User Controls are the easiest to learn and the most basic. Think of them as a collection of existing controls such as buttons, text boxes and labels that you frequently place together to do similar tasks. By creating a user control, you only have to create their functionality once for use in multiple locations within your project. There are a few cons to a user control: Once you situate the child controls into your user control they remain static, which means you can’t change the layout later on. You also cannot enable themes in a user control. The biggest thing to remember is that User Controls will not show up in your toolbox for use in other projects. A user control is derived from System.Windows.Controls.UserControl.
Custom Controls are the most flexible, but also have a longer learning curve. Custom controls can implement themes and can be dynamically configured for each application. They can also be displayed in your toolbox for easy drag and drop implementation in any project. Custom Controls are derived from System.Windows.Controls.Control.
For my first project, I need to make a custom onscreen keyboard control for a touchscreen application. There are already a few examples of this such as this one by jmcilhinney:
http://www.vbforums.com/showthread.p...ard&highlight=
As much as I like John’s example, there are a few differences in my application that require me to make my own, plus making my own will help me understand the process better. However, there are a few features in jmcilhinney’s onscreen keyboard that I want to use in my own, so I promise I will give credit for any of your code that is used John!
This project will evolve in a series of posts as I get further and further along.
Now for the first obstacle:
While researching user controls, I repeatedly encountered instructions that told me to start a new Visual Studio project based on the Windows Control Library template. Here’s the catch, if you are using the Express Edition of Visual Studio, you don’t have that template!
Not to worry though. Making your own template is actually quite easy.
Step 1: Start a new project using the Class Library template, which is available in the Express Edition. Name the project “WindowsControlLibrary”.

Step 2: Right-click on the project name in the Solution Explorer and select Add > New Item. Then select User Control.

Step 3: Save and build the project.

Step 4: Export the project as a template.

Step 5: In this example we’re going to create a project template.
Last edited by Siddharth Rout; Apr 7th, 2013 at 02:59 AM.
Reason: Spelling Updated as requested by circuits2
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|