|
You need to either use a picturebox ( this is for girls ), or draw the image yourself. You need to set a timer, and handle your paint event. Your timer needs to call Invalidate() to force a paint message, and your paint event needs to draw the image in the right location.
Actually, if you use a picturebox, your timer event can set it's location without having to Invalidate(), but that solution doesn't scale well if you have a lot of images.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank You very much !
Keep in touch
|
|
|
|
|
Hi,
I'm fighting with performance problems in application which displays data from sound card on the fly.
How can I suppress repaintig a form everytime I move other window over the form or scroll it?
Can I control painting the form only programmaticaly, makes the form holds its state when other window covers it and simply ignore such an events?
|
|
|
|
|
-raada- wrote: How can I suppress repaintig a form everytime I move other window over the form or scroll it?
You can't.
-raada- wrote: Can I control painting the form only programmaticaly, makes the form holds its state when other window covers it and simply ignore such an events?
What you are asking is, you want the form to not refresh itself when it is obscured. If the form is covered, it won't paint itself. It will paint itself when it is uncovered again, or it will be blank.
You can set the AllPaintInWMPaint ( something like that ) control flag, and override the Paint event to control exactly what gets painted. You could set flags within the program which cause this event to do nothing, but, of course, your program will then be ugly.
How do you know that the paint event is your performance problem ? What are you painting ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I know it because when the painting module is not attached the problem doesn't exist. (Module works with already preprocessed data and doesn't do much other thing then just paint them.)
Each sample is represented by array of double values which represents intensity of given frequency in that sample - when it's bigger than a threshold I paint a line at proper place (x axis is time y frequency)
When I repaint the whole signal when new sample was processed - it was unbearable.
Painting is executed in separate thread and I couldn't achieved satisfying results by just set time interval for repainting the signal.
So now I paint just individual samples by calling InvalidateRectangle method and whole signal when Paint event is fired not programmaticaly. But still not satisfyed.
I was asking just to be sure if I have to optimalize painting algorythm or I'm missing something else.
|
|
|
|
|
It does sound like your actual painting code needs optimising. Not drawing parts of it, is not optimisation.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
how much data is there to paint ? More samples than pixels in a row ?? If so, reduce the paint work
by either skipping or taking an average value.
It might help to show some code (and some typical values).
|
|
|
|
|
Hi Luc,
well ... I supppose that the most used setting will lead to 160 or 80 Hz frequency when 256 long array of transformed double values has to be processed by painting algorythm.
here is sample code
private void DrawDFTSample(double[] sample, Graphics g)
{
Range yRange = description.YRange;
double colorIndex = 0;
double colorIndexStep = description.Colors.Length / sample.Length;
double fi;
int yGraphBeginning = Height;
double yDisplay;
int xDisplay = currentRectangle.X + currentRectangle.Width / 2;
Pen p = new Pen(Color.Red);
p.Width = (currentRectangle.Width > 1) ? currentRectangle.Width - 1 : 1;
double threshold = 0;
yDisplay = yGraphBeginning;
for(int i=0; i<sample.Length; i++)
{
fi = sample[i];
if(fi >= threshold)
{
p.Color = description.Colors[(int)colorIndex];
yDisplay -= yPixStep;
g.DrawLine(p, xDisplay-1, (int)yDisplay, xDisplay+1, (int)yDisplay);
}
colorIndex += colorIndexStep;
}
counter++;
currentRectangle.X = (int)((double)counter * xPixStep);
}
Now I will try to optimize it by storing already computed values into array of points so I will be able to just draw them without reprocessing signal values when need to repaint whole signal occur.
Hope it will help me
|
|
|
|
|
Hi,
at first glance your code is OK except maybe for p.Color=...
I am not sure but this seems potentially the most expensive line in the for loop.
May I suggest you first retry with only one pen that does not change at all;
if perfo then is all right (or at least much better), make an array of pens
corresponding to description.Colors[] unless that array is really big.
Furthermore I am confused by the line
colorIndexStep = description.Colors.Length / sample.Length;
since it suggests there are more colors than samples (and with 256 samples, that would
be a lot of colors...)
And what is the "160 or 80 Hz frequency" you mentioned ?
is this the rate at which you hope to get the display updated ?? I dont think
Windows can do this at all (see my timers article !).
Best regards.
|
|
|
|
|
There are error to compile this code because panel3.left and panel3.top are not defined in the class. How to overcome this?
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove (e);
if (isDragging3 == true)
{
panel3.Left = e.X + panel3.Left - x3;
panel3.Top = e.Y + panel3.Top - y3;
}
}
|
|
|
|
|
What is panel3, if it's a control of any type, then it would have those properties.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Actually it has that control but it need to be declared. But when i made it into class, but in class it can't be done.
|
|
|
|
|
OK, so the control does not exist ? You didn't say that. In the properties window of the designer, make sure the GenerateMember property is true.
And, choose a better name for it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
The problem is that you have abstracted the class from the control, and you have control specific code: you should use
protect override void OnmouseMouseMove(System.Object sender,
System.Windows.Forms.MouseEventArgs e) then you should be able to access the left and top property's through the sender object
|
|
|
|
|
How to access the left and top property's through the sender object? Can you give example. i am new to c# and need guide..
|
|
|
|
|
Sounds to me like you need to learn some C# before you try to write whatever it is you are trying to write.
If you handle an event for a control, within your main class, then you have two incoming variables, like this
protected void OnPaneResize(object sender, EventArgs ea)
{
}
You can then do this:
protected void OnPaneResize(object sender, EventArgs ea)
{
Control c = sender as Control;
if (c != null)
{
c.Left = 5; // or whatever
}
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello,
I am using C# and DirectShow making a Windows Application to play DVD. I would like to be able to display the name of the DVD movie which is playing in the application.
I was wondering if you know of any API that I can use to get this information.
Thank you very much and have a great day.
Khoramdin
-- modified at 10:35 Saturday 10th March, 2007
|
|
|
|
|
You should be able to get the name of hte disc, the name that Windows displays. There is no movie name apart from the disc name encoded onto the disc, so no API can get it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello Christian,
Thanx for the reply. Since your last message I have done some research and have come to conclusion that base on your advise I should use "System.Management namespace" to get required information.
Could you be kind enough to let me know if this is the correct way to get this done?
Thank you so much for your help.
Khoramdin
|
|
|
|
|
I have the following code that creates a thumbnail for a given image and saves the new image to disk. It works but the images cannot be displayed by MSIE, and it appears that they are a different format than jpeg. Here's the code:
private void MakeThumbImage(string sSrcFilename, string sDestFilename)
{
Image orgImg = Image.FromFile(sSrcFilename);
int iHeight = orgImg.Height;
int iWidth = orgImg.Width;
int iNewHeight = iHeight;
int iNewWidth = iWidth;
if (orgImg.Width >= 96)
{
iNewWidth = 96;
}
else
{
iNewWidth = orgImg.Width;
}
double ratio = (double)iWidth / iNewWidth;
iNewHeight = (iHeight / (int)ratio);
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image thumb = orgImg.GetThumbnailImage(iNewWidth, iNewHeight, myCallback, IntPtr.Zero);
if (thumb != null)
{
thumb.Save(sDestFilename);
}
orgImg.Dispose();
thumb.Dispose();
}
private bool ThumbnailCallback()
{
return false;
}
I need to create a thumb for whatever file type it is (e.g., gif, png, jpg).
Thanks,
Mark
|
|
|
|
|
It may be a bmp. You should read up on the Save method, and how to specify a file format with it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks. That fixed it fine!
Mark
-- modified at 12:45 Saturday 10th March, 2007
|
|
|
|
|
I have been trying to identify a solution to this problem for some time. I have a control on the form. I change the location of that control on a path from an ending point back to the starting point.
I accomplish this by mappint the path incrementally along 64 points along a line. I put all of those points into an array and then loop through the array with a for-each loop. This part works fine, but now, here is the problem.
When the control is displayed on the form at its new location, I would like for that location image to be cleared before displaying the control at its next location. The way it displays now is that there is a path of displayed locations for the control from its ending point back to its starting point, kind of like ghost images.
private static void ProvideDragPathReturnToParent(Control ctrl, int intX_end, int intY_end,
int intX_start, int intY_start)
{
Point pt0 = new Point(intX_start, intY_start);
Point pt64 = new Point(intX_end, intY_end);
Point pt32 = new Point(((pt0.X + pt64.X)/2), ((pt0.Y + pt64.Y)/2));
Point pt16 = new Point(((pt0.X + pt32.X)/2), ((pt0.Y + pt32.Y)/2));
Point pt48 = new Point(((pt32.X + pt64.X)/2), ((pt32.Y + pt64.Y)/2));
Point pt8 = new Point(((pt0.X + pt16.X)/2), ((pt0.Y + pt16.Y)/2));
Point pt24 = new Point(((pt16.X + pt32.X)/2), ((pt16.Y + pt32.Y)/2));
Point pt40 = new Point(((pt32.X + pt48.X)/2), ((pt32.Y + pt48.Y)/2));
Point pt56 = new Point(((pt48.X + pt64.X)/2), ((pt48.Y + pt64.Y)/2));
Point pt4 = new Point(((pt0.X + pt8.X)/2), ((pt0.Y + pt8.Y)/2));
Point pt12 = new Point(((pt8.X + pt16.X)/2), ((pt8.Y + pt16.Y)/2));
Point pt20 = new Point(((pt16.X + pt24.X)/2), ((pt16.Y + pt24.Y)/2));
Point pt28 = new Point(((pt24.X + pt32.X)/2), ((pt24.Y + pt32.Y)/2));
Point pt36 = new Point(((pt32.X + pt40.X)/2), ((pt32.Y + pt40.Y)/2));
Point pt44 = new Point(((pt40.X + pt48.X)/2), ((pt40.Y + pt48.Y)/2));
Point pt52 = new Point(((pt48.X + pt56.X)/2), ((pt48.Y + pt56.Y)/2));
Point pt60 = new Point(((pt56.X + pt64.X)/2), ((pt56.Y + pt64.Y)/2));
Point pt2 = new Point(((pt0.X + pt4.X)/2), ((pt0.Y + pt4.Y)/2));
Point pt6 = new Point(((pt4.X + pt8.X)/2), ((pt4.Y + pt8.Y)/2));
Point pt10 = new Point(((pt8.X + pt12.X)/2), ((pt8.Y + pt12.Y)/2));
Point pt14 = new Point(((pt12.X + pt16.X)/2), ((pt12.Y + pt16.Y)/2));
Point pt18 = new Point(((pt16.X + pt20.X)/2), ((pt16.Y + pt20.Y)/2));
Point pt22 = new Point(((pt20.X + pt24.X)/2), ((pt20.Y + pt24.Y)/2));
Point pt26 = new Point(((pt24.X + pt28.X)/2), ((pt24.Y + pt28.Y)/2));
Point pt30 = new Point(((pt28.X + pt32.X)/2), ((pt28.Y + pt32.Y)/2));
Point pt34 = new Point(((pt32.X + pt36.X)/2), ((pt32.Y + pt36.Y)/2));
Point pt38 = new Point(((pt36.X + pt40.X)/2), ((pt36.Y + pt40.Y)/2));
Point pt42 = new Point(((pt40.X + pt44.X)/2), ((pt40.Y + pt44.Y)/2));
Point pt46 = new Point(((pt44.X + pt48.X)/2), ((pt44.Y + pt48.Y)/2));
Point pt50 = new Point(((pt48.X + pt52.X)/2), ((pt48.Y + pt52.Y)/2));
Point pt54 = new Point(((pt52.X + pt56.X)/2), ((pt52.Y + pt56.Y)/2));
Point pt58 = new Point(((pt56.X + pt60.X)/2), ((pt56.Y + pt60.Y)/2));
Point pt62 = new Point(((pt60.X + pt64.X)/2), ((pt60.Y + pt64.Y)/2));
Point pt1 = new Point(((pt0.X + pt2.X)/2), ((pt0.Y + pt2.Y)/2));
Point pt3 = new Point(((pt2.X + pt4.X)/2), ((pt2.Y + pt4.Y)/2));
Point pt5 = new Point(((pt4.X + pt6.X)/2), ((pt4.Y + pt6.Y)/2));
Point pt7 = new Point(((pt6.X + pt8.X)/2), ((pt6.Y + pt8.Y)/2));
Point pt9 = new Point(((pt8.X + pt10.X)/2), ((pt8.Y + pt10.Y)/2));
Point pt11 = new Point(((pt10.X + pt12.X)/2), ((pt10.Y + pt12.Y)/2));
Point pt13 = new Point(((pt12.X + pt14.X)/2), ((pt12.Y + pt14.Y)/2));
Point pt15 = new Point(((pt14.X + pt16.X)/2), ((pt14.Y + pt16.Y)/2));
Point pt17 = new Point(((pt16.X + pt18.X)/2), ((pt16.Y + pt18.Y)/2));
Point pt19 = new Point(((pt18.X + pt20.X)/2), ((pt18.Y + pt20.Y)/2));
Point pt21 = new Point(((pt20.X + pt22.X)/2), ((pt20.Y + pt22.Y)/2));
Point pt23 = new Point(((pt22.X + pt24.X)/2), ((pt22.Y + pt24.Y)/2));
Point pt25 = new Point(((pt24.X + pt26.X)/2), ((pt24.Y + pt26.Y)/2));
Point pt27 = new Point(((pt26.X + pt28.X)/2), ((pt26.Y + pt28.Y)/2));
Point pt29 = new Point(((pt28.X + pt30.X)/2), ((pt28.Y + pt30.Y)/2));
Point pt31 = new Point(((pt30.X + pt32.X)/2), ((pt30.Y + pt32.Y)/2));
Point pt33 = new Point(((pt32.X + pt34.X)/2), ((pt32.Y + pt34.Y)/2));
Point pt35 = new Point(((pt34.X + pt36.X)/2), ((pt34.Y + pt36.Y)/2));
Point pt37 = new Point(((pt36.X + pt38.X)/2), ((pt36.Y + pt38.Y)/2));
Point pt39 = new Point(((pt38.X + pt40.X)/2), ((pt38.Y + pt40.Y)/2));
Point pt41 = new Point(((pt40.X + pt42.X)/2), ((pt40.Y + pt42.Y)/2));
Point pt43 = new Point(((pt42.X + pt44.X)/2), ((pt42.Y + pt44.Y)/2));
Point pt45 = new Point(((pt44.X + pt46.X)/2), ((pt44.Y + pt46.Y)/2));
Point pt47 = new Point(((pt46.X + pt48.X)/2), ((pt46.Y + pt48.Y)/2));
Point pt49 = new Point(((pt48.X + pt50.X)/2), ((pt48.Y + pt50.Y)/2));
Point pt51 = new Point(((pt50.X + pt52.X)/2), ((pt50.Y + pt52.Y)/2));
Point pt53 = new Point(((pt52.X + pt54.X)/2), ((pt52.Y + pt54.Y)/2));
Point pt55 = new Point(((pt54.X + pt56.X)/2), ((pt54.Y + pt56.Y)/2));
Point pt57 = new Point(((pt56.X + pt58.X)/2), ((pt56.Y + pt58.Y)/2));
Point pt59 = new Point(((pt58.X + pt60.X)/2), ((pt58.Y + pt60.Y)/2));
Point pt61 = new Point(((pt60.X + pt62.X)/2), ((pt60.Y + pt62.Y)/2));
Point pt63 = new Point(((pt62.X + pt64.X)/2), ((pt62.Y + pt64.Y)/2));
Point[] arrPoint = {pt64, pt63, pt62, pt61, pt60, pt59, pt58, pt57, pt56,
pt55, pt54, pt53, pt52, pt51, pt50, pt49, pt48, pt47,
pt46, pt45, pt44, pt43, pt42, pt41, pt40, pt39, pt38,
pt37, pt36, pt35, pt34, pt33, pt32, pt31, pt30, pt29,
pt28, pt27, pt26, pt25, pt24, pt23, pt22, pt21, pt20,
pt19, pt18, pt17, pt16, pt15, pt14, pt13, pt12, pt11,
pt10, pt9, pt8, pt7, pt6, pt5, pt4, pt3, pt2, pt1, pt0};
foreach (Point pt in arrPoint)
{
ctrl.Location = pt;
ctrl.Update();
}
}
-- modified at 8:55 Saturday 10th March, 2007
|
|
|
|
|
You are only redrawing the control itself. As you are not giving control to the system until the loop ends, the form never gets a chance to redraw itself.
I would suggest that you use a timer control to move the control, that way the form gets a chance to erase the old control.
By the way: you use a lot of code to create the array, when it can easily be done in a loop.
---
single minded; short sighted; long gone;
|
|
|
|
|
How could it be done in a loop, and how would a timer be used to get the form to redraw itself? I have tried to apply code like this but it does not work properly.
private static void ProvideDragPathReturnToParent(Control ctrl, int intX_end, int intY_end,
int intX_start, int intY_start)
{
int x = 0, y = 0;
if ((intX_end > intX_start) & (intY_end > intY_start))
{
for (x = intX_end; x >= intX_start; x--)
{
for (y = intY_end; y >= intY_start; y--)
{
ctrl.Location = new System.Drawing.Point(x, y);
ctrl.Update();
}
}
}
else if ((intX_end < intX_start) & (intY_end < intY_start))
{
for (x = intX_end; x <= intX_start; x++)
{
for (y = intY_end; y <= intY_start; y++)
{
}
}
}
else if ((intX_end > intX_start) & (intY_end < intY_start))
{
for (x = intX_end; x <= intX_start; x++)
{
for (y = intY_end; y <= intY_start; y++)
{
}
}
}
else if ((intX_end < intX_start) & (intY_end > intY_start))
{
for (x = intX_end; x <= intX_start; x++)
{
for (y = intY_end; y <= intY_start; y++)
{
}
}
}
}
The problem here is that I do not know when the control will fit each of the conditions for position on the form. The x and y coordinates for the start and end points are based, I presume, upon PointToClient coordinates which goes from (0, 0) to (max, max) screen cordinates. However, I do not know the results of where it will be dropped.
Also, the x-coordinates must be completed before moving on to the y-coordinates. I would need to have one x-coordinate completed before moving on to the y-Coordinate, and then go back again to the next x-coordinate. I would request some input as to how to proceed.
-- modified at 13:12 Saturday 10th March, 2007
|
|
|
|
|