|
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
|
|
|
|
|
Hei Ashfield, thanks for your answer, Yes I have tried the debugger to see whats going on in the application. In fact debugging the code, I've come to the point that it tries to run the delegate part of first iteration after all the other iterations have completed.
After completing all the iterations, it comes to the end line, increases "u" by one and then returns to the delegate line and tries to execute it with "u"s value equal to something wrong.
Thabks again for your help.
|
|
|
|
|
Hi all,
I've two Datagridview controls. Each grid has different datasources.
Eg. Datasource of grid1 is Hastable.
Datasource of Grid1 is datatable.
i want to display all the columns in both gridcontrol in the same order.
Eg if Grid1 has columns in the order like Name,Age,DOB,SAL and i want the same order in grid2 also.
i'm trying to set displayindex. but it's not displaying in the same order.and also want to add Scrollbars if necessary.
Everything has to be done programatically. can anyone help me?
thanks in advance
sri
|
|
|
|
|
So you want the event from 1 datagridview to be replicated on the other DG and the event is the sorting of the columns when the user clicks the column header. Do you start to see a pattern here.
Take a look at the events available for the DG, there are lots of them and many for the column header. Identify the one used by the DG for sorting and replicate the event on the other DG (you will need a flag to identify the source so you don't fall into an endless loop).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello,
(first im sorry for my english ist verry bad (
since 3 days i try to get the FileInfo like Author, Album, Tracknumber, Genre ect. of an audio file, but i faild.
i found an article shows exactly what i want but its in c++ http://www.codeproject.com/KB/audio-video/cmp3info.aspx[^]
Has anyone an idea how to get this informations?
thanks a lot
modified on Tuesday, September 30, 2008 1:30 PM
|
|
|
|
|
You need c# version of id3 tag library. A simple search on Google or codeproject should bring helpful results.
|
|
|
|
|
problem was to search somethink i dont know.
now i know that its called id3 tag
thank you verry much
|
|
|
|