|
Are you closing the port when you're finished with it? It sounds like you're keeping it open and the program is trying to close the port when it ends - which will generate an exception if it's not available. If you need to keep the port open for the duration, you should close the port manually in the formclosing event - and again, put that inside a try/catch block.
Dave
|
|
|
|
|
Thanks DaveyM69
I try to do this
protected override void OnClosing(CancelEventArgs e)
{
try
{
sp.Close();
}
catch
{
int probe = 33;
}
}
In this case there is no exception when close the program but the program is stoped on the breakpoint in the catch.
There is something interesting.When I start the program again the all window is white for a 2 or 3 seconds and then starts normaly.
|
|
|
|
|
Hmm... Looks like it's taking a while for it to Dispose. You could try calling Dispose() or Dispose(true) and maybe even do a GC.Collect() to force the clean up.
First thing I'd do is see what exceptions if any are occurring
catch(System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.InnerException.Message);
}
Dave
|
|
|
|
|
The problem is when I unplug the USB converter from PC and COM Port is disapear any tring of using a method of instance of serial port generate exception i.e. I can't use Sp.Dispose() or SP.Close();
|
|
|
|
|
Maybe check if it's null before doing any operations?
public static bool IsPortAvailable(System.IO.Ports.SerialPort portToTest)
{
return !(null == portToTest);
}
Dave
|
|
|
|
|
Thanks DaveyM69 and sorry to loosing your time.In this moment nothing
help.Now I will relax and try again later to decide the problem
Thanks for all
|
|
|
|
|
I'm creating an excel file using c# and the ms office object library. In a few circumstances, after I've created a new worksheet tab and filled it with data, I need to go back and delete it, but unfortunately, this isn't working. My system seems to just ignore my delete command. How can I delete a worksheet I just created?
Here's some of my code. This code would delete worksheet #25:
------------------------------------------------
using MSExcel = Microsoft.Office.Interop.Excel;
private MSExcel._Application excel;
private MSExcel._Workbook workbook;
private MSExcel._Worksheet worksheet;
private MSExcel.Sheets sheet;
worksheet = (MSExcel._Worksheet)this.workbook.Worksheets[25];
((MSExcel._Worksheet)worksheet).Delete();
--------------------------------------------------
When I run this code, the program runs through each line but it simply doesn't delete that worksheet. Any idea why?
Thanks in advance.
-Goalie35
|
|
|
|
|
Try putting null to all the columns of that row. The row will be removed.
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
Hi Laddie. Thanks for the reply.
The problem is I'm not trying to remove a single row from a worksheet but rather I'm trying to remove the entire worksheet tab.
Thanks again.
-Goalie35
|
|
|
|
|
I poked around at this and almost gave up and said it was impossible.
But it looks like all you'll have to do is turn off alerts when you delete.
Your code would look something like:
excel.Application.DisplayAlerts = false;<br />
this.workbook.Worksheets[25].Delete();<br />
excel.Application.DisplayAlerts = true;
|
|
|
|
|
That was it!
Thinking about it, it seems so obvious, yet I probably never would have thought of that. Naturally, excel wants to throw up a warning before deleting the worksheet. It seems the most obvious solutions are the ones most often overlooked.
Thanks a million.
-Goalie35
|
|
|
|
|
hi,
I want to save an office file with his formats in database SqlServer 2000
and Read It from database with his formats .
thanks
Wafy
|
|
|
|
|
|
hi,
thanks for your answered but what i mean how to save with his format that
such as font ,color ,background and so on not Extension .
thanks Giorgi.
Wafy
|
|
|
|
|
When you save whole file to a database everything will be saved such as font, color and so on. You can later recreate the file by writing the content stored stored into database to a file by binaryreader.
|
|
|
|
|
Is it possible to import a table containing data(everything is indexed and ready for import) in MSAccess to SQL Server 2005 database table using C#.
The database and table is already created using C# code.If so can anybody tell me how this can be done?
While researching on the issue i heard about BCP;But even that i am not sure how exactly it works.
Thanking You
modified on Tuesday, March 4, 2008 7:10 AM
|
|
|
|
|
Hi all,
I have a flow of things I need to do, and by now I couldn't find a covenient (or any) way doing it:
1. Loading image from binary file. The image is a 3D image, and I know each slice dimentions. Each pixel in this picture is of type Int16 (2 bytes per pixel).
2. Now, I need to set the 'Image' property of my PictureBox to one of my image slices (let's say the first one).
I'll be grateful if someone could explain how to perform these procedures.
Thanks!
Eyal.
|
|
|
|
|
1) Write a test app to extract a slice and then test it by viewing it. If you don't have anything to view a slice of your 3D image with, this could be a very long day. You'll need to confirm your knowledge of how the slices are assembled in the 3D image first.
2) You'll need to know more than the pixel depth for a slice. The .Net framework will work with jpg/gif/bmp/dip/tiff/png that I recall so you'll have to convert the slice to one of these if it is not already. To do that you'll need to know the slice layout wrt it's storage technique (i.e. raster etc), any compression and the palette configuration. Then write the conversion routine (if needed) and load up the resulting image.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hi,
I think I know all there is to know regarding how my binary file is assembled. However, there are unresolved issues:
1. Can you please explain how I can create a known-format image after loading the data I need?
2. Since every pixel is represented by 16bit (2 bytes and not 1), the only way I see for loading the image is loop for reading pixel-pixel BinaryReader. Any better suggestions? FileStream.read reads 1 byte at a time...
Thanks!
|
|
|
|
|
You can use a BinaryReader to easily read Int16 values.
Create a Bitmap object with the pixel dimensions of the image that you want to show.
Get the values from the 3D data and insert as color values in the Bitmap . An easy way to set the pixels in the Bitmap is to use the SetPixel method. A more complicated way (but somehing like 100 times faster) is to use the LockBits and UnlockBits methods and unsafe code (pointer operations) to write directly to the memory area for the Bitmap .
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello,
i want to capture a Stream from an webcam. I used the Directx.dll and it worked fine. But i now need to know how to grab a single picture from the webcam and to put it into a bmp or jpeg. Does anyone know?
|
|
|
|
|
hi,
how i can retrive the selected items from the listbox at a time?
although i change the selectionmode with the multiple.
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
<br />
TextBox3.Text = "" + ListBox1.SelectedItem;<br />
}
above code retrive the only one item even that i select the more then one items.
|
|
|
|
|
Listbox provides a collection which returns all the selected items.. and you can loop through that collection to get each selected item
ListBox.SelectedItems
for more help
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref17/html/P_System_Windows_Forms_ListBox_Items.htm
|
|
|
|
|
SelectedItem retrieves the item with focus. SelectedItems returns a SelectedObjectCollection of all selected items. You can itterate through this.
Dave
|
|
|
|
|
ListBox1.SelectedItems...
|
|
|
|