|
Avoid naming the class Object, or you will have to specify the full namespace every time you use it, as there is a class named Object in the System namespace.
You can either create a typed collection for objects of the base class, or use an untyped collection, like an ArrayList or a Hashtable. For a typed collection, you can use any member that you declared in the base class without type casting the objects. For an untyped collection, you have to type cast the objects to the base class or the specific class before using them.
To check the class of an object, you use the in operator:
if (anObject is Planet) {
((Planet)anObject).SomeMethod();
} else {
((SpaceStation)anObject).SomeOtherMethod();
}
---
b { font-weight: normal; }
|
|
|
|
|
Thankyou.
Is there is any reason, or preference in using hashtables or Arraylists rather than collections?
I sort of assumed that using collections would be better to form a hierachy structure.
Such as some like....
Console.Writeline (myUniverse.SpaceObjects[0].ShipsDocked[1].ShipName.ToString())
Im guessing if I use an arraylist, then I would need to include an index field in all of my classes, to associate them to their parents?
If I'm regularly performing looping through all spaceobjects, to trigger some method for each, what would be quicker, collections or arraylists?
Or am I going down the wrong route here?
|
|
|
|
|
Hastable and ArrayList are collections.
---
b { font-weight: normal; }
|
|
|
|
|
Hi there!
I have a couple of spotlights controlled from the computer, and would like to flash these in the same beat as the music I'm playing.
Therefore i need to analyse the music i play in Winamp (or if its easyier, the main mixer) and by an lowpassfilter or equal get every beat from the music.
This couldn't be to hard i guess, because there is plenty of visual plugins to winamp reacting to Music.
Writing a winamp plugin analysing the music in winamp and sending the "beats" to my C# controlling app is one way. Or?
How to write a winamp plugin? How do communicate? How do analyse the beat?
Tell me your ideas!
----------------------------------------------
Johan Böhlin
Student at Chalmers university of technology, Sweden.
CS
johboh@student.chalmers.se
----------------------------------------------
|
|
|
|
|
Check the documentation for creating plugins for winamp. I think that there already is a beat analyzer built in, at least there was one in the Advanced Visualization Studio in Windamp 2.80.
---
b { font-weight: normal; }
|
|
|
|
|
Hi there!
Do you know any "How-to: Winamp plugin in C#", or should i use google?
----------------------------------------------
Johan Böhlin
Student at Chalmers university of technology, Sweden.
CS
johboh@student.chalmers.se
----------------------------------------------
|
|
|
|
|
Have you checked on http://www.winamp.com/ ?
Otherwise go google.
---
b { font-weight: normal; }
|
|
|
|
|
Hi there.
I have an app that has several menus. I want that when a certain menuItem(s) is/are selected other menuItems are disabled. For instance, if a user selects menuItem2 I want menuItems 10, 12 and 17 to be disabled. How do I go about coding that?
I know about Enable = false but I don´t know how to code: if such and such menuItems are selected then such and such menuItems are to be disabled.
Thanks,
FJ
|
|
|
|
|
Are you talking about menu items with CheckBox's ?
Something this simple might help:
menuItem3.Enabled = (menuItem1.Checked && menuItem2.Checked && ...);
Enjoy,
David
|
|
|
|
|
Hi.
No, what I mean is to have a menuItem like Paste grayed out unless you have something on the clipboard, one can´t paste unless something is on the clipboard. Once you have something on the clipboard Paste becomces selectable, not grayed out. I want certain menuItems to be grayed out if some other menuItem is selected.
Thanks,
FJ
|
|
|
|
|
Hi!
You can use the menu's Popup event to enable/disable the menu items of your menu, so if you have a menu myMenu you could write the Popup event handler like this:
private void myMenu_Popup(object sender, EventArgs e)
{
myMenuItem1.Enabled = SomeFunctionToDecideWhetherMenuItem1IsEnabled();
} or, using the clipboard example:
private void menuEdit_Popup(object sender, EventArgs e)
{
DataObject dob = Clipboad.GetDataObjet();
menuEditPaste.Enabled = dob.GetDataPresent(DataFormats.Text);
} Regards,
mav
|
|
|
|
|
Hi, thanks for your help.
I still don´t know how to do this. How can I disable a menuItem when some other menuItem is selected? For instance, if menuItem5 is chosen then I want menuItem11 and menuItem12 to be disabled? How do I do that?
Thanks again for your help,
FJ
|
|
|
|
|
private void menuItem5_Clicked(object sender, EventArgs e)
{
menuItem11.Enabled = false;
menuItem12.Enabled = false;
} that's as explicit as I can put it...
mav
|
|
|
|
|
Hi.
This is very clear!! Vielen Dank!
Take care,
FJ
|
|
|
|
|
Search for an ActionList component on codeproject, this should help you.
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
I want to display the status in a ProgressBar when copying large files across the network. I am using FileInfo.CopyTo method within the DoWork Method of the BackgroundWorker class (please see the code below). How am I able to fire events while the copying is taking place to update the ProgressBar. The problem is that the execution enters FileInfo.CopyTo method and does not leave until the process is complete.
Hope this makes sense.
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {<br />
<br />
BackgroundWorker worker = sender as BackgroundWorker;<br />
reached = 0;<br />
fileInfoFrom = new FileInfo(@"C:\Temp\Path1\Test.zip");<br />
fileInfoTo = new FileInfo(@"C:\Temp\Path2\Test.zip");<br />
<br />
<br />
fs = (fileInfoTo.Exists) ? fileInfoTo.Length : 0f;<br />
fileInfoFrom.CopyTo(@"C:\Temp\Path2\Test.zip", true);<br />
<br />
int completed =<br />
(int)((float)fs / (float)fileInfoFrom.Length * 100);<br />
if (completed > reached) {<br />
reached = completed;<br />
worker.ReportProgress(completed);<br />
}<br />
}
-- modified at 12:47 Sunday 4th December, 2005
|
|
|
|
|
Well, the way I'd tackle it would be to implement the File Copy function myself. I could raise events with controlled frequency as I shovel the data from the source file to the new destination file.
Regards,
Rob Philpott.
|
|
|
|
|
Do you know of any examples that I can take a look at?
|
|
|
|
|
Hi,
I've cobbled together an implementation you can use to get you started. Please note this is rough and ready and has no Exception handling in it etc. Ideally, to do the job properly I'd implement a new class and provide BeginCopy , CancelCopy and EndCopy static methods as we are encouraged to do for asynchronous methods.
BTW - because you will launch the copy on a worker thread, make sure you switch thread before attempting to update your progress bar (use Control.BeginInvoke ).
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.IO;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
FileCopy(@"f:\BTSDev Hard Disk.vhd", @"c:\test.vhd", new UpdateProgressDelegate(RelayProgress));<br />
}<br />
<br />
public static void RelayProgress(int percentile)<br />
{<br />
Console.WriteLine("{0}% complete", percentile);<br />
}<br />
<br />
delegate void UpdateProgressDelegate(int percentile);<br />
<br />
static void FileCopy(string sourceFileName, string destinationFileName, UpdateProgressDelegate handler)<br />
{<br />
byte[] buffer = new byte[1024];<br />
<br />
FileStream fsInput = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read);<br />
FileStream fsOutput = new FileStream(destinationFileName, FileMode.Create, FileAccess.Write);<br />
<br />
long totalLength = fsInput.Length;<br />
long readSoFar = 0;<br />
int percentile = 0;<br />
<br />
handler(0);<br />
<br />
int readThisBuffer = fsInput.Read(buffer, 0, 1024);<br />
<br />
while (readThisBuffer > 0)<br />
{<br />
readSoFar += readThisBuffer;<br />
int newPercentile = (int)((double)readSoFar / (double)totalLength * 100.0);<br />
if (newPercentile > percentile)<br />
{<br />
percentile = newPercentile;<br />
<br />
if (handler != null)<br />
{<br />
handler(percentile);<br />
}<br />
}<br />
<br />
fsOutput.Write(buffer, 0, readThisBuffer);<br />
readThisBuffer = fsInput.Read(buffer, 0, 1024);<br />
}<br />
<br />
handler(100);<br />
<br />
fsInput.Close();<br />
fsOutput.Close();<br />
} <br />
}<br />
}<br />
Regards,
Rob Philpott.
|
|
|
|
|
Thank you, that makes sense. Do you think this method would be slower than the FileInfo or File classes? I am sure thaey use a very similar method within those classes.
Thank you once again. Will be implementing the method.
|
|
|
|
|
Hi,
No problem, glad to be of help
Performace wise I'd expect the Framework methods to have the edge as they use unmanaged Win32 calls behind the scenes (probably the reason asynchronous methods aren't provided for us). One thing you could do if the files you are copying are very big is to increase the size of the buffer from 1KB to say 8KB or more.
Regards,
Rob Philpott.
|
|
|
|
|
I usually use special characters in many Form, in VS.NET i must use Advanced Save to change my Encoding. How i can change VS.NET 2003 to default encoding Unicode UTF 8 for all project? Thanks
Nothing
|
|
|
|
|
Hi all,
I wanted to ask if it is possible to make the combobox only accept values from its dropdown options, because you can just enter some rubbish in the combobox and then I would have to check if the chosen input actually is a valid input(ie one from the options). Is there another way to do this or I would have to validate the input against the options?
Regards,
gamehack
|
|
|
|
|
Yes, you can. Check out the ComboBox.DropDownStyle property.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thank you
|
|
|
|