473,387 Members | 1,485 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,387 software developers and data experts.

Sub-classing windows forms controls

I have added a Windows Forms Control Library project to my solution and
created a form control (let's call it libForm) in this new project which
inherits from System.Windows.Forms.Form. I set the Text property of this
form to the name of the application ("MyApp"). When the control library is
built and a reference added to the main project, I am able to inherit from
libForm in my main project, but the Text property on these new forms remains
the default. I have two questions:

1) Should I not expect the Text property value to be inherited from the
libForm control class?
2) With most Windows control types (textbox, label, etc.) they can be added
to the toolbox. I assume that the conventional method for implementing a
custom form class is just through the inherits statement. Is that correct?

--
Richard Carpenter

Jun 27 '08 #1
3 1211
On Sat, 12 Apr 2008 16:59:44 -0700, Richard Carpenter
<ru*******@hotmail.comwrote:
[...]
1) Should I not expect the Text property value to be inherited from the
libForm control class?
I think not. For the same reason that writing a new class that inherits
Form still has the Text property's initial value explicitly overridden by
the Designer, so too would a new class that inherits from your custom
Form-derived class. That is, the Designer treats that property specially,
and adds explicit code in the .Designer.cs file to initialize it according
to the Designer's default.
2) With most Windows control types (textbox, label, etc.) they can be
added to the toolbox. I assume that the conventional method for
implementing a custom form class is just through the inherits statement.
Is that correct?
I'm sorry, I don't really understand this question. I don't see the
connection between the two different sentences, nor does C# have an
"inherits" statement (do you simply mean the ":" used in the class
declaration?).

A custom control that shows up in the Toolbox is simply the custom class
itself. You don't get new class inheriting that custom control when you
use something from the Toolbox. You just get a new instance of that class
itself (added to whatever container you drag it to).

You can create a custom form class with the designer by using the "Add New
Form..." menu item, or similar commands. Regardless of the specific route
you take, you'll get a whole new class added to your project, already
declared to inherit the Form class (e.g. "class Form1 : Form").

The syntax for inheriting the Form class isn't just "the conventional
method". It's the only way to do it. If you want to create a custom form
class -- that is, a new class that inherits the existing Form class -- you
have to use that syntax and inherit the Form class (either directly or via
a class that itself inherits the Form class).

Pete
Jun 27 '08 #2
On Apr 12, 8:20*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Sat, 12 Apr 2008 16:59:44 -0700, Richard Carpenter *

<rumble...@hotmail.comwrote:
[...]
1) Should I not expect the Text property value to be inherited from the *
libForm control class?

I think not. *For the same reason that writing a new class that inherits*
Form still has the Text property's initial value explicitly overridden by *
the Designer, so too would a new class that inherits from your custom *
Form-derived class. *That is, the Designer treats that property specially, *
and adds explicit code in the .Designer.cs file to initialize it according*
to the Designer's default.
Interesting. I guess I'll need to set the properties in code, then.
2) With most Windows control types (textbox, label, etc.) they can be *
added to the toolbox. I assume that the conventional method for *
implementing a custom form class is just through the inherits statement.*
Is that correct?

I'm sorry, I don't really understand this question. *I don't see the *
connection between the two different sentences, nor does C# have an *
"inherits" statement (do you simply mean the ":" used in the class *
declaration?).
Yes, apologies, that's exactly what I meant.
A custom control that shows up in the Toolbox is simply the custom class *
itself. *You don't get new class inheriting that custom control when you*
use something from the Toolbox. *You just get a new instance of that class *
itself (added to whatever container you drag it to).

You can create a custom form class with the designer by using the "Add New*
Form..." menu item, or similar commands. *Regardless of the specific route *
you take, you'll get a whole new class added to your project, already *
declared to inherit the Form class (e.g. "class Form1 : Form").
Yeah, that's the way I'm used to doing it. I was just wondering if
there was something I was missing.
The syntax for inheriting the Form class isn't just "the conventional *
method". *It's the only way to do it. *If you want to create a custom form *
class -- that is, a new class that inherits the existing Form class -- you*
have to use that syntax and inherit the Form class (either directly or via*
a class that itself inherits the Form class).
Thanks a bunch for the reply.

--
Richard Carpenter
Jun 27 '08 #3
Lav
Can you paste the code where you find the behavior strange ?
Jun 27 '08 #4

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

Similar topics

5
by: John Dewbert | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Hello, I have trouble passing a folder object (from a FileSystemObject) to a sub procedure. Consider the following code: ...
2
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not...
5
by: Colleyville Alan | last post by:
I have a sub that can do two different tasks based on the value of one variable. So I'd like to have two different buttons on the same form run this, but each one setting a flag so that the...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
3
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
10
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal...
12
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to...
5
by: Sharon | last post by:
Hi all. To prevent access to a sub system internal types, is it necessary to create the sub system in a different project, and use the internal access level? Or is there another way that will...
6
by: Bob | last post by:
Hi, I found this code here below (about cartitems and shoppingcart) and I have two questions about sub New(). In the first class CartItem, there is two times sub New(): Public Sub New() End...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.