|
Have one method, and have each control call it?
|
|
|
|
|
I'm very new to C#. I'm a beginner. I just need a very simple example of a ProgressBar that fills once every second for 10 seconds then goes blank and then fills every second for 10 seconds. I need this to study how it's done for something else. Many thanks if you are to help.
|
|
|
|
|
Listen, you have to start doing that, later on if you get stuck ask here for help ok? you are asking to post all the code, we are not your employees!!!
That is not hard to accomplish, i am sure you can do that!!!
Good Luck
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Put a Timer control on your form and experiment with it. The method in which you write the code is the Tick event handler.
|
|
|
|
|
Hi...
I am trying to draw a line with DrawLine method in a panel when a button is pressed ! But i cant do this outside of panel1_onPain(object sender,PaineEventArgs e) event handler.
I'll be glad if you give me an example.
ThanX !
|
|
|
|
|
you can get the graphics from panel.CreateGraphics() and use that to draw whatever you want.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
You can draw graphics anywhere you like, so you can draw anything on the screen where the panel happens to be. However, when the panel is redrawn for any reason, whatever you have drawn is gone.
Also, if you draw on the screen where the panel is and the panel is partly or fully covered by another window, you will draw on top of that window, not on your panel.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: panel is redrawn for any reason, whatever you have drawn is gone
Hi Guffa, not wanting to hijack the thread, but this is something, I've come across myself recently in a WinMobile signature capture control.
What would you suggest is the best way around that? I stored the drawing in a MemoryStream and used that in the OnPaint but it felt a bit 'hacky'.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
A MemoryStream seems to be an awkward place to save something like that. It means that you have to decode it somehow every time you use it. Whatever you store, there has to be some more convenient way to keep track of it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I create several labels at runtime, and their click event is for all labels the same.
My only problem is how to recognize which label is clicked, because now I only get the label.Text property in the eventargs which is not very usefull.
The answer must be somewhere in this messageboard but I don't know on which term I have to search.
Many thanks in advance
|
|
|
|
|
You should have sender as a parameter in your eventhandler. That's the reference to the label sending the click event.
The need to optimize rises from a bad design
|
|
|
|
|
or you can use Tag property as unique identity
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
I already looked at the sender parameter, but it didn't have any usefull properties.
Thanks to your answer I cast the sender to a label and all properties are available.
Thanks
Rob
|
|
|
|
|
On general principles you probably should check that sender is castable to a label first and chuck a messagebox otherwise. It'll avoid any embarassing crashes if you ever end up (intentionally or not) using the event handler on a different type of control.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
sender gives you access to the control that fired the event. Cast sender as a label (presumably it only serves a label) and then you have all the properties of the label available. Sender is an object and therefore has very few properties until it is recast.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
To sum up what Dan and Mycroft said above:
private void label_Click(object sender, EventArgs e)
{
if (sender is Label)
{
Label clickedLabel = (Label)sender;
}
else
{
throw new ArgumentException(
"The control that called this function was not a Label");
}
}
I've thrown an exception, but you may want to show a message box or write to the error log so the program doesn't halt, or better still catch the exception elsewhere and handle it then.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hi all.
i want to create some doc in my application then format them (bold,italic,..) and then restore them.
is there any way that i don't have to using ms word doc instead t ?
sepel
modified on Wednesday, October 1, 2008 3:02 AM
|
|
|
|
|
You could use a rich text box and save in the RTF format. Of course, you could also create your own (simplified) format, but this would be much work.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Everyone.
I'm developing an application which needs to record voice from microphone and save it in a wav file.
But the voice being recorded, isn't clear, it's lost some part something like 1-0-1-0-1-0-1...
which the 1s indicate the voice is present and the 0s indicate that there's no voice present, each ones duration is about 500ms.
Here is my code. Where is the problem?
mem2Write[uu] = new MemoryStream();
captureDeviceCollection = new CaptureDevicesCollection();
DeviceInformation deviceInfo = captureDeviceCollection[sh];
CaptureBufferDescription captureBufferDescription = new CaptureBufferDescription();
captureBufferDescription.BufferBytes = waveFormat.AverageBytesPerSecond / 5;
captureBufferDescription.Format = waveFormat;
BufferDescription playbackBufferDescription = new BufferDescription();
playbackBufferDescription.BufferBytes = waveFormat.AverageBytesPerSecond / 5;
playbackBufferDescription.Format = waveFormat;
SecondaryBuffer playbackBuffer = new SecondaryBuffer(playbackBufferDescription, device);
int bufferSize = captureBufferDescription.BufferBytes;
Capture capture = new Capture(deviceInfo.DriverGuid);
CaptureBuffer captureBuffer = new CaptureBuffer(captureBufferDescription, capture);
CreateNotifyPositions(captureBuffer, bufferSize);
//int halfBuffer = bufferSize / 2;
int tenBuffer = bufferSize / 10;
//int halfBuffer = bufferSize;
captureBuffer.Start(true);
//bool readFirstBufferPart = true;
int readFirstBufferPart = 0;
int offset = 0;
mem2Write[uu].Position = 0;
MemoryStream memStream = new MemoryStream(tenBuffer);
bStop = false;
while (!bStop)
{
autoResetEvent.WaitOne();
memStream.Seek(0, SeekOrigin.Begin);
captureBuffer.Read(offset, memStream, tenBuffer, LockFlag.None);
//readFirstBufferPart = !readFirstBufferPart;
readFirstBufferPart= (readFirstBufferPart+1)% 10;
//offset = readFirstBufferPart ? 0 : thirdBuffer;
offset = tenBuffer * readFirstBufferPart;
//TODO: Fix this ugly way of initializing differently.
//Choose the vocoder. And then send the data to other party at port 1550.
//dataToWrite
mem2Write[uu].Write(memStream.GetBuffer(), 0, (Int32)memStream.Length);
mem2Write[uu].Position += (Int32)memStream.Length;
}
|
|
|
|
|
you have to show us where is the line of your code that getting an exception then we can help you.
so where is your problem ???
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
Hei Mbah, thanks for your answer. You know, I do not get an exception. The program records the voice from the specified input and stores in in the specified output. The problem is that the recorded voice is not clear, I don't know how to explain, it's something like the voice is edged. As I said before, it is something like 1-0-1-0... where in 1s there is voice and in 0s the voice is absent.
Thank you for your help again
|
|
|
|
|
your problem is the memory administration.
//int halfBuffer = bufferSize / 2; no problem
int tenBuffer = bufferSize / 10; problem
i dont know as fix this but I would like to know
|
|
|
|
|
Hei there! Thanks for your answer. No I don't think the prob is there. You know, at first the halfbuffer=buffersizes/2; but the recorded voice was something really awful, then I made it buffersize/10, it cleared the voice somehow, but not completely. But when I tried buffersize/100 it worsened the problem.
|
|
|
|
|
Hi everyone
I'm developing an application which needs to use multiple threads. As the number of threads needed becomes known during runtime,
I have used an array of threads called "thrRec", all threads use the same method called "readBufferThr(int sh,int uu)"and pass different arguments to it.
My problem is that for example if I choose to run 5 threads, the first thread doesn't call the method properly. Next threads, have no problem, but the first one
wants to run the method in the end and passes wrong arguments to it. Here is my code:
Thread []thrRec=new Thread[chLBDev.CheckedItems.Count];
ThreadStart[] thrStrartRec = new ThreadStart[chLBDev.CheckedItems.Count];
int u=0;
foreach (int i in chLBDev.CheckedIndices)
{
thrStrartRec[u] = new ThreadStart(delegate { readBufferThr(i,u); });
thrRec[u] = new Thread(thrStrartRec[u]);
thrRec[u].Start();
u++;
}
readBufferThr(int sh,int uu)
{
//do something
}
Where's the problem?
Please help.
|
|
|
|
|
Have you tried running in the debugger to check your values?
Bob
Ashfield Consultants Ltd
|
|
|
|