|
I disposed fonts and brushes, I recreate them because it may vary from one text to another
I’m keeping reference to the bitmaps and context.
|
|
|
|
|
You hold open a Graphics context?? Don't. On every pass, if you create a Graphics object, you also MUST dispose it when you're done drawing the current frame.
If you're getting the Graphics object from the Paint event args (Graphics g = e.Graphics, or something similar), then you do NOT dispose the graphics object. You didn't create it, so you don't dispose of it.
|
|
|
|
|
Hi, I now dispose the context after each frame is rendered. But still get the same error.
|
|
|
|
|
Let's see the code where this blows up. What line does it die on?
Did the previous timer event finish? What I mean is that the timer fires once, you start drawing on the image, the timer fires again, but you haven't finished drawing on the previous tick, so when you go to create another Graphics object to draw the next frame, it collides with the last one.
|
|
|
|
|
I run it in debug mode, and the frame rendering finish long beefore the second timer event.
Here is a resume of all the code, is quite large one to post completely.
private class Principal:Form
{
//.... declarations , constructor, Othes Methods, etc.
//waht is important for the case
private Bitmap offScreenBmp;
private Graphics offScreenDC;
private Bitmap FondoLimpioBmp;
private bool DrawingToBuffer;
private viod BackImg() //this is been called once at form_load (for now).
{
DrawingToBuffer = true;
FondoLimpioBmp = new Bitmap(BackIngPath);
//BackIngPath is string containing path and file name of backgound image.
FondoLimpioBmp = new Bitmap(BackIngPath);
Graphics FondoLimpioDC = Graphics.FromImage(FondoLimpioBmp );
//Draw Some Gradients here to FondoLimpioDC, no problems here
//PicBack is a PicuteBox in the form.
offScreenBmp = new Bitmap(PicBack.Width, PicBack.Height);
offScreenDC = Graphics.FromImage(offScreenBmp);
offScreenDC.Clear(Color.Transparent);
offScreenDC.DrawImage(this.BackgroundImage,new Point(0,0));
offScreenDC.SmoothingMode = SmoothingMode.AntiAlias;
offScreenDC.DrawImage(FondoLimpioBmp , 0, 0);
FondoLimpioDC.dispose();
offScreenDC.Dispose(); //Add this after yuor comment.
DrawingToBuffer = false;
}
private void Paginar() /// this is called from Timer_Tick event
{
if (!DrawingToBuffer){ //flag para prevenir 2 instancias al mismo tiempo
// Here gos code to read data from database....
DrawingToBuffer = true;
offScreenDC = Graphics.FromImage(offScreenBmp);
offScreenDC.Clear(Color.Transparent);
offScreenDC.DrawImage(FondoLimpioBmp, 0, 0);
offScreenDC.SmoothingMode = SmoothingMode.AntiAlias;
StringFormat sf = new StringFormat();
Brush tBrush = Brushes.Black;
sf.LineAlignment = StringAlignment.Center;
Font tFont = new Font("Arial", 17F, FontStyle.Bold);
string itemToShow;
int Y1, Y2, Y3, Y4;
RectangleF txtRect;
for(int i = 0; i < 10; i++)
{
Y1 = (sepHeigth * i) + (rowHeigth * i);
Y2 = (sepHeigth * (i + 1)) + (rowHeigth * i);
Y3 = Y2;
Y4 = (sepHeigth * (i + 1)) + (rowHeigth * (i + 1));
sf.Alignment = StringAlignment.Center;
txtRect = new RectangleF(TitleSrv.Left, Y3, TitleSrv.Width, rowHeigth);
itemToShow = LSRVLbl[i].Text;
sf.FormatFlags = StringFormatFlags.NoClip;
//*************************************************************//
//This is the line where error is thrown
offScreenDC.DrawString(itemToShow, tFont, tBrush, txtRect, sf);
//*************************************************************
txtRect = new RectangleF(TitleInt.Left, Y3, TitleInt.Width, rowHeigth);
itemToShow = LINTLbl[i].Text;
offScreenDC.DrawString(itemToShow, tFont, tBrush, txtRect, sf);
sf.Alignment = StringAlignment.Near;
txtRect = new RectangleF(TitleOrDes.Left, Y3, TitleOrDes.Width, rowHeigth);
itemToShow = LORDESLbl[i].Text;
offScreenDC.DrawString(itemToShow, tFont17, tBrush, txtRect, sf);
}
sf.Dispose();
tFont.Dispose();
tBrush.Dispose();
offScreenDC.Dispose();
offScreenDC = null;
DrawingToBuffer = false;
PicBox.Invalidate();
}
private void PicBack_Paint(object sender, PaintEventArgs e)
{
if(!DrawingToBuffer)
{
e.Graphics.Clear(Color.Transparent);
e.Graphics.DrawImageUnscaled(offScreenBmp, 0, 0);
}
}
}
|
|
|
|
|
DoomedOne wrote: if (!DrawingToBuffer){ //flag para prevenir 2 instancias al mismo tiempo
// Here gos code to read data from database....
DrawingToBuffer = true;
You are trying to have a mutex so only one instance of this code can execute the
drawing actions, but:
1) having a separate test, then set of a variable is not reliable
2) if as your comment indicate you do a database access in between, it is
doomed to fail.
So give it a try with DrawingToBuffer=true before you do DB access,
and better yet use a real non-reentrance defense (such as disabling the timer
while inside paginar).
|
|
|
|
|
Hi,
I’ve tired that too, disabling the timer as first sentence in the Timer_tick event and enabling it again at the end, after the frame has been rendered, and don't work.
The problem do not looks like a collision between 2 running threads trying run the same paint code, is more like something is missing to clean up, or set, between calls to de "Paginar" code.
|
|
|
|
|
Hi,
I've solved the problem by moving the definition of offscreenBMP to the code block, recreating it on every render and assigning it to the pictureBox in the "Paginar" method, instead of coping it in the paint event.
Thanks to every one.
|
|
|
|
|
Hi,
In my programe i am one using datagrid.
User can enter decimal value and i am validating the value.
for that i am using RegulerExpression.
(?!^0*$)(?!^0*\.+0)*$^\d{1,5}(\.+\d{1,2})?$
but this is not working it's giving error.
Message "Invalid escape sequence"
those are . and \
help me
its arrgent.
Thanks
asif
|
|
|
|
|
Hi,
A very good site for regex is Regular Expression Library[^].
If you search here for decimal you will find 93 regex samples.
There's also a regex tester on it.
Sven
|
|
|
|
|
this is a really generic regex for a decimal value, ^\d*\.\d*$
I'm listening but I only speak GEEK.
|
|
|
|
|
I have a situation I am not sure how to deal with.
I have a class derived from the DataTable class
When I call the GetChanges form within an instance of the derived class the constructor of the derived class is called instead of just the DataTable constructor.
this.GetChanges();
I was expecting that only the Datatable constructor would be called. Is there a way around this ?
I tried calling
base.GeatChanges();
but same result.
|
|
|
|
|
It's called inheretance and Object-Oriented Programming.
only two letters away from being an asset
|
|
|
|
|
Since when is the method GetChanges a constructor for the DataTable class?? Or any class for that matter?
|
|
|
|
|
The GetChanges function has DataTable as a return type, so yes, at some point the constructor for the DataTable type will be called.
|
|
|
|
|
True, mostly. The constructor for A class will be called. How about base.GetChanges() .
|
|
|
|
|
|
I don't have a problem understanding inheritence
What I am not sure is why since the return type of the GetChanges is DataTable, I expect the DataTable contructor to be called but if I call that same function form a Class derived form DataTable all of a sudden the constructor of the dirived class is called although the return type is still a DataTable, I didn't touch that function. Here is the situation as clear as I can make it:
class myType : DataTable
{
myType():base()
{}
public someFunction()
{
code....
DataTable someDataTable = this.GetChanges();
}
In the last line a myType seems to be created by the Activator, I would have expected it to create a DataTable, nothing more.
|
|
|
|
|
Microsoft documentation says the GetChanges method:
Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges was called.
My guess is that it is using DataTable.Clone and the documentation on DataTable.Clone notes that "If these classes have been derived, the clone will also be of the same derived classes". See Documentation.[^]
So it is copying your instance (which is of MyType) and returning it as a DataTable. Overriding DataTable.Clone or GetChanges might fix your problem.
topcoderjax
|
|
|
|
|
Makes sense, thanks for the input
|
|
|
|
|
i would like to invite help of expert .net programmers/ .net architects for creating test questions for online testing platform.
compensation at $50 for 200 questions/answers . plus credits on test site for your effort.
http://jhatak.com/uwebcertify/index.aspx
i also require similar help for java question bank
your help appreciated
|
|
|
|
|
The job board would the place for this, not a programming forum
only two letters away from being an asset
|
|
|
|
|
I want to take the backup of mysql database through programming.
Any ideas? Any Links?
Thank you.
|
|
|
|
|
Create a stored precedure that does the backup and execute it from the code
|
|
|
|
|
hello,
i have to use a component to extract exif data from jpg and tif files in my application. everything works fine so far. the component returns apex values as strings (formatted as fractions), e.g. 5000/100 for ShutterspeedValue or 227/32 for FocalLength.
i've read in the EXIF spec that there are quite difficult formulas to be used to calculate the real values. since i'm not a math-genius i'd like to ask if someone has done this already and can point me to some c# snippets.
i'm pretty desperate on this one and appreceate any help. thanks in advance.
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|