|
Have you ever programmed before? You can declare a variable of any type you want. This is evident in every programming language. You can use generics or types for variables, fields, properties, function parameters, and whatever you choose.
Some languages like JavaScript/JScript may declare a variable type as var (a generic), but even it has a type - the type of whatever function or object filled it (like var d = new Date(); - d is now of type Date )
Similarily, the same is true in .NET (and Java and MFC). Every class in those frameworks (and some others) derives from Object (or CObject , etc.) If you assign a different type to a generic variable, the type is still that of the type you assigned it:
object o = new Button();
o is actually of type Button , even though it is declared as an Object . You could also declare that variable as a Button , or a Control , or any base class of the Button type. Casting that object doesn't change it - merely gives you access to the methods and properties defined for that class (or inherited by base classes). For example, it wouldn't matter if the variable was declared as a Object or a Button . If you called the ToString method, the method that is called is the one declared on Button because it overrided the method of a base class. This is typically (shall I say, "standard") object-oriented programming (OOP).
I recommend you pick up a good book on .NET programming, or even just OO programming. Looking at a lot of the questions that you've posted, you should also browse around the base class library (BCL) documentation that was installed with the .NET Framework SDK and Visual Studio .NET.
This isn't a slam, but a reminder that research is only half (if not more) of development. Guessing and getting other people to do the work is not going to teach you anything. Browsing around the .NET Framework library will at least familiarize you with what is available so you have some idea of what you could use in a given problem so you don't have to reinvent the wheel. A good book on OO will help you design efficient and effective code.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
could you not add a universal handler for all of the buttons? then use
sender.GetType().Name="blabla"
Csharp™ the coder formally known as dynamic
Me.twins.duedate = DateTime.Now.AddDays(+17).ToLongDateString Me.Birthday = DirectCast(Me.twins.DueDate, DateAndTime.SameDay)
|
|
|
|
|
here's a quick example i built for you...
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
foreach(Control btn in this.Controls)<br />
{<br />
if(btn.GetType().Name=="Button")<br />
{<br />
btn.Click+=new System.EventHandler(this.Clicker);<br />
}<br />
}<br />
}<br />
<br />
private void Clicker(object sender, System.EventArgs e)<br />
{<br />
Button b=(Button)sender;<br />
MessageBox.Show(b.Name);<br />
}
hope it helps
Csharp™ the coder formally known as dynamic
Me.twins.duedate = DateTime.Now.AddDays(+17).ToLongDateString Me.Birthday = DirectCast(Me.twins.DueDate, DateAndTime.SameDay)
|
|
|
|
|
no no no thanks... I HAVE IT!
/\ |_ E X E GG
|
|
|
|
|
Hello, I have a slight problem. I have an application written in Java, but i'm rewriting it to C# currently. Now i've run into some problems since some parts of the save procedure used java serialization (of a hashtable).
Of course I need to be able to still read files made with the java version, but how can this be done? basically I would need to decode the serialized java object. Is there any documentation to be found on this subject?
does anyone have an idea?
|
|
|
|
|
misterbear wrote:
does anyone have an idea?
Yap: check on Sun's site if there is any doc on how the standard hashtables are serialized!
Once you know that,
open the files, and read them into a C# Hashtable as needed.
HTH,
F.O.R.
|
|
|
|
|
Keep in mind that the objects in the hashtable were also serialized. For the most part, if you were to use simply objects in a Java hashtable and save that to a file (I'm thinking just a simple test class with String members), you could also reverse engineer it. That wouldn't be so hard using your favorite hex editor. Depending on the complexity of the objects within it, though, that's another story.
If nothing else and worse comes to worse, you could always use the JNI concepts I cover in my article, Embedding .NET Controls in Java. The content of the article doesn't apply so much as the concept does - using JNI to bridge the gab between .NET and Java. A JNI Win32 DLL (not a managed assembly - Java won't know how to load it) to use Java calls to deserialize a hashtable and pass the members to .NET, or could even use late binding and the unmanaged CLR methods to get your .NET assembly to serialize the hashtable. Basically, this idea would be a one-time conversion utility (I recommend not overriding the old file though, or you should at least back it up).
Obviously, deserializing the hashtable would be preferred (and most likely not hard to do), but the latter idea could be handy in a worse-case scenario.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanks for the help. fortunately my hashtable is expected to contain strings only and i've found out they have a very simple serialization scheme so I'm starting to get the hang of it now.. But there are still a couple of "mystic" bytes in there =)
|
|
|
|
|
here's the code...
private void menuItem2_Click(object sender, System.EventArgs e)
{
StreamWriter fout;
if(this.saveFileDialog1.ShowDialog()==DialogResult.OK)
{
fout= new StreamWriter (new FileStream(this.saveFileDialog1.FileName, FileMode.Create));
<code>fout.Write(this.listBoxLog.Items.ToString());</code> fout.Close();
}
}
Now the line in bold...
What would I put to make it write out the whole listBox...
Or would I have to put it in an array or something first...?
/\ |_ E X E GG
|
|
|
|
|
I think this works:
foreach(Object <code>o</code> in <code>this</code>.<code>listBoxLog</code>.<code>Items</code>)
fout.Write((<code>string</code>)<code>o</code>);
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Thank you again...
/\ |_ E X E GG
|
|
|
|
|
Are dynamic textboxes or labels possible? Like for example you want to get a list of names and you want to put it in labels but you wouldnt know how many names will be sent?
"To teach is to learn twice"
|
|
|
|
|
Dynamic controls are very easy to implement. For example:
Label lblName ;
foreach(string sName in arrName)
{
lblName = New Label();
lblName.Text = sName;
myForm.Controls.Add(lblName);
}
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
Is it possible to make a program in C# that will serve as the exe file for autorun cds? if not, wat software do I use?
"To teach is to learn twice"
|
|
|
|
|
|
But wud the executable run even without the .net framework on the other pc? If not, what is the most commom dev tool used to make an autorun executable?
"To teach is to learn twice"
|
|
|
|
|
daljv wrote:
But wud the executable run even without the .net framework on the other pc? If not, what is the most commom dev tool used to make an autorun executable?
If you use any CLS-compliant language you'll need the .NET redistributable on the target machine. An alternative is to use something like Macromedia Director or Macromedia Flash (make a standalone exe). You could also use the now obsolete VB6 (and hope that they have the VB runtime DLLs)
The safest approach would be to use HTML pages (you can then have gifs, jpgs, swf etc in sub directories)
Nish
Extending MFC Applications with the .NET Framework [NW] (My book with Tom)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
Come with me if you want to live
|
|
|
|
|
but if html were to be used, wat wud i place in my autorun.inf?
|
|
|
|
|
|
Nishant S wrote:
You could also use the now obsolete VB6 (and hope that they have the VB runtime DLLs)
You'd be surprised if I tell you the number of projects done at present day using VB6.
- Kannan
|
|
|
|
|
|
But for windows client applications which needs to go into desktops of the masses, I guess people would still prefer using the RAD tools of the past.
I dont think its justified to download a 20mb runtime for a program that has a couple of dialogs. Probably thats one of the reasons we havent seen some cool products (something popular like winzip or a messenger).
- Kannan
|
|
|
|
|
Ok here is the scenario. I have an automated process manager that I am running, it is polling using the timer class every 10 minutes to see if something needs to be run.
If the window is FormWindowState.Normal the memory is between 11 - 21 meg which is fine, when I minimize the window it drops memory useage to around 600k, which is great.
However if I try to run GC after a poll and successful process run, the memory doesn't seem to get collected no matter what I try. I would expect memory to realease to at least 3 - 4 meg once the process is completed however when I call GC this doesnt happen, if I manually minimize the display the memory releases down to 600 - 800k. So I dont think I have references in place that should be there, its almost like GC doesnt fire until I minimize.
Any thoughts?
|
|
|
|
|
One other quick question is there an event that fires when FormWindowState property is changed? I cant find one in documentation but wanted to make sure I wasnt overlooking anything.
|
|
|
|