473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Creating controls in C#

Jim
I'm a little new to the C# way of doing thisgs... Although
I've done this sort of thing before in VS 6 / MFC...
creatnig controls, ActiveX controls, etc. Creating
controls in MFC is pretty straightforward and dare I say
intuitive? (well, as intuitive as you can get w/ MFC.)

Anyhow, I am wanting to create some controls of my own w/
C#. I'm not quite sure where to start though. I created
a Windows Control library project, and I get
a "Usercontrol1.cs" file / designer, now what? I tried
changing the class to inherit from a Textbox insted of a
UserControl, and my designer wouldnt' render the image
anymore, althuogh a text box did show up in my test
container, but now I'm a little stuck...

With MFC, I had a source listing of the base class so I
could tell what things I needed to override. I don't have
that in C#, and some of the functions (like OnDraw())
dont' seem to be the same, so I don't knwo where to go
from here.

What I want to create, for now at least, is just a simple
text box control for entering an IP address. I have
another post out abuot this subject, abuot the IP adderss
control that is already in Windows (somewhere) but in this
case, I want to create the control just for the practice
of doing it in C#. I am trying to get up to speed on this
now that I'll be working with it. Thanks!

JIM
Nov 15 '05 #1
2 1776
Jim,

For what you are doing, you want to derive from TextBox, as you
suspected. When you have a custom control project (or rather, add a custom
control), it assumes you want a composite control with other controls on it,
so it automatically derives from UserControl.

However, if you are looking to create a base control, then you can not
do this obviously. Deriving from TextBox is the right thing, but as you
have found, you don't get designer support. Of course, you probably don't
need it either at this point.

The Control base class has a number of overrides. Check out the MSDN
documentation, and look at the protected members specifically. These are
the ones that are overridden to give your control the functionality you
want.

Specifically, you will want to look at the following properties/methods:

OnPaint
CreateParams
WndProc

Hopet his helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jim" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
I'm a little new to the C# way of doing thisgs... Although
I've done this sort of thing before in VS 6 / MFC...
creatnig controls, ActiveX controls, etc. Creating
controls in MFC is pretty straightforward and dare I say
intuitive? (well, as intuitive as you can get w/ MFC.)

Anyhow, I am wanting to create some controls of my own w/
C#. I'm not quite sure where to start though. I created
a Windows Control library project, and I get
a "Usercontrol1.cs" file / designer, now what? I tried
changing the class to inherit from a Textbox insted of a
UserControl, and my designer wouldnt' render the image
anymore, althuogh a text box did show up in my test
container, but now I'm a little stuck...

With MFC, I had a source listing of the base class so I
could tell what things I needed to override. I don't have
that in C#, and some of the functions (like OnDraw())
dont' seem to be the same, so I don't knwo where to go
from here.

What I want to create, for now at least, is just a simple
text box control for entering an IP address. I have
another post out abuot this subject, abuot the IP adderss
control that is already in Windows (somewhere) but in this
case, I want to create the control just for the practice
of doing it in C#. I am trying to get up to speed on this
now that I'll be working with it. Thanks!

JIM

Nov 15 '05 #2
Jim
Thanks... I appreciate the info there. I hope that gets
me going ni the right direction.... I take it then that I
can remove the stuff from my class that the designer puts
in there? (the #region that says it's for the designer)
or should I just leave all that alone?

I was given to understand that migrating to C# from C++
wasn't going to be that big of a deal, but the more I see
of it, the moer I'm starting to wonder if MS just didn't
re-invent the wheel... It's a fine platform, and I'm too
new to pass judgement on it, it just seems that some
things that were once easy and intuitive have now become
obscure and in some cases (like the original IP control
from Windows) are outright absent from this new platform.

Perhaps though I am missing something-- It was / is my
understanding that .NET is supposed to replace the
previous VS / MFC way of diong things?

Years ago (liek 1991... LOL) I bought a great little
paperback called "Moving from C to C++" that gave me a
nice hands-on transition from procedural C language to the
object-orietned world of C++ (or at least as OO as you
could get before Windows... LOL) Are there any good,
concise resources on teh migration from C++ to C#, or C#
just a whole nwe ball of wax? I don't need to learn how
to program all over again, just need to learn to do the
things I already know how to do, but learn to do them ni
C#, and a basic understanding of the way apps and
components are put together in C# as opposed, for example
to C++. It all seems to be substantially different than
from what I expected, the more that i look at it. Thanks.

JIM
-----Original Message-----
Jim,

For what you are doing, you want to derive from TextBox, as yoususpected. When you have a custom control project (or rather, add a customcontrol), it assumes you want a composite control with other controls on it,so it automatically derives from UserControl.

However, if you are looking to create a base control, then you can notdo this obviously. Deriving from TextBox is the right thing, but as youhave found, you don't get designer support. Of course, you probably don'tneed it either at this point.

The Control base class has a number of overrides. Check out the MSDNdocumentation, and look at the protected members specifically. These arethe ones that are overridden to give your control the functionality youwant.

Specifically, you will want to look at the following properties/methods:
OnPaint
CreateParams
WndProc

Hopet his helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jim" <an*******@discussions.microsoft.com> wrote in messagenews:0d****************************@phx.gbl...
I'm a little new to the C# way of doing thisgs... Although I've done this sort of thing before in VS 6 / MFC...
creatnig controls, ActiveX controls, etc. Creating
controls in MFC is pretty straightforward and dare I say
intuitive? (well, as intuitive as you can get w/ MFC.)

Anyhow, I am wanting to create some controls of my own w/ C#. I'm not quite sure where to start though. I created a Windows Control library project, and I get
a "Usercontrol1.cs" file / designer, now what? I tried
changing the class to inherit from a Textbox insted of a
UserControl, and my designer wouldnt' render the image
anymore, althuogh a text box did show up in my test
container, but now I'm a little stuck...

With MFC, I had a source listing of the base class so I
could tell what things I needed to override. I don't have that in C#, and some of the functions (like OnDraw())
dont' seem to be the same, so I don't knwo where to go
from here.

What I want to create, for now at least, is just a simple text box control for entering an IP address. I have
another post out abuot this subject, abuot the IP adderss control that is already in Windows (somewhere) but in this case, I want to create the control just for the practice
of doing it in C#. I am trying to get up to speed on this now that I'll be working with it. Thanks!

JIM

.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
0
by: Jai | last post by:
Dear All Creating Custom Controls but Not User Controls,How to create custom controls,i.e Extending the functionality of the Existing Controls.(Web Custom Controls). Previously i have...
3
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
7
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
1
by: Abdo Haji-Ali | last post by:
Previously I used to create user controls if I wanted to use a specific set of controls in multiple pages, however I want to deploy my control in other applications so I thought of creating custom...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.