|
leckey wrote: Then why does it still hate this?
Because it is mean and it's father used to beat it with a baseball bat.
You aren't passing the 'param' object into the ExecuteDataset method. Creating it is one thing, using it another.
Cheers & beers,
Josh
|
|
|
|
|
Thanks again! A new problem has arisen. I get "Object must implement IConvertible." Trying to research this so I can stop bugging CodeProject...In my stored procedure I have
@PartID varchar
Is this the issue?
|
|
|
|
|
The problem is not in the stored procedure. SPs have no concept of IConvertible, that's a .NET thing. Turn on your debugger and see where the exception is thrown. It is impossible to figure out what the issue is based on just that error message alone.
Josh
|
|
|
|
|
Hi,
I'm trying to create a custom control to draw a graph in a canvas in real-time, similarly to an osciloscope. I have a main control loop that performs some calculations and updates the current point coordinates (x and y, with x corresponding to the time). I used to use Flash, but due to performance issues I decided to try out using C# (waht means I'm new to C#).
I'm already able to draw lines on my control, but I'm not able to update the canvas whenever a new point is calculated. The problem is that I don't know how to trigger the paint event. I've already registered it, but I don't know how to call it after the point is calculated.
I hope I made myself clear...
Thanks in advance,
Ze Augusto
|
|
|
|
|
Call Invalidate() on the control. That will post a request for a repaint, but if you really need an immediate repaint you should call Update() after calling Invalidate(). Note, you can also call Refresh(), which basically calls those two methods for you.
|
|
|
|
|
First, thanks for your help. I did what you suggested, and it did solve the repaint issue. Now I can see the lines been updated.
Now, the problem is that the screen is getting erased before the new point is drawn (as it would be expected from your description), but I need to keep the points already drawn and add the new point to the end of the line, forming a continuous curve. Then, when that line reaches the end (right border) of the canvas, I should send the carrier back to the begining (left border) and continue drawing, with a blank region in front of it, as if there was an eraser in front of the current point.
Thanks again!
|
|
|
|
|
ZeAugusto wrote: as if there was an eraser in front of the current point.
No erasing but the graphics system does not remember what you previously drew, you have to do that and draw everything in the window (or invalid region) during a paint event. Last modified: Wednesday, June 21, 2006 12:58:57 PM --
|
|
|
|
|
Rather than invalidating the control, call yourCustomControl.CreateGraphics() to get a Graphics object which will render onto your control surface. Then perform the painting in a separate method (not the Paint event handler). That new method will draw only the new point(s) and not erase the other ones. You'll probably want to have your Paint event handler call into this new method so that the rendering logic is factored properly.
Josh
|
|
|
|
|
I think a proper way is using double-buffering. You maintain a graphical buffer and you draw to the buffer. Whenever you want to update the screen, copy the buffer to the screen. There are two approaches to the buffer drawing:
1) If you just add (not erase, not change) contents to the screen, grab the graphic object and draw to the buffer on the top of existing contents.
2) If you erase or change any existing contents on the screen, you need to repaint the buffer's background and then redraw it completely.
I've assumed you have fair understanding about how Windows graphics work. If you need more guidance, drop a line.
Best,
Jun
|
|
|
|
|
Thanks for all the replies!
As I didn't know how to add content without refreshing the whole object, I ended up implementing a mixture of your suggestion with Josh's and Led's ones. I used the GraphicsPath class instead of just drawing single line segments, adding the newly calculated points to it, and then redrew the entire path at every Refresh() call (which happens whenever I add a point to the graph, every 40 ms). At the end of the line, I clone this path to a second one, and reset the first. This way, I work with two paths, the most recent one "above" the oldest, and redraw both when a new point is added.
To solve that "erasing" part I mentioned before, I used a little trick. I draw a black rectangle (because the background of the graph region is also black) between the two paths, and resize it so that it is always a few pixels wider than the top path. This way, it looks like there is an eraser in front of the line being drawn. It's quite similar to what I've already done in Flash.
But I have a new question, though. As far as I draw all these objects every 40 miliseconds, I wonder if I might experience some performance issues. The application is intended to support an average of 5 to 10 simutaneous instances of this control, so that might become a problem... Or am I just being paranoid because of my Flash experience?
Thanks,
Ze
|
|
|
|
|
ZeAugusto wrote: I wonder if I might experience some performance issues.
Can't say for sure. Keep your fingers crossed.
ZeAugusto wrote: The application is intended to support an average of 5 to 10 simutaneous instances of this control, so that might become a problem...
It also depends on how large (portion of screen taken) your control is.
Best,
Jun
|
|
|
|
|
|
Hi,
My opacity control causes a really bad BLACK flicker after the opacity is initially decreased via the trackbar control. Any ideas on how to get rid of the black flicker would be greatly appreciated.
PS: I tried calling Invalidate and ReDraw after Opacity is adjusted with no luck.
Some of the code...
//
// trackBar1
// Code located on the fader (opacity) control
this.trackBar1.Location = new System.Drawing.Point(26, 14);
this.trackBar1.Maximum = 100;
this.trackBar1.Minimum = 10;
this.trackBar1.LargeChange = 5;
this.trackBar1.SmallChange = 5;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(220, 45);
this.trackBar1.TabIndex = 0;
this.trackBar1.TickFrequency = 10;
this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.Both;
this.trackBar1.Value = 100;
this.trackBar1.MouseUp += new
System.Windows.Forms.MouseEventHandler(this.TrackBar1_ValueChanged);
private void TrackBar1_ValueChanged(object sender, System.EventArgs e)
{
if (_OpacityChanged != null)//run event
{
_OpacityChanged(this.trackBar1.Value);
}
}
// Code located on the main form. User clicks button to bring up control
private void faderControl_Click(object sender, EventArgs e)
{
FaderControl myFaderControl = new FaderControl();
myFaderControl._OpacityChanged += new
FaderControl.UpdateOpacity(OnOpacityChanged);
myFaderControl.ShowDialog();
}
private void OnOpacityChanged(double OpacityValue)
{
double newOpacityValue = OpacityValue / 100;
this.Opacity = newOpacityValue;
}
|
|
|
|
|
Are you setting styles for double buffering and all painting in wmpaint?
|
|
|
|
|
Mike, Thanks for your reply!
I am setting all controls that go on the form to this.DoubleBuffering = true.
How do I set all painting to wmpaint? I'm not familiar with this property.
Tom
|
|
|
|
|
SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
|
|
Mike,
Thanks again, I'm using something similar. On all forms and controls I envoke...
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
ControlStyles.OptimizedDoubleBuffer, true);
Still Ugly Black Flicker occurs!
Tom
|
|
|
|
|
Cubzfan wrote: On all forms and controls I envoke
No. In your custom control. FaderControl is your own custom control right? That's what is flickering yes?
|
|
|
|
|
Mike,
No, the form the control is changing the Opacity flickers black when the control is initially taken from the default full opaque setting to any decrease setting. The control works fine after that. If you increase or decrease the parent forms opacity with the child control it changes as it should unless the control is once again set all the way to the right (max setting the parent form to full opaqe) and you decrease again the black flicker happens again.
Hope this helps clear things up???
I really appreciate the help!!
|
|
|
|
|
So you are working on a Custom Control, you are changing the opacity of a .NET Form. Yeah I have no idea what might help with that. See Dustin Metzgar's post maybe it will help.
|
|
|
|
|
Which OS are you using? I noticed having flicker problems in Win 2000, but everything was fine in XP.
Logifusion[^]
|
|
|
|
|
Dustin,
Thanx for the reply! I am using XP.
|
|
|
|
|
Damn. Thought maybe it was an easy solution. In one of the projects I worked on, the help->about dialog box would fade in using the opacity control. In 2000, it often had problems and would sometimes appear black until it got to an opacity of 1.00. The only thing I can really suggest is that you try setting the opacity in the Form's thread. It looks like you have a separate dialog box that you use to set the main form's opacity. I think that means there is one thread for your dialog and one for your main form. Maybe you can try using Invoke and a delegate to set the opacity in the main form's thread.
I'm not sure if it works or not. We ended up just saying "Eh, good enough."
Logifusion[^]
|
|
|
|
|
Dustin,
This gets better! I disabled the opacity control and tried setting the forms opacity to 0.50 when the form is initialised. When the form pops up, same thing black flicker then form and new opacity are what they are suppose to be.
Very frustrating, but I will prevail!!
Thanx again,
Tom
|
|
|
|
|
Tom,
I was glancing several times at this thread today, and something about the "black flicker" was sounding familiar. Anyway, I think I've figured out a solution, so I'll take a crack at it.
Slight disclaimer: I've only done one test with this, and I think it works, but I cannot be sure. Please let me know if it doesn't work.
Basically the solution is this: don't use the OptimizedDoubleBuffer and AllPaintingInWmPaint styles for the form which you are making more or less opaque. I was reading a short article on another site about Transparent Windows Forms Controls (you can look at it here[^] - some of the images are broken, but the article text is all that matters). On that page, the author notes that, when making truly transparent controls, you cannot use double buffering, because "The memory bitmap which is provided to your code has an opaque background and does not allow the carefully retained parent pixels to show through". This makes sense when you think about how double-buffering is done: basically, you are drawing to a buffer which is never displayed, and so I would imagine there is no previously drawn pixels on that buffer (which is necessary for transparency, because you need your pixels to be blended with the pixels which are behind them).
Give that a try on your Form, and see what happens. That is, in your Form's constructor (the one whose opacity you are changing) take out the two styles OptimizedDoubleBuffer and AllPaintingInWmPaint . I'm not sure why AllPaintingInWmPaint does not work properly, but in my test it gave a black flicker when it was set, even without the double-bufferring. I suspect it has to do with OnPaintBackground not being called when that style is set, and therefore the proper blending does not occur with the form background.
As a side note, I can make the background flicker black when I minimize and then restore my form. You did not mention this before, but I thought it might help to mention it so that you can check if your code produces the same effects as I have been throughout.
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|