|
Any suggested reading on Class's, Inheritance and class accessbility with C#?.. I'm getting my feet wet with ClassLibraries and been finding nothing but too abstract examples from .NET's help.. want to protect what can be instantiated w/out nesting class's.. trying to funnel creation thru single class. I'm sure its the bee's and not the bears in this neck of the woods but if anybody's found any good examples plz let me know..
aspiringCodeMonkey says ...
|
|
|
|
|
You Wrote : Any suggested reading on Class's, Inheritance and class accessbility with C#?
In .NET we have different class types. Say Abstract class, Selaled class , Concreate Class , Singleton class etc.
In .NET we have classical(is a) inheritance and containmnet(has a).
In .NET we have different type of access modifiers. Say Public,private,Protected,Internal,Internal Protected.
So it is very tough to explain entire concept in a small paragraph. And also it is very tough to see your requirement in one article (consolidated). So what i suggest you is search and find few article related to above mentioned keywords.
This will also help you to learn about Class Libraries
Getting Started With Class Lib
Sreejith Nair
[ My Articles ]
|
|
|
|
|
The immediate answer to your problem is to specify any classes that you only want visible within the class library as 'internal', and have one 'public' class, which is accessible to anything referencing your library. However, internal classes are completely invisible outside the class library.
Another trick is to make a class public, but make all its constructors internal, so it can only be created by other classes in the same library, but can then used by any code anywhere.
Hope that helps,
Andrew
|
|
|
|
|
How can I divide Application to FRAMES so that I can display Forms to these Frames ?
Who know please help me.
Thanks alot
change global
|
|
|
|
|
Search MSDN for the documentation for the Splitter class. It allows you to divide a form into frames.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I have a control that includes a few buttons, a drop down and a text box.
There is a property called DestinationGrid which is set at design time to be the grid the control works with. I also have another property called SelectedRow which is used to set the on the grid. Because the grid doesnt have any rows I get an error when I view the form at design time saying that SelectedRow - Object not set to an instance ...
How can I stop thsi error occuring?
I could remove the property and use a SetSelectedRow() and GetSelectedRow() method, but would like to use a property.
Any suggestions? Thanks
|
|
|
|
|
Write a intialiser in your custom class constructor. That means, in your custom control constructor you have to initalise the selected row value if the datagrid is selectable. To check whether datagrid is selectable use this dataGrid1.CanSelect property . If it is selectable then it will return true else will return false.
This is only a small idea to handle the situation.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Here is my problem. I have a vb.net form that is an FTP client, It calls a C# class for when it downloads a file. while the file is being downloaded it is in a loop in the C# class.
Info on the vb.net form dosnt get updated until the download finishes and C# class exits the loop.
how do I make the C# class update the form with download stats while sill in the loop? I need this to be able to show download speed and progress.
|
|
|
|
|
Why don't you create a thread from which you call the C# class.
Then Loop while waiting for the thread to complete, and update the form while in the loop?
Pauwll
|
|
|
|
|
how would i do that?
right now its somthing like this.
progress1.progress = 0
ftp.Download(filename)
statusbar.panels(0).text = "Done Downloading"
once it gets to the download line it starts donwloading and the program seems like its frozen until the download finishes, then it continues like normal.
|
|
|
|
|
This is because your Userinterface and Download are in the same thread, as mentioned before. A thread is linear, meaning in order to execute order 3, you need to do 1 and 2 first.
This means, if you have a thread which loops from 1 to 10 and prints, the result will be:
1
2
3
4
5
6
7
8
9
10
Your program is busy with the Download code, so it cannot execute the UI-code at the same time.
What you need to read about is "multithreading", e.g. have your computer do several things at the same time.
If you had 2 threads looping from 1 to 10, you could get:
1
1
2
3
2
4
3
5
4
5
6
6
7
7
8
9
8
10
9
10
This is because Windows decides which thread gets to execute at any time, but tries to divide processing time evenly among threads (this changes if you start messing with priorities).
Fire up MSDN (online or local) and read up on the System.Threading namespace.
If you have a static method you want to run in its own thread, just
create a new thread (Thread oThread = new Thread(new ThreadStart(myStaticMethod));) and then start this thread (oThread.Start();).
It will automatically stop after it has completed its work.
You could also use QueueUserWorkItem if you want Windows to take care of creating and starting your thread, or you could use asynchronous methods for your FTPing.
Cheers
Sebs
|
|
|
|
|
OK i got the threading figured out.
now i got the download rining in its own thread, The program is responsive while its downloading and the animations move on the form.
but i still have the same problem. how do i get the download status from the class in the new thread?
is there some way of sending info from a C# class to a vb form?
for example, have the class update a label on the form with amount downloaded so far.
|
|
|
|
|
hi !
How can I open excel file, show it on DataGrid, then save it into Database(SQLServer) ???
|
|
|
|
|
You can have a look into the COM component "Microsoft Excel 11.0 Object Library" which is avilable in IDE COM tab once you have office installed in your machine. This class will expose lot of operations which we can deal with excel files. please find MSDN for more info and code samples.
Please read this article too Working With excel
Sreejith Nair
[ My Articles ]
|
|
|
|
|
I create a user control object and show its properties through a propertygrid
object in my application. It is sure that there are 100 hundred of properties
inherited from System.Windows.Forms.UserControl and they are all showed on
the propertygrid. Is there a way i can hide all these inherited properties
and show only my user control's properties ?
|
|
|
|
|
Override the properties you want to hide (calling the base class where appropriate) and add the following attribute:
[Browsable(false)]
Note that this will only hide the property from the visual form editor, it will still appear on the Intelissense and anyone will still be able to use it.
Yes, even I am blogging now!
|
|
|
|
|
Is that the only way i can do? because I have 10 - 20 user controls and i need to hide all of inherited properties. This would be a huge task !!!! T_T
|
|
|
|
|
Tee+ wrote:
Is that the only way i can do?
Maybe not, it's the only way I know
Tee+ wrote:
because I have 10 - 20 user controls and i need to hide all of inherited properties. This would be a huge task !!!! T_T
You can try deriving a (non-abstract) class from UserControl, and hide the properties. Then, you derive all your controls from this class, instead of UserControl. It should work, but I didn't try it.
Yes, even I am blogging now!
|
|
|
|
|
humm .... let's see whether i get your idea, because i am kind of new ^^''
public class myUserControl : System.Windows.Form.UserControl
{
public myUserControl {
get all UserControl properties and override the "BroswerAttribute" for all properties
}
}
so then my created UserControl will derive from myUserControl instead of Window UserControl ?
Is this right ??? ... if so i think i will try tomorrow and i will let you know.
|
|
|
|
|
Tee+ wrote:
so then my created UserControl will derive from myUserControl instead of Window UserControl ?
Exactly. An additional advantage of doing things this way is that any similar behavior of your 20 controls (e.g., methods, properties, etc) can be added to myUserControl. This also can make easier for you to write generic code.
Yes, even I am blogging now!
|
|
|
|
|
Here is my code:
AttributeCollection attributes = properties.Attributes;
BrowsableAttribute myAttribute = (BrowsableAttribute)attributes[typeof(BrowsableAttribute)];
properties.Attributes[typeof(BrowsableAttribute)] = BrowsableAttribute.Yes;
It said it is read-only. Can i reset the browsableattribute in this way or i miss something?
|
|
|
|
|
use System.Design.dll to hide the unwanted property which is avilable from any base to your derived.
<br />
using System;<br />
using System.Windows.Forms.Design;<br />
<br />
namespace CusControl<br />
{<br />
public class MyControl:ScrollableControlDesigner<br />
{<br />
public MyControl()<br />
{<br />
}<br />
<br />
protected override void PreFilterProperties(System.Collections.IDictionary properties)<br />
{<br />
properties.Remove("BorderStyle");<br />
}<br />
}<br />
}<br />
<br />
Sreejith Nair
[ My Articles ]
|
|
|
|
|
I have tried what you have gave me ... Here is my code:
protected override void PostFilterProperties(IDictionary properties)
{
PropertyDescriptor _locked = (PropertyDescriptor)properties["Locked"];
PropertyDescriptor _name = (PropertyDescriptor)properties["Name"];
PropertyDescriptor _tabindex = (PropertyDescriptor)properties["TabIndex"];
PropertyDescriptor _location = (PropertyDescriptor)properties["Location"];
PropertyDescriptor _size = (PropertyDescriptor)properties["Size"];
properties.Clear ();
properties.Add ("Locked", _locked);
properties.Add ("TabIndex", _tabindex);
properties.Add ("Location", _location);
properties.Add ("Size", _size);
properties.Add ("Name", _name);
base.PostFilterProperties (properties);
}
Anything look good but what i found is the "Name" properties doesn't restore successfully ... what happen with that ?
|
|
|
|
|
properties.Clear (); This line put me in confusion. Just comment this and try. And the Name property is used to idetify a control no matter if it design time or run time. So i am not sure about removing Name property from Base.
please refer MSDN System.Design.Dll namespace.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Hi
How i can open window folder programmatically??
Thank
|
|
|
|