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

Best coding style for c#( 3rd)

I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?

Jun 30 '06 #1
10 1400
kiplring ha scritto:

[cut]
How can I do it?


You can write a wrapper class.

Bye,
Giulio - Italia
Jun 30 '06 #2
I will say you can't because there is no way to change your base class
properties unless you can rewrite the base class. Just leave it there and
don't use it.

If you manage to or someone can teach you how to do it then please do email
me. Thanks

chanmm

"kiplring" <ki********@hotmail.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?

Jun 30 '06 #3
kiplring wrote:
I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?


Hi Kiplring,

Just _one_ property? Do you not just use the Show() or ShowDialog()
methods?

What you could do is something like:

///
public class InputWindowForm
{
private Form _actualForm;

public InputWindowForm ()
{
_actualForm = new Form();
}

public string Message
{
get { return "foo"; }
}
}
///

And provide wrapper functions/properties to what you need. IMHO, however, I
don't really see the point. You'll probably find you're starting to need
more and more properties/methods and you'll be adding quite a lot of
wrapper functions. It also defeats the purpose of inheritance.

-- Tom Spink
Jun 30 '06 #4
Hi,

"Giulio Petrucci" <gi*************@SUPERCALIFRAGILISTICHESPIRALIDOSO .com>
wrote in message news:O6**************@TK2MSFTNGP04.phx.gbl...
kiplring ha scritto:

[cut]
How can I do it?


You can write a wrapper class.

This has the drawback (huge one) that you cannot use the new type as a
"Form" instance.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 30 '06 #5
Hi,

"kiplring" <ki********@hotmail.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.
So what is the problem with that?
So I want to hide all things except the one property
"inputWindow.Message".


Why you want to hide them?
Just create your new property and let all the others as expected. in this
way you can still use your new form as any other regular form.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 30 '06 #6
"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
wrote:
Hi,

"Giulio Petrucci" <gi*************@SUPERCALIFRAGILISTICHESPIRALIDOSO .com>
wrote in message news:O6**************@TK2MSFTNGP04.phx.gbl...
kiplring ha scritto:

[cut]
How can I do it?


You can write a wrapper class.

This has the drawback (huge one) that you cannot use the new type as a
"Form" instance.


Spot on, Ignacio, but then, the OP seems like he/she wants to hide
all 'Form' functionality, so the ability to downcast doesn't seem
appropriate anyway.

--
Hope this helps,
Tom Spink
Jun 30 '06 #7
kiplring wrote:
So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?


One way that hasn't been mentioned yet is with interfaces. Create an
interface with the one method, "Message", that you want. Then have your
form implement that interface. Whoever is using this class can just
request an instance of this interface via a factory method or something.
As a bonus (maybe) you could always cast to a Form if you needed the
extra properties. The code would look something like this (untested and
uncompiled, but you should get the point):

public interface IMessage
{
string Message{ get; set; }
}

public class InputWindow: Windows.Forms.Form, IMessage
{
...
string Message
{
//implement property here...
}
}

public class InputWindowFactory
{
public static IMessage GetInputWindow()
{
return new InputWindow();
}
}

Then just do this to use the form with one visible property:
IMessage MyInputWindow = InputWindowFactory.GetInputWindow();

HTH,
Gabe
Jul 1 '06 #8
"kiplring" <ki********@hotmail.comwrote in news:1151678429.789229.89400
@75g2000cwc.googlegroups.com:
I made a input window derived from System.Windows.Forms.Form.

What I use is just one property "inputWindow.Message".

But System.Windows.Forms.Form has so many properties, functions,
evnets.

So I want to hide all things except the one property
"inputWindow.Message".

How can I do it?
Hide from who? Programmer, designer, intellisense?

If you want to hide ie. the Text-property, you can use attributes:
[
Browsable(false),
EditorBrowsable(EditorBrowsableState.Never ),
DesignerSerializationVisibility
(DesignerSerializationVisibility.Hidden),
Bindable(false)
]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}

It will still be callable, but will not show up in designers etc.

--
Rune Huseby
Jul 3 '06 #9
Some times, I am terrified the perpectness of c#.

Gabe Moothart. Really Really Thanks.

I solved the problem with this code.

INetworkManager networkForm = new NetworkManager();

I made an interface with interface autogeneration function in "vs
2005".
And I always receive the object with the interface.

Thanks again.

Jul 5 '06 #10
Why you want to hide them?
Just create your new property and let all the others as expected. in this
way you can still use your new form as any other regular form.
Because I want to find a function with Less up&down press.

Also, if there are anyone who reuse my code, I want to outline the
function which is "Safe" to use. I don't want my code throw error with
unexpected function call. And, some programmers don't like to read long
whole "READ ME" file. The best read me file is "Just use
INetworkmanager when you use it.

I always trim my coding style for better reuse.

Currently I'm thinking there is anyway which prevent programer to use
Networkmanager class directly. ( Force him to use INetworkmanager)

Jul 5 '06 #11

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

Similar topics

1
by: kiplring | last post by:
List<string> effectList = new List<string>(); effectList.Clear(); effectList = null; using (List<string> effectList = new List<string>()) { } If there are so many calls, I should save as...
42
by: kiplring | last post by:
1. int intArr = new int; 2. int intArr = new int; rgnNumberArr.Initialize(); 3. int intArr = new int; for( int i=0; i<intArr .lenght; i++)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.