Thank you Heath for your respons and it
I added to my Main class:
private void DrawScanArea(MyButtonLib.MyButton btnRect)
Rectangle rect = new Rectangle(btnRect.Location, btnRect.Size);
ThePanel.StoredRect = rect;
To my panel class:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
if (rStoredRect != Rectangle.Empty)
Pen pen = new Pen(Brushes.Blue, 5f);
The problem is that the button hides the rectangle(it paints the button over)
I've tryed to put the OnPaint(..) in my Main class, and the ofcourse the panel hids the rectangle.
I tryed to put it in my button class:
private Rectangle scnaRect = Rectangle.Empty;
public void DrawScanArea(Rectangle rect)
scnaRect = rect;
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
if (scnaRect != Rectangle.Empty)
Pen pen = new Pen(Brushes.Blue, 5f);
But it won't draw the rectangel at all.
What to do?
You're original response stated that you wanted the rectangle drawn around the button. If you would've stated your intentions correctly, I could have given you a good idea of what to do the first time. You also could've used a number of methods from the ControlPaint class in System.Windows.Forms, but for your needs as stated originally I knew this wouldn't work for you.
In any case, you must understand how painting works and how client coordinates are calculated. When you put the painting code in your main form (assuming your Panel wasn't docked), the coordinates where in the client-space of the form, not the panel. Client coordinates are calculated in terms of the container. A Form is a container, just as a Panel is a container. Also, if a Controls handles it's own painting, the painting effects of the container class are not easily made visible (there's a number of things that must be set correctly) because they have two different HDCs that are managed for each control.
Not exactly a C# question, but is there an algorithm that will sort points in a cyclic order? To elaborate the problem, I have a set of points describing the boundary of a closed region. But they are in random order. I want to sort them in such a way that interconnecting adjacent points in the array will recreate the boundary. For example, if (0,1),(1,1),(0,0),(1,0) are given, the result should be (0,1),(1,1),(1,0),(0,0).
If each pair is unique, then you shouldn't have too much problem with this. Once you pick your starting pair, find the next pair in which the first point corresponds to the last point of your starting pair and continue that way, optionally validating when all the points have been sorted that your last pair/last point corresponds with your first pair/first point. Unfortunately, this is an O(n*n!) operation. This could be improved if you also pre-sorted the remaining pairs according to their starting point as you enumerated them each time.
I've been currently doing as you said, but it is inefficient, and wanted to know if there was a faster algorithm. To complicate matters, the list of points might contain disjoint region boundaries.
thanks for answering me for the previous question but as i didn't deal with SDKs before i don't know how to perform the task so again please, i have a task which needs to catch voice from microphone and deal with it as binary bits so i need a code sample that records or catches voice from mic
Then now's your time to use an SDK. It's not rocket science. What do you think the .NET Framework SDK consists of? And SDK is nothing more than documentation, libraries, and tools. The Speech SDK contains ActiveX controls that are registered on the system than you can add to your toolbox in VS.NET and drag to your form to create COM interop assemblies. You must read the SDK documentation - however briefly - for information on which ActiveX controls to use and what methods and properties are available.
If you want to translate voice into text, this is not an easy thing to do and the Speech SDK is one of the de facto ways of doing this.
If all you want to do is record the microphone input to a WAV file, then you'll have to use the DirectX SDK, which you can download from http://msdn.microsoft.com/directx[^]. This is not something as easy as you think. Specifically, you'll want to read about the Capture class in the Microsoft.DirectX.DirectSound namespace. There's even an example called "CaptureSound" that does what you need.
I have web service with a windows client , sometimes when I call the web service this error happend:
Client found response content type of '', but expected 'text/xml'.
The request failed with the error message:
<HTML><HEAD><META HTTP-EQUIV="REFRESH" CONTENT="0" URL="http://myhost.com/WS.asmx"></HEAD><BODY>
It is happend by chance and I donn't no any reason, cause if I close my application and open it again and call methods with the same datait does not happend.Any idea?
The web service isn't sending the Content-Type of the response, and I notice that it's <meta> tag is formatted incorrectly. URL is not a valid attribute, and the CONTENT attribute should also look like this:
I'm guessing you don't have control over the WS. In any case, it appears that the WS is trying to redirect you to a new URL in a bad way. With WS's, they should actually send the 301 or similar HTTP status code. A web service proxy isn't required to understand HTML content like this, and it would be crazy to assume that one would.
If you have control over the WS, change this behavior. If you don't, contact the host/developer.
Finally, if the server is sending a 301 (or similar) in addition to the content of the page (which is odd, but possible), make sure you set your web proxy's AllowAutoRedirect to true (the default is false).
Heath Stewart wrote: If you have control over the WS, change this behavior
Actually I'm the developer of that WS , but I couldn't understand how should I change that behaviour. This behaviour sometimes happend and I don't know in what condition it happen. Do you know what cause this?
Heath Stewart wrote: make sure you set your web proxy's AllowAutoRedirect to true
I don't have VS.NET now to test but I check the MSDN. Is that something that I should set in the client before the first call of it and its part of web service class?
ASP.NET is trying to redirect the call to your WS for some reason. The weird part is that it's sending HTML to do so (hence the META HTTP-EQUIV="refresh", which is the same as the HTTP Refresh header). I honestly don't know what could be causing this. If the WS call needs to be redirected (and that's one of the problems), it should simply send the HTTP status codes accordingly - not content. Stopping the redirect would be your best option if you can figure out why it is trying to redirect.
There's already a ton of tools that do this, such as Mozilla (http://www.mozilla.org[^]), which is a completely open-source browser and has tools similar to Mac's Sherlock technology. It has definitions for many search engines and collects all the results and displays them. Since it's open source, you can look at their implementation for an example.
It's really not a difficult problem, though. You just need a way to get results from search engines. Some - like Google - expose XML Web Services while others you can scrape the results (this is what mozilla does) from the pages. You then put all these results in a collection and display them.
Write your own custom collection editor and make a deep copy of the object which you're trying to edit before displaying it in the collectio editor form you'd create. The reason this is happening is because the collection editor is responsible for editing the collection. The objects in that collection are references to objects elsewhere, something the collection editor does not care about. By making a deep copy of the collection you are creating new objects to which the collection of objects reference. Depending on your implementation, though, this might now work.
Say that the collection references a bunch of controls in your form. If you make a deep copy, edit it, and replace the original copy you have to remove all the old controls from the Controls collection of the control or form and add the new ones. If all the collection contains is a bunch of strings, ListViewItems, etc., then this is probably okay to do.
You could make it easy and extend the CollectionEditor, override EditValue, and re-use the CollectionEditor.CollectionForm. Just remember to change the EditorAttribute on the property that is of the collection Type (or on the collection class itself).
One final option uses the DesignerTransaction, though I don't know if it'll work in this case. Since an IServiceProvider is passed to the UITypeEditor.EditValue, you could try getting the IDesignerHost service and call CreateTransaction on it to create an associated DesignerTransaction. You can then commit or undo a batch of operations. You could do something like this:
protectedoverrideobject EditValue(ITypeDescriptorContext context,
IServiceProvider provider, objectvalue)
DesignerTransaction trans = null;
IDesignerHost host = provider.GetService(typeof(IDesignerHost));
if (host != null)
trans = host.CreateTransaction();
IWindowsFormsEditorService forms = provider.GetService(typeof(
CollectionForm form = new CollectionForm(this);
form.EditValue = value;
DialogResult result = form.ShowEditorDialog(forms);
if (result == DialogResult.OK)
value = form.EditValue;
if (trans != null) trans.Commit();
elseif (trans != null) trans.Cancel();
if (trans != null) trans.Cancel();
This is a very simple example and untested, but the concept is sound so long as you can use the DesignerTransaction from this context (and I don't see why you couldn't). Read the documentation for the DesignerTransaction in the .NET Framework SDK for more information and an example.
We have developed a C# application with Studio 2002 and framework 1.0.
In this app, we have about 10 sockets that communicate through tcp/ip and we
also have some 'platform invoke' calls to a third party dll along with numerous
calls to a SQL 2000 Server to log different events.
Today we had a 'crash' and the following popup was displayed:
Microsoft Visual C++ Runtime library
Expression: 1 == pConnection->fCallCheck
ABORT RETRY IGNORE
If we press ignore the program just continues and everything seems to be working.
But does anyone have a clue what has happened?
Could it be our program that does something wrong?
Could it be something in the framework?
Could it be the third-paty dll?
OR COULD IT BE SOMETHING WITH SQL SERVER? (I've found an article that suggests this)
Exactly what Mazdak said. The error happened in the VC++ runtime, not the CLR. If something croaked in the CLR, you'd get a SystemException (or derivative) and the dialog looks different and contains different information.
Since the error message is also giving you a filename, it's possible that you have debug symbols on your machine for the third-party library so you might want to try debugging your app.
In any case, it is possible that you called a P/Invoked function with a bad parameter and their library isn't validating params correctly, but the error still occured in their native library.
There is nothing in the .NET base class library that can do this out-right. There are, however, many articles here on CodeProject that deal with communicating to a few of these (I know they exist for serial and parallel ports). Just use the search at the top of any page.