|
selcuks wrote: But what if I should received the path information as a parameter to my main() method?
The reason you use \\ is because \ is used to escape characters, for example, \" is how you put a quote. You have another option:
@"c:\Program Files\Atalasoft\DotImage 6.0"
will work fine, the @ means that \ means \. The \\ actually is turned into \ in your final string ( although the debugger will show \\ ). So, if you pass a parameter, it should be a single \, because \\ is in fact how you tell the compiler to emit a single \, if you've not put @ at the front of the string.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ive been developing an interface that updates a schematic with dimension lines and re draws different parts based on selection from radio buttons.
The problem is when I go to delete part of the drawing and draw a different part. The only method I have for erasing is to paint over the drawing with a white pen, but now when I mouse over the control the Diagram flickers remains of the painted over drawings.
Ive read some articles about double buffering, but was hoping there was something else I could do without a major setback.
|
|
|
|
|
Your design is incorrect. You drawn parts should be objects that you can manage.
|
|
|
|
|
This is a MAJOR setback. What you need to do, is collect details of lines to draw, and draw them on the screen in the paint event, not ever drawing them on the image. Then you can just undo any line you want.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Yea I really didnt know anything about painting when I started so went about this in the completely wrong way. You say collect details of lines to draw and put them all into 1 paint event. Right now I have dozens of paint events that are called. The diagram has to update in real time every time the useer changes a textbox or radio button so it had to draw a lot.
|
|
|
|
|
Cozmo23 wrote: Right now I have dozens of paint events that are called
How is that possible ? A control has one paint event, and one only.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi..
I Need to Draw a sine wave on the form based on the X and Y values. I have stored those values in List variable..
How can i draw a continuous sine wave using GDI+ using C#
|
|
|
|
|
In the Graphics class you have the DrawLine, DrawLines, DrawBezier and DrawBeziers methods. Use whatever fits the kind of data you have in the list.
To draw graphics on a form, use the Paint event of the form or of a control on the form. A graphics object that you should use for the drawing is send in the event arguments to the event handler.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
But How can i get a continuous sine wave using Drawline, etc..
I have 100 samples from ADC, now i need to draw a waveform in winForm. Can u suggest me some link where can i get the complete information abt thid..??
|
|
|
|
|
DrawLines takes a Point[] , what is the problem?
|
|
|
|
|
When i increase the HZoomFactor (zoom in). the waveform that is displaying is not looks like Sine wave.. What can i do for that..?
Can i Get any Examples on GDI+.
|
|
|
|
|
Use DrawCurve rather then.
Actually I have no idea what you mean by that. What does it look like if it does not look like a Sine wave?
|
|
|
|
|
When you zoom in you need to redraw your sine wave in OnPaint ().
Because pixels on the screen are discrete, any "curve" you draw is only an approximation at a given level. Zooming in gives you more pixels per measurement unit, magnifying the approximation errors from the previous curve, so it needs to be redrawn.
|
|
|
|
|
There is no method that can draw a sine wave. You have to divide the wave into lines or curves, and draw them individually. The DrawLines method takes an array of Point values, so that you can draw several attached lines in one call.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yes i tried and i got the solution for my problem, initially i was trying with Drawline so im not able to draw properly, using Drawlines it is coming properly..
Thank you.
Guffa
|
|
|
|
|
if the problem is that you require smoothing between points you could use something like a bezier curve to draw your sine wave
|
|
|
|
|
Hi,
We are using a C++ dll from our C# code.
The C++ code reads data from a serial communication port, and fills up a buffer with the data read.
We are sometimes experiencing a big delay (around 5 seconds) when the C++ function returns.
The C# code looks something like this:
class Program
{
[DllImport("SerialCommunication.dll", EntryPoint = "SerialCommRead", SetLastError = true)]
protected static extern unsafe SERIAL_COM_STATUS SerialCommRead(uint handle,
[MarshalAs(UnmanagedType.LPArray)] byte[] buffer,
uint length, [MarshalAs(UnmanagedType.LPArray)] uint[] bytesRead);
protected void Read()
{
StreamWriter logWriter = new new StreamWriter("test.log", true);
SERIAL_COM_STATUS status = SerialCommRead(m_PortHandle, m_ReadBuffer,(uint)m_ReadBuffer.Length, bytesRead);
DateTime t = DateTime.Now;
logWriter.Write(t.Day.ToString() + "/" + t.Month.ToString() + "/" + t.Year.ToString() + " " +
t.Hour.ToString() + ":" + t.Minute.ToString() + ":" + t.Second.ToString() + "." +
t.Millisecond.ToString() + " ");
logWriter.WriteLine("After SerialCommRead(), status: " + status.ToString() + " bytesRead: " +
bytesRead[0].ToString());
logWriter.Flush();
}
}
The C++ code:
__declspec(dllexport) SERIAL_COM_STATUS SerialCommRead(HANDLE handle, unsigned char *buffer,
unsigned int length, unsigned int *bytesRead)
{
COMSTAT ComStat;
DWORD errorFlags, err;
*bytesRead = 0;
OVERLAPPED overlappedRead;
memset(&overlappedRead, 0, sizeof(OVERLAPPED));
overlappedRead.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!overlappedRead.hEvent) {
err = GetLastError();
return(SER_COM_CREATE_EVENT_ERROR);
}
if (!ClearCommError(handle, &errorFlags, &ComStat)) {
err = GetLastError();
CloseHandle(overlappedRead.hEvent);
return(SER_COM_READ_ERROR);
}
if (!ComStat.cbInQue) {
CloseHandle(overlappedRead.hEvent);
return(SER_COM_OK); // There is nothing in queue to read
}
DWORD numOfBytesRead = 0;
if (!ReadFile(handle, (LPVOID)buffer, (DWORD)length, &numOfBytesRead, &overlappedRead)) {
err = GetLastError();
if (ERROR_IO_PENDING == err) {
DWORD res = WaitForSingleObject(overlappedRead.hEvent, SER_COM_OVERLAP_READ_TIMEOUT);
switch (res) {
case WAIT_OBJECT_0:
if (!GetOverlappedResult(handle, &overlappedRead, &numOfBytesRead, TRUE)) {
err = GetLastError();
CloseHandle(overlappedRead.hEvent);
return(SER_COM_GET_OVERLAP_ERROR);
}
break;
case WAIT_TIMEOUT:
*bytesRead = (unsigned int)numOfBytesRead;
CloseHandle(overlappedRead.hEvent);
return(SER_COM_TIMEOUT_ERROR);
case WAIT_FAILED:
err = GetLastError();
*bytesRead = (unsigned int)numOfBytesRead;
CloseHandle(overlappedRead.hEvent);
return(SER_COM_WAIT_ERROR);
default:
*bytesRead = (unsigned int)numOfBytesRead;
CloseHandle(overlappedRead.hEvent);
return(SER_COM_ERROR);
}
} else {
CloseHandle(overlappedRead.hEvent);
return(SER_COM_READ_ERROR);
}
}
CloseHandle(overlappedRead.hEvent);
*bytesRead = (unsigned int)numOfBytesRead;
PrintToFile("SerialCommRead(): going to return");
return(SER_COM_OK);
}
void PrintToFile(char *str)
{
struct _timeb timebuffer;
_ftime( &timebuffer );
char timeline[26];
ctime_s( timeline, 26, & ( timebuffer.time ) );
static FILE *fHandle = NULL;
if (NULL == fHandle)
{
// First time, open th file
fHandle = fopen(“test2.log”, "wt");
}
if (fHandle) {
fprintf(fHandle, "%.19s.%hu ", timeline, timebuffer.millitm);
fprintf(fHandle, "%s\n", str);
fflush(fHandle);
}
}
In file “test2.log” the printout of “SerialCommRead(): going to return” appears with a timestamp that is sometimes 5 seconds earlier than the printout to “test.log” from the C# code.
Looks like it takes the C++ function 5 seconds to return…
Any ideas?
Thanks,
Galit.
|
|
|
|
|
ive got an idea...
PUT YOUR CODE IN [pre] and [code] TAGS!!!
no one wants to read unindented code. especially if its as much code as you posted
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi Guys. I have an application that writes a bunch of records to Excel. At the end of writing the data I need to sum a column. However, I don't know how many records there will be in the file so I can't set the range to sum in the code. I tried this by setting it something like the below but for some reason it doubles the Total that is summed.
I need to know how to get the last range and set that in the formula dynamically.
objRange = objSheet.get_Range("E1", System.Reflection.Missing.Value);
objRange.Formula = "=SUM(J4:J50000)";
objRange.FormulaHidden = true;
objRange.Calculate();
objRange.Font.Bold = true;
objRange.Font.ColorIndex = "5";
From the above I am selecting cel E1 and in this cell I have the formula to sum the totals of the data in Column J. As I don't know what the last line of data is going to be I set the final cell to calculate as J50000.
Can somebody please help me with this??
Cheers
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
int lastUsedColumn = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing).Column;
int lastUsedRow = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing).Row;
should tell you the last used row and column
|
|
|
|
|
Thanks mate. Then how do I use that in the formula. Sorry for asking.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
instead of summing from J4 to J5000 sum from J4 to J[last used row]. then you won't be including any extra rows in your sum
|
|
|
|
|
Brilliant. I'll give that a shot.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi Jimmanuel. I have used the below and I get an error when it does the calculation. Am I doing this right?
int lastUsedRow = objSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,
Type.Missing).Row;
And this is where I add it into the formula.
objRange = objSheet.get_Range("E1", System.Reflection.Missing.Value);
objRange.Formula = "=SUM(J4:J[lastUsedRow])";
objRange.FormulaHidden = true;
objRange.Calculate();
objRange.Font.Bold = true;
objRange.Font.ColorIndex = "5";
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
objRange.Formula = string.Format("=SUM(J4:J{0})", lastUsedRow);
it might also be a good idea to do some error checking to make sure that lastUsedRow is valid. I don't know what would happen if you tried summing from J4 to J0 for instance . . .
|
|
|
|