|
What protocol are you using to connect to the server to check for downloads? Usually you can provide a NetworkCrediential object which contains the username and password for the server to verify.
|
|
|
|
|
I have disposed the Button named "b" but I can still access it's properties. how is it possible like its names?
private void Form3_Load(object sender, EventArgs e)
{
b = new Button();
b.Text = "Button1";
b.Size = new Size(50, 50);
Controls.Add(b);
Button bb = new Button();
bb.Text = "Button2";
bb.Size=new Size (100, 100);
bb.Click += new EventHandler(bb_Click);
Controls.Add(bb);
}
void bb_Click(object sender, EventArgs e)
{
Controls.Remove(b);
b.Dispose();
GC.SuppressFinalize(b);
GC.Collect();
if (b.IsDisposed ==true)
{
MessageBox.Show("disposed"+b.Text);
}
else
{
MessageBox.Show("not disposed");
}
|
|
|
|
|
Disposing is meant to clean up any unmanaged resources that the button uses, so for example custom paint brushes using normal WinAPI methods as opposed to System.Drawing . brushes. Usually what people do since they can't "recover" from Disposing of an object is they set it to null so that any accidental or unintentional code which uses the disposed object throws a NullReferenceException rather than work some times or not at all or works in peculiar ways.
|
|
|
|
|
If disposing of an object deals with unmanaged resources then it means object is not set free until we explicitly set it to null. What if I am done using 100 Button objects wouldn't they perserve their space in memory. Please clear me in my understanding of objects life cycle after disposing.
Thanks for answering
|
|
|
|
|
If I remember correctly then it's not safe to do anything with an object after it's been disposed because the Garbage Collector may free it up (make it null essentially) at any point.
netJP12L wrote: What if I am done using 100 Button objects wouldn't they perserve their space in memory
Set them to null after you've disposed of them:
aButton.Dispose();
aButton = null;
That'll make sure you don't access them accidentally, the GC will free them up as and when it needs space.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
On Windows when you press the start button (lower left corner) one of the entries that comes up is "my music." Part of this folders name includes the user name. For example in the following path "C:/Documents and Settings/john smith/My Documents/My Music" john smith is the user name. Since this part of the name will vary from user to user how can I open this folder on different computers with the same program?
Jason
|
|
|
|
|
you should to use dynamic USERNAME instead of john smith.
then you have to determine the USER NAME of current user programmatically.
its too easy. just search in google.
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
You're going to be treading in "murky" waters because on Vista the whole naming convention has changed. For example "My Documents" is now called "Documents" and is located:
"C:\Users\USERNAME\Documents" rather than "C:\Documents and Settings\USERNAME\My Documents" The Desktop:
"C:\Users\USERNAME\Desktop" rather than "C:\Documents and Settings\USERNAME\Desktop"
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
will return a string with the full path of the current user's My Music folder
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Dave is right,
For all those special folders you may be interested in, use Environment.GetFolderPath()
and Environment.SpecialFolder enumeration
They keep moving these things around from one Windows version to the next, so it really is the
only way to make it portable.
|
|
|
|
|
I have a struct:
public struct IITObjectPersistentID
{
public int highID;
public int lowID;
public IITObjectPersistentID(int HighID, int LowID)
{
highID = HighID;
lowID = LowID;
}
public override string ToString()
{
return "{" + highID.ToString() + "." + lowID.ToString() + "}";
}
}
I have overridden ToString(), but I want to be able to specify the normal ToString() arguments. Ie, I want to be able to get the hex display of the numbers, too, like:
IITObjectPersistentID OPIDx = new IITObjectPersistentID(25,50);
string displayAsHex = OPIDx.ToString("X");
How can I write conditional code in the override statement that lets me pass arguments to OPIDx.ToString() ?
|
|
|
|
|
You don't. You just overload ToString by writing a new ToString method that takes the argument. Just as int does.
public string
ToString
(
string Format
)
{
return "{" + highID.ToString ( Format ) + "." + lowID.ToString ( Format ) + "}" ;
}
|
|
|
|
|
I'm sorry, your code confuses me. Are you saying I just need to remove the "override" portion of my method?
|
|
|
|
|
You do appear to be saying that, then, as it worked! Thanks.
So for any subsequent readers, the answer is:
You write the first ToString method as "override" and without parameters - then you write more ToString() overloaded methods without the "override" conditional/declaration/whatever that part of the signature is.
So:
public struct IITObjectPersistentID
{
public int highID;
public int lowID;
public IITObjectPersistentID(int HighID, int LowID)
{
highID = HighID;
lowID = LowID;
}
public override string ToString()
{
return "{" + highID.ToString() + "." + lowID.ToString() + "}";
}
public string ToString(string Format)
{
return "{" + highID.ToString(Format) + "." + lowID.ToString(Format) + "}";
}
}
|
|
|
|
|
Correct, the term to remember here is "overload".
|
|
|
|
|
You don't need to override ToString if your passing arguments.
Every object has a default ToString() with no parameters, which will return the objects name. If you need your own paramaterless ToString then you use override to override the default method with the same signature.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
I'm not following you.
My struct has two fields. The default ToString() simply returns the name of the struct.
I want my ToString to either return the format I provided {122345.67879} or, say, the same fields in hex {FFFFF.00000}.
(yes I realize that's not proper hex)
So how do I write my ToString override to accept an argument (like "X")?
|
|
|
|
|
Voting 1 because you don't understand isn't going to get you very far on these forums!
I'm in a good mood today however so how about something like this?
public override string ToString()
{
return ToString(string.Empty);
}
public string ToString(string format)
{
return "{" + highID.ToString(format) + "." + lowID.ToString(format) + "}";
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks - apparently the fix is not including the "override" declaration in the second ToString() method. This was preventing it from compiling.
|
|
|
|
|
You just need to crate one more method in you structure with ToString which contains single argument. like
<pre>
public struct IITObjectPersistentID {
public int highID;
public int lowID;
public IITObjectPersistentID(int HighID, int LowID)
{
highID = HighID;
lowID = LowID;
}
public override string ToString()
{
return "{" + highID.ToString() + "." + lowID.ToString() + "}";
}
internal string ToString(string str)
{
//Do ur code here
}
}</pre>
|
|
|
|
|
Hi,
there are no optional parameters in C#; each combination of parameters results in another method.
ToString() and ToString(string) are two different methods that share their name, but not their signature
(=list of parameter types).
Object class has a ToString() but not a ToString(string).
So when you class derives from Object, it needs an override to provide its own ToString()
and it is not allowed an override keyword on ToString(string).
|
|
|
|
|
Hi,
I load sql data in datagridview, combobox, textbox but i can´t do it to statusstrip object.
At least in normal way. I pass it to other object and then to it.
Any sugestions?
thanks 
|
|
|
|
|
Can you explain in a bit more detail what you are trying to do. Putting data into a StatusStrip object is no different from other controls, the difference is that you can't do it easily through the designer (which is what I suspect you're trying to do) but you can through code.
|
|
|
|
|
hi,
I have a application with 1 form (main_form) and 6 usercontrols(login_page, menu_page, item1_page, item2_page, item3_page, item4_page).
The form has inside all usercontrols!!!
When i want to enter menu_page i edit visible = true, and visible = false to other usercontrols
i use delegates to trigger events within any usercontrol or form
it works
someone does it other way? 
|
|
|
|
|
Sounds kinda like a home-grown tab control.
At least you're using usercontrols.
You'd have to describe more about how the user navigates.
Depending on what you're doing, I would probably pop up (modal) dialogs.
Typically, when the form loads, I would pop up the login_page.
Once logged in, the user sees the menu_page.
When the user selects a menu item, I pop up the appropriate item_page.
But, like cats, there are many ways to skin it.
|
|
|
|