|
I learned that class consists of members(data member or member function);
but in other articles I see new terms such as property and method.
Does method can be compared to member function?
And why use properties(get,set)?
Thanks.
this is my signature for forums quoted from shog*9:
I can't help but feel, somewhere deep within that withered, bitter, scheming person, there is a small child, frightened, looking a way out.
|
|
|
|
|
zhoujun wrote:
And why use properties(get,set)?
Because you generally in C++ make variables private and provide get/set methods so you can control access. With C#, you can do that, but use a syntax that is more like accessing variables. It's nice.
zhoujun wrote:
Does method can be compared to member function?
Yes, they are the same.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
It's good object-oriented practice to use get/set for object properties, that way, you can change the underlying representation of the data without breaking the access method (get/set). The real underlying value [field] that's returned or set in get/set is either stored by the object instance, or retrieved from elsewhere, and by abstracting the get/set instead of directly accessing the underlying value allows you to change the representation without "breaking" your object clients.
In C#, a property is a kind of method function, you just don't have to call it like a function
|
|
|
|
|
Your library of 'functions' becomes your class. So a definition of class is a collections of methods that perform similar functions.
The methods can get information passed to them using parameters or you can expose properties. Likewise you can have a method that you call which sets several values internally that you can retreive using properties.
Properties is a means of exposing private information within your class to the public. An advantage of doing this is many fold:
When a public consumer of your class puts data into a property you can hide complex calculations and processes that may be applied to that data. In a simple classroom example I show someone setting the number of gallons of beer the classroom is about to brew. Internally, I break that information out into the number of gallons, number of liters, computed weight by gallon in pounds, and computed weight in grams. All the user knows is that when they set gallons they can 'easily' find out how much they are making in liters.
Another benefit is something called data hiding. If you expose your public properties using simple data types, you can shelter the user of your class from any changes in the actual data behind the scenes. Your get/set properties handle the converstion of the data from the complex data types into the simple data types without their knowledge.
In general you can think of your class like a castle. Things go on inside of it that only those who are priveledged to be inside know what is happening. The properties are like small windows in the castle that let you see glimpses of whatever you are allowed to see within the castle. If you tell a courier at the door that troops must be sent to the north wall, you don't know everything that goes on to actually get those troops there. You just know it happens and your request is satisfied.
In practice, a well managed class library can be developed and tested once. Each time it is reused you only have to test your USE of the class, not the implementation within the class.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
I am a beginner of C#. Now I have a question about how to display bitmap files in MDI form window. Following are some code I wrote :
1. In the parent form :
m_bmp = (Bitmap)Bitmap.FromFile(openFileDialog.FileName);
Form2 frm = new Form2();
frm.MdiParent = this;
frm.SetBitmap(m_bmp);
frm.Show();
2. In the child form2 :
protected override void OnPaint (PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(m_bmp, new Point(100,100));
}
About the running result, for the first time, it can successfully display a bitmap image(i1.bmp) in a child form window. But if I open another bitmap(i2.bmp) in another child form window, the previous form window will also changed to display i2.bmp.
How to solve this problem? Please help me.
|
|
|
|
|
Consider this. There's a custom control, MyCtl which displays a tree of items. It has a collection of MyItem objects. Both MyCtl and MyItem have item collections (that is, you can have sub-items, sub-sub-items, and so forth). The item collections in MyCtl and MyItem are marked as DesignerSerializationVisibility.Content, so that they are saved in the code when modified through the designer. Items can successfully be added to the item collection of the MyCtl control, through the designer (collection editor). When sub-items are added, with the Collection Editor, an "Object reference not set to an instance of an object" message comes up when OK is clicked and the sub-items are lost.
I've created a small test project to show you this behavior, along with a set of instructions, shown below.
The ZIP file of the sample project is found at:
http://www.dacris.com/collections.zip
*ZIP file updated with VS.NET 2002 project files
Here are the instructions:
1. Open the attached Zip file and extract it to an empty folder.
2. Open Collections.sln in the VS.NET IDE.
3. Build the solution to generate the Collections class library.
4. Open Form1.cs in the Windows Forms designer.
5. Select the control containing the tree of strings (it is set to DockStyle=Fill, so just click the form's client area).
6. Scroll the property grid all the way down.
7. Click the '...' button next to the Items collection property.
8. Select the third item in the list of items.
9. In the property grid for that item, select the '...' button next to the Items collection property.
10. Click the Add button on the dialog box that comes up.
11. Select the newly added item and enter a string value for the Text property (such as 'The disappearing item') in the property grid of the newly added item.
12. Click OK. Notice how the item has appeared on the control in the form, and it is called 'The disappearing item'.
13. Click OK again on the dialog box that remains. An "Object reference not set to an instance of an object" message should appear. Click OK.
14. Click Cancel. Another message will appear. Click OK to close it.
15. Click Cancel again.
Notice how the item has now disappeared from both the control and the component tray, and the Form1 window is not marked as modified (asterisk).
How can I get the items to persist on infinite depth levels? How on earth did MS do it with the TreeView and Menu controls? I am stuck and I need your help.
I shall award my full gratitude to the first person who manages to successfully add a sub-item and save it, and then explain to me how they did it.
Thanks in advance.
|
|
|
|
|
It would help if I could open VS.NET 2003 beta files.....
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
Oops..ok i'll fix that. download again in about 5 minutes. sorry
|
|
|
|
|
When a new window is created, it automatically gets focus. How do I stop that? I want to make a form but keep the focus where it is.
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
There used to be methods exposed where you would do
form.Load(); instead of form.Show();
However it does not exist in the framework.
I looked at what I would think to be the next logical method which is
form.Activate(); but at least from the popup definition, it will cause the form to load and get focus as well!!!
However, you could hope that this is misleading and try doing the form.Activate() method to load the form without showing it.
I have found it to be very, very difficult to load a form and manage it from an independant parent in the framework.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Hello, CPians around the world.;)
I don't understand your question very well, but
I guess that you want to make the parent form to get the focus
after the child dialog is created?
You can use Timer function, and after the form is created (Enabled), you can
manupulate the input focus to the parent.
I hope that this is your desire?
Please, don't send me your email about your programming questions directly.
However, if you believe that you gives me some benefits, you can send me your email.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
How do I split a string by another string?
string.split() only takes a char or a char[] as arguments.
I want to split "this is a test" into
stringArr[0] == "this"
stringArr[1] == "test"
with something like
stringArr = testString.split("is a");
|
|
|
|
|
public string[] SplitString(string value, string delimeter)
{
return value.Replace(delimeter, "|").Split('|');
}
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
You can do that with Regex.Split().
|
|
|
|
|
Thanks alot, both of you!
|
|
|
|
|
How to change the ForeColor when the control is Enabled = false? I know this is the behavior of the enabled property but if I want a different ForeColor? Is there anyway to accomplish this?
Thanks a million in advance.
|
|
|
|
|
Hi all
I'm not sure if this is a bug, but I'm a bit baffled
Consider the following (case 1):
DataRow row = table.NewRow();
for (int i = 0; i < reader.FieldCount; i++) row[i] = reader.GetValue(i);
table.Rows.Add(row);
This works, but according to MS i should use case 2 for effeciency.
Case 2:
DataRow row = table.NewRow();
reader.GetValues(row.ItemArray);
table.Rows.Add(row);
This one just returns all columns as DBNull WHy?
What am I doing wrong? All help appreciated!
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
Can anyone tell me why the GetData( DataFormats.EnhancedMetafile ) return null when the clipboard
contains metafile data.
IDataObject IData = Clipboard.GetDataObject();
Image Data = null;
if( IData.GetDataPresent(DataFormats.EnhancedMetafile) )
{
Data = (Image) IData.GetData( DataFormats.EnhancedMetafile );
}
if( Data != null )
{
e.Graphics.DrawImage( Data, new Point(0, 0));
}
|
|
|
|
|
I wanted a "folder browser" control for my application. I found several examples based on the BrowseForFolder class out there and I am able to to use them in my app. The problem I have is that I do not know how to create something like this. I understand the concept but that is about it.
I am interested in COM+/Windows API programming with C#. Can someone recommend a good book or article that explains these subjects to a COM+/Windows API beginner? I feel like a turtle flipped on its back when I run into this topic.
Matt is a network administrator for an auditing company in the midwest.
|
|
|
|
|
|
Thank you again. The MSDN link is just what I am looking for!
Matt is a network administrator for an auditing company in the midwest.
|
|
|
|
|
I have an arraylist (arrList) that has contains objects (obj). I would like to bind arrList to a datagrid with each column of the datagrid shows a member of the obj. Anyone know a 'good' way to do this aside from iterating through arrList and creating a dataset to bind to the datagrid?
Matt is a network administrator for an auditing company in the midwest.
|
|
|
|
|
Setting your datagrid's DataSource to the arraylist should do the trick...as far I understood it. You might have to make a strongly typed collection though and implement IEnumerator. I suggest downloading this http://kristopherjohnson.net/kj/TypedCollectionGenerator[^] to autocreate the derived class.
Hope it helps
"I dont have a life, I have a program." Also, I won't support any software without the LeppieRules variable.
|
|
|
|
|
Thanks for the tip.
Matt is a network administrator for an auditing company in the midwest.
|
|
|
|
|
Hi everybody!
I would like to display the image formats (. gif) in crystal reports ,
but the Solution Knowledge Base of Crystal Care Thechnical Support :
"{Crystal Reports reads the following SQL BLOB formats:
· TIFF
· BMP
· JPEG
· PNG
Crystal Reports does not support:
· gif
· TIFF files that use LZW compression}"
What is the best way to do it?
I use c#.
Thanks in advance...
|
|
|
|