|
What he means is that you should NOT call the Paint method directly. If you do, you can have very unexpected and strange results. You should only be painting the control when Windows expects you to. When it wants you to repaint, it'll send the WM_PAINT message to your control, thereby firing the Paint event.
When you call Invalidate, your telling the control to invalidate its client area. You haven't actually fired the Paint event. The control will let Windows know that it has to repaint itself. Windows will then figure out when it is safe for you to repaint your window and send back the paint message when it is appropriate for you to repaint.
Dave Kreskowiak
Microsoft MVP - Visual Basic
-- modified at 19:17 Thursday 29th June, 2006
|
|
|
|
|
Ohhhhhhhhhhhhhhhhhh,
You mean "this.OnPaint(....)";
But its the first time we are speaking of a method.
"What he means is that you should NOT call the Paint method directly"
Now I got it.
Thank you so much for your time Dave.
Martin
|
|
|
|
|
It's not possible to raise the OnPaint event. (You can't raise any event outside yours)
What you need ist the .Refresh Method.
This causes a Paint Event of Controls.
That means:
yourform or yourcontrol.Refresh();
All the best,
Martin
|
|
|
|
|
yes i main concern is flikering because at every update of my drawing the whole thing got redrawn.
panel.invalidate() and panel.refresh() fliker the screen. Is there a solution for that of by the way im developing in the CF 2.0. so possibilities are very limited.
Donkaiser
|
|
|
|
|
First make shure, that you do not invalidate or refresh in the OnPaint Event. (would make it recursive, I think)
here is what the designer makes:
this.SuspendLayout();
//code
this.ResumeLayout(false);
All the best,
Martin
|
|
|
|
|
you can also override the PaintBackground.
But the problem is because you see the client area when it redraws. You should create an off screen buffer. write to it, then write to the client after its all done. then you wont see any flicker.
WinForms is not a very good graphical program. And this is very complicated. I recommend an MFC book to fully understand how to control painting.
Although a method may exist to limit the flickering. I dont know of one and I use API's to contol that. But, a little flicker is okay for a business program.
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Actually, if you set the style of the control to OptimizedDoubleBuffer it will handle all of the double buffer work for you. That is if you are using VS 2005
|
|
|
|
|
In order to reduce flickering you may have to use a technique which is commonly reffered to double-buffering. What that means is that you create graphics context in the background and draw there. When you're done, you 'swap' the two graphics contexts. What that means is that you basically copy the back buffer graphics context's contents to the active graphics context.
A quick search for double buffering will most likely give you all the information that you need.
----
www.digitalGetto.com
|
|
|
|
|
I try to implement double buffer but i can't get the handle of the SetStyle method
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
VS2005 give me the error saying that SetStyle and ControlStyles is not contained in the definition of the form.
how can i get the handle on this function to use on a panel to prevent flickering?
Donkaiser
Donkaiser
|
|
|
|
|
I'm not 100% sure but I think if you want to use the standard doublebuffering that .NET 2.0 GDI+ is offering you have to implement some other functions to support it. Make sure you find a good article on that. It's not trivial at first but once you grasp the fundamentals it should be straight forwards.
Also, did you mention using the Compact Framework?! That may be the reason. Google for an example of how to implement double buffering in C# with .NET 1.0/1.1... that is not using the .SetStyle and ControlStyles.DoubleBuffer.
Good luck
----
www.digitalGetto.com
|
|
|
|
|
I have two datagrids, dgParts and a nested datagrid dgWeights
protected System.Web.UI.WebControls.DataGrid dgParts;<br />
protected System.Web.UI.WebControls.DataGrid dgWeights;
I add a blank line to the dgParts grid with the following code:
private void add_Click(object sender, System.EventArgs e)<br />
{<br />
DataTable dt = ds.Tables["Rest"];<br />
DataRow row;<br />
row = dt.NewRow();<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
row["PartNumber"] = strPartNumberInputReference; <br />
row["DrawingNumber"]=DBNull.Value;<br />
row["DrawingRevision"]=DBNull.Value;<br />
row["DwgPath"]=DBNull.Value;<br />
dt.Rows.Add(row); <br />
dt.AcceptChanges(); <br />
dgParts.DataSource=dt; <br />
dgParts.DataBind();<br />
<br />
<br />
}
So I am trying to do the same thing for the dgWeights grid:
private void addWeight_Click(object sender, System.EventArgs e)<br />
{<br />
BindData();<br />
DataTable dt = ds.Tables["Weight"];<br />
DataRow row2;<br />
row2 = dt.NewRow();<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
row2["weight"] = DBNull.Value;<br />
row2["wtdescription"] = DBNull.Value;<br />
dt.Rows.Add(row2); <br />
dt.AcceptChanges(); <br />
dgWeights.DataSource=dt; <br />
dgWeights.DataBind();<br />
<br />
}
However, in the debugger it says that the dgWeights is null and I get the error that is in my title description. What am I missing?
|
|
|
|
|
Hi!
I'm trying to make the image in a PictureBox tile, and I can't just use the background image property since I need to change the position of the image too, which you can't do with a background image. In other words I want an image to repeat in a PictureBox. If you can help me I'd appreciate it.
Thanks,
Martin
|
|
|
|
|
Create a bitmap the same size of the control, Then redraw your image inside it however many times you need
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
I think your best bet is to override to override the OnPaint and add custom code to render the image tiled inside the picturebox.
----
www.digitalGetto.com
|
|
|
|
|
I am writing an application that basically has an sidebar and form_view_panel. This sidebar has X amount of buttons on it which correspond to loading specific forms in the form_view_panel. What I need to do is raise an event to the forms in the form_view_panel to let it know when a form change is about to occur(i.e. a toolbar button was clicked), if it(the form in the form_view_panel) wants to allow this to occur at that specific time then it responds back allowing the changing process to occur ORif it doesnt want to change at that point in time that it responds back not allowing the change to occur. So any suggestions on how to implement this using C# event handling methods. Any help will be greatly appreciated.
Thank You
|
|
|
|
|
If I understand correctly, you wanted to send a button-click event from one form to another.
First, a button-click event has to be first handled by its container form. It cannot be sent to or handled by another form. This is how event model should work.
That said, you still can notify any other forms that something interesting has happened. The simpliest (may not be beast) approach is making a callback into any interested forms from within the event handler and let them to further process the event if necessary.
Hope this helps.
Best,
Jun
|
|
|
|
|
The last thing you said is very interest...this callback seems to me to be at least a path for me to go down. Do you know have or know of any code examples?
|
|
|
|
|
Here is some pseudo code:
private void ButtonHandler(object sender, System.EventArgs e)
{
if(sender == this.buttonAdd)
{
anotherForm.AddCallback( someParameters );
}
else if(sender == this.buttonModify)
{
anotherForm.ModifyCallback( someParameters );
}
else if(sender == this.buttonDelete)
{
anotherForm.DeleteCallback( someParameters );
}
}
Best,
Jun
|
|
|
|
|
See the MVC pattern on Wikipedia.com. The Controller can be used to provide the messaging across different views so that the views remain isolated.
|
|
|
|
|
Hello!
It's not really a c# topic but I managed get my answers from this group before. And I need this for my C# application.
Can u tell me where to set default mail and VOIP client. I want to use mailto: and callto: calls from my application and for now callto: calls my Skype and I want to set other client for testing. Do u know where to set that in winXP?
Thanx
Ante
Ante
|
|
|
|
|
Start menu / settings / Control Panel / Add or Remove Program / Set Program Access and Defaults / Custom
Command and Conquer!
uh....
expand and edit!
|
|
|
|
|
thanx!
but is there any why to set callto: ? Actually I need this one more than mailto: since I'm trying to test integration of VOIP programs into my application
Ante
|
|
|
|
|
Well if you look in the registry HKEY_CLASS_ROOT
you will see there is a top level key name 'http', 'https', 'mailto', etc...
I bet there is one named 'callto'
Now I don't know what's inside. But that's the place to look in.
|
|
|
|
|
Thanx!
I'll try to use it
Ante
|
|
|
|
|
Hi
Im using VS 2005 and C# and the Enterprise Library 2.0. I want to design an application that can't be affected by the Database engine i used (SQL Server, Orcale, My Sql, Postegree) how can i acheive that since MySql and Postegree is not supported in Ado.net as
provider.
Thanks for your help
|
|
|
|