|
I have what should be a simple problem, but I'm not able to figure it out.
Suppose I have a 5 by 10 array. I populate the array, and now want to display this on a form.
The array is populated in a separate codefile, which passes the array to the main form file.
When I click on a button, I want to be able to see each row of the array i.e if the array is:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 etc etc...
Clicking the button once should give me
1 2 3 4 5 6 7 8 9 10
Clicking again should give me
11 ... 20
and so on.
How do I make this happen? I have a label named "labDisp" and a button "btnShow" on the form.
Thank you.
|
|
|
|
|
Easy - an array is a valid source for a repeater ( and that's all you need here, so why use anything heavier ? ), so store the index you're up to in viewstate, then grab the array you need from the array of arrays and make it the data source for a repeater.
Ooops - forget that if you're not doing a web page. Instead, just pass the arrays to a datagrid.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
In your form class set up a member variable like:
private int currentIndex = -1;
In your button click event handler:
currentIndex++;
if (currentIndex==5)
currentIndex = 0;
StringBuilder sb = new StringBuilder();
for(int i=0; i<9; i++)
{
sb.Append(arrayObject[currentIndex, i].ToString());
sb.Append(" ");
}
labDisp.Text = sb.ToString();
I'm assuming your array is called "arrayObject" since you didn't mention it anywhere.
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
|
|
|
|
|
I am using the C# code below (found here: http://www.codeproject.com/cs/miscctrl/dotnetcolorpicker.asp) to override the cursor/arrow keys so I can use them for my own devices.
protected override bool IsInputKey( System.Windows.Forms.Keys keyData )
{
bool bIsInputKey = true;
switch( keyData )
{
case Keys.Left:
break;
case Keys.Right:
break;
case Keys.Down:
break;
case Keys.Up:
break;
default:
bIsInputKey = base.IsInputKey(keyData);
break;
}
return bIsInputKey;
}
This does not appear to work, I have set keypreview on the form to true, that does not help.
I have tried this code in a dummy app and it works fine, and I have placed a break in the above code to see if the override is ever run - it isn't. There must be something in the rest of the code or a property that is stopping this.
Does anyone have any suggestions???? I am new to C# and have banged my head against the wall all day on this one!!!
Many thanks in advance
|
|
|
|
|
I have managed to deduce some more on this, it appears that a series of buttons within a groupbox on the form are taking the key inputs as their own.
I have duplicated this in another simple form, by turning the tabstop property for each to 'false' it prevents this behaviour.
Unfortunately the same is not true for my actual application!!!
seriously busting my head over this now...
|
|
|
|
|
Hey
I'm looking for a good book covering distributed .NET programming. Not a book that introduces .NET/C#, men covering the subject.
Hope some of you might help.
Best regards
Rasmus
|
|
|
|
|
You could try ".NET Remoting" from MS Press, McLean, Naftel & Williams.
Should do the trick.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
i found this book useful
Microsoft .NET Distributed Applications: Integrating XML Web Services and .NET Remoting
by Matthew Macdonald
|
|
|
|
|
Hi!
Here is my question
What is the code or method to detect the application's CD
when the user install or start the application?
Since the application must access the videos that are in the CD,
I need the app to automatically detect where it's cd is, and if possible,
have the cd's file uncopyable
Thanks!
Antoine
ps.: I'm writing a c# app with Visual Studio 2002 Ent, .NET 1.1, on winXP and for WinXP/2K.
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
First retrieve logical disks, If one of them has driveType 5 then it is a cdrom. Try to locate a file that you know your cd-rom contains.
you should also use System.Management in your code, i mean add it in references section of your project.
Here is the code:
ManagementClass disks = New ManagementClass("Win32_LogicalDisk");
ManagementObjectCollection moc = disks.GetInstances();
ManagementObject mo;
foreach(mo in moc){
if(mo["DriveType"].ToString() == "5"){
if(System.IO.File.Exists(mo["Name"].ToString + "\somefile.ext"){
MessageBox.Show("Correct disk in cdrom drive")
}
}
}
disks.Dispose()
I hope this helps
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
I want to have a floating window in my app. One that is always on top of the main window...
But, if I make a form and set the TopMost property to true, the window is also on top of every other application.
I mean, when working in my app it works fine, but if i open another app in front of it, my floating window is also on top of that app... Not good...
Any ideas?
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
nsms@spyf.dk <- Spam Collecting
|
|
|
|
|
|
Unfortunately you can not set the parent of a form
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
nsms@spyf.dk <- Spam Collecting
|
|
|
|
|
Oh yes you can :-p
Form.OwnedForms Property
"When a form is owned by another form, it is minimized and closed with the owner form. For example, if Form2 is owned by form Form1, if Form1 is closed or minimized, Form2 is also closed or minimized. Owned forms are also never displayed behind their owner form. You can use owned forms for windows such as find and replace windows, which should not be displayed behind the owner form when the owner form is selected."
greetz
*Niels Penneman*
Software/Dev Site Personal Site
|
|
|
|
|
The parent and the owner are too different things. Besides, to set the owner you use the Form.Owner property on the form that should be owned. The Form.OwnedForms property is a read-only property that is a Form[] array. Even replacing an element in the array won't set the Form.Owner property of the form you want owned.
-----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-----
|
|
|
|
|
Sorry, but I had never used this before so I looked it up and found the OwnedForms property and I thought, that must be it!
Nice
greetz
*Niels Penneman*
Software/Dev Site Personal Site
|
|
|
|
|
SomeForm dlg = new SomeForm();
dlg.Owner = this;
dlg.Show();
works just like
SomeForm dlg = new SomeForm();
this.AddOwnedForm(dlg);
dlg.Show();
But thanks both of you, I got my problem solved...
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
nsms@spyf.dk <- Spam Collecting
|
|
|
|
|
thanks a lot
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
nsms@spyf.dk <- Spam Collecting
|
|
|
|
|
Setting Form.Parent (inheritted from Control ) won't solve this problem. Instead, set Form.Owner of the floating windows to the Form they should always overlap. See the documentation for Form.Owner in the .NET Framework SDK for more details.
-----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-----
|
|
|
|
|
Hello everyone, really struggling here......Can someone clear up a few issues for an inexperienced C# student...I need to implement a precise timer (ie not the ones supplied invisual studio.net)I need the timer component to act 1) like the .Net timers available ie. i set a time say 2 seconds and when this time has a elapsed an event is raised? 2) the elapsed time that raises an event may be less than 1 second that is something like miliseconds. 3)i implement several of these timers in one single application (perhaps using threads)?
Basically I am communicating serially with another computer (was quite difficult using C# until I discovered somewhere that you can use the MSCOMM control)... and I need to set up several timeouts. For instance I send several messages to the other computer and for each message I expect a reply in a certain amount of time. So I send a message and then I want to start a timer... when a certain amount of time elapses say 500 milliseconds then i want an event to be raised as a visual studio timer would do..... If anybody has any comments advice snippets of code with a little explanation or even other sources of help .... i would be truly grateful!
Maria (phillips_maria@hotmail.com)
|
|
|
|
|
What's wrong with System.Threading.Timer ? The TimerCallback is executed in a separate thread which is one of your requirements. For even more accuracy (according to the .NET Framework SDK), you can use a server-based timer like System.Timers.Timer .
If you want to use native function, you have to P/Invoke it and worry about marshaling parameters (depending on the native function called). The very act of marshaling could degrade accuracy over time, whereas the System.Threading.Timer is internally managed by the CLR. The other two call CreateWaitableTimer . So, basically, either you P/Invoke the methods or use the timers that do, or use System.Threading.Timer which should be about as accurate as you can get with the class library since it's managed internally by the CLR.
-----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-----
|
|
|
|
|
Firstly I thank you for your reply (i have never used a message board before). Secondly to bug you some more... I don't know if i was told the wrong thing but i was told that for automation purposes using operating system timers wasn't a good idea... do u have any thoughts on this?
When i say automation... my application will control a couple of robots....
If say I were to use the timers that you have mentioned above ... is there a way of finding out the resolution of their Ticks? also which of the above timers should i use? And you say that this is as accurate as i'm going to get?
|
|
|
|
|
As far as the resolution of the three timers in the .NET base class library go, the System.Windows.Forms.Timer uses the native SetTimer API, which uses time in milliseconds. System.Timers.Timer uses the native SetWaitableTimer and then uses a WaitableTimer (internal class) which calls SetWaitableTimer . This native function uses ticks - or 100 nanoseconds. Unfortunately, the System.Timers.Timer.Interval property takes time in milliseconds, thus decreasing the resolution. The System.Threading.Timer is mostly managed internally, so we can't know for sure how it works, but the documentation states that the interval is also specified in milliseconds.
So, the resolution of the timers in the .NET base class library is 1 millisecond. If you want to wrap CreateWaitableTimer , SetWaitableTimer , and CancelWaitableTimer in order to use ticks for better resolution, you can. The difference in time may make up for any time spent marshaling parameters. Of course, as long as you stick with the intrinsic types (int , long , double , byte , etc.), the SDK states that no time is spent marshaling since it is unnecessary.
As far as using timers besides those provided by the OS, I'm not really sure what else you'd use besides a timer card[^]. The resolution of a few of those cards isn't any better (some are even measured in seconds!) but you might get more accurate results taking only the hardware into account. Since each will most likely come with a C SDK, you might find yourself worrying about marshaling again.
Since you mentioned in your last post that these are to control robots, I would recommend you find some resources online regarding programming robots to find out how others accomplish that. The only experience I've had is reading a little about programmable robots with their own controller boards (a former-coworker of mine did the work, but I was passively curious at best).
-----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-----
|
|
|
|
|
Dear Heath Stewart,
Thank you ... your reply has given me alot to go on!
Thanks
Maria
|
|
|
|
|
I read this on code project....
"Not long time ago, I was programming an application for Windows that every certain time had to execute a task; in the development of the project everything went with normality but arrived the day to prove the program in the definitive machines where it had to remain working, and we observed that once in a while timers stopped working. We did thousand verifications always reaching the same result, sometimes, timers provided by the Framework don't tick, no events fired. It was then when we began to look for a solution to replace these timers and the solution that seemed better to me was the one to replace them by timers of the API of Windows. We looked on the Internet in case somebody had had the same idea that I had, without success, and therefore put hands to the work."
the address for this article is http://www.codeproject.com/csharp/FTwin32Timers.asp?target=timers
Does anyone have any comments? In my application i really cannot afford for a timer not to fire.
maria
|
|
|
|