|
I'm making a custom text control and opted to use GDI's TextOut over GDI+ DrawString due to its more accurate spacing between letters. I got it all working how I wanted, but after using it for a while I get an out of memory exception and I'm not sure why. I know its this procedure since changing it to the gdi+ drawstring thats in the framework stops this from happening. The drawstring procedure I made along with the dllimports are as follows:
[DllImport("gdi32.dll")] <br />
static extern bool TextOut(IntPtr hdc, int nXStart, int nYStart, string lpString, int cbString); <br />
<br />
[DllImport("gdi32.dll")] <br />
static extern int SetTextColor(IntPtr hdc, int crColor); <br />
<br />
[DllImport("gdi32.dll")] <br />
static extern int SetBkColor(IntPtr hdc, int crColor); <br />
<br />
[DllImport("gdi32.dll")] <br />
static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); <br />
<br />
public static void DrawString(ref Graphics g, string s, Font Font, Color ForeColour,Color BackColour, Point point) { <br />
IntPtr hdc = g.GetHdc(); <br />
IntPtr fntOld = SelectObject(hdc, Font.ToHfont()); <br />
<br />
SetTextColor(hdc, RGB(ForeColour)); <br />
SetBkColor(hdc, RGB(BackColour)); <br />
TextOut(hdc, point.X, point.Y, s, System.Text.Encoding.Default.GetByteCount(s)); <br />
SelectObject(hdc, fntOld); <br />
g.ReleaseHdc(hdc); <br />
}
The graphics object that gets sent to the procedure is just e.Graphics from the controls paint event.
Any ideas as to why this happens would be greatly appreciated.
Draders
I figured out the problem, I needed to give Font.ToHfont() its own IntPtr and then delete it after i'm done with it using the DeleteObject GDI method.
-- modified at 11:21 Friday 24th February, 2006
|
|
|
|
|
Hi All,
I'd like to build a C# organizer application with winforms and some kind of database in the back. Is it possible to build it in a way that will not require some database system installed on each computer that the application will be distributed to. Or it defintely needs either sql server or oledb, etc? Any oppinion will be greately appreciated.
|
|
|
|
|
You can just use an MS Access database, which is simply a file so you won't need a server installed on each computer and you can just distribute it with the application. However, you do need the Access driver installed, but I am pretty sure this comes with windows.
Wacky waving inflateable arm flailing tube man!
- Family Guy
|
|
|
|
|
Nice signiture Thanks for the info. Is the data provider for MS Access to ADO.NET Microsoft.Jet.OLEDB.4.0 right?
|
|
|
|
|
Right on
Wacky waving inflateable arm flailing tube man!
- Family Guy
|
|
|
|
|
HI, use SQLite oder firebird embedded instead of Jet 4.0 (Access).
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
I'm not sure how I would go about how to get a control to create an object specifically for one of it's properties.
For example, say I have a class called 'LayoutSystem', with the constructor 'LayoutSystem(int width, int Height)', and on the main form I have a control with the property 'LayoutSystem' of type 'LayoutSystem'
The code I currently have would generate this:
LayoutSystem layoutSystem1 = new LayoutSystem();<br />
<br />
...<br />
layoutSystem1.Width = 100;<br />
layoutSystem1.Height = 200;<br />
control1.LayoutSystem = layoutSystem1;<br />
but instead I need the code to generate like this:
<br />
control1.LayoutSystem = new LayoutSystem(100, 200);<br />
I'm not sure what this would be called, and I've searched all over for something about it, but I can't find anything.
Also, I don't know if I would have to go about it differently if say in that constructor in the second bit of code, i had another constructor:
<br />
control1.LayoutSystem = new LayoutSystem(100, 200, new LayoutSystem[] { (LayoutSystem) new LayoutSystemChild(50, 100), (LayoutSystem) new LayoutSystemChild(50, 100)});<br />
... in that case the constructor would be LayoutSystem(int width, int height, LayoutSystem[] childLayoutSystems)
I've spent hours trying to find something on this, but I can't seem to find anything.
-- modified at 13:51 Thursday 23rd February, 2006
|
|
|
|
|
It's funny... every time you post on asking how to do something, you end up figuring it out for yourself a not too long after..
I figured I would have to use a custom TypeConverter, based on some article i finally found here on serialization.
|
|
|
|
|
SteelixB wrote: It's funny... every time you post on asking how to do something, you end up figuring it out for yourself a not too long after..
I've done that before myself. Posting generally means a casual google didn't find anything, depending on priority I might keep diging even after I post.
|
|
|
|
|
Hi All,
I am having trouble with CSV files
Everything works fine if the csv is formatted as bellow example
header ---> one, two, three, four
Data 1------> ab, bc, de, fg
Data 2------> cb, cc, ce, cg
However sometimes i get a file that has a row spilt over two lines as bellow example
header ---> one, two, three, four
Data 1------> ab, bc, d
Data 1------> e, fg
Data 2------> cb, cc, ce, cg
Does anyone know how to search through a csv file and remove any occurrences of this split line problem ???
I would be most grateful for any help
Thanks
John
|
|
|
|
|
The problem is that you are reading the file the wrong way. The records are separated by line breaks, but fields in a record may also contain line breaks. Therefore you should read the file as a stream instead of line by line.
Normally, a field containing line breaks will be enclosed in quotes:
one, two, three, four<br />
ab, bc, "d<br />
e", fg<br />
cb, cc, ce, cg
If you just keep track of whether you are inside a quote or not, the line breaks are no problem. If you are inside the quote, a line break is just data, not a record separator.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
Thanks for the quick response !!!
I have never seen " " around the line break.
Any more info on how to read the file as a stream would be fab !!!
I am kinda new to all this
Thanks again !!!
John
|
|
|
|
|
Sadly there exists no proper standard or specification for CSV files.
Where does the CSV files come from? If possible, try to get a specification of the format used.
If the fields containing line breaks are not quoted, you will have a tricky task to separate the line breaks in the fields from the record separating line breaks.
It's possible as long as there are no line breaks in the last field of the records. If there are, it might be impossible to read the file. Look at this example:
1, 2, 3<br />
aa, bb, cc<br />
xx<br />
aa, bb, cc
Does the "xx" part belong to the last field of the first line, or the first field of the last line? It's impossible to tell.
---
b { font-weight: normal; }
|
|
|
|
|
Umm i see your point
the last field is an ID Number so it is unlikely that this would ever have any form of line break.
The ones I have looked at seem to contain the break at random points in the line. almost as though someone has just randomly hit the enter key whilst scrolling the csv.
How would you recommend solving this prob ? even if it is not fully reliable.
How does this stream line thing work ??
I really don’t know where to start
Thanks
John
|
|
|
|
|
I am trying to monitor a thread I created in my application. Specifically, I need to go process messages when the thread exits (either gracefully or it has been killed). Is there anyway in Windows CE that I can do this?
|
|
|
|
|
Hai all,
I want to show a UserControl instead of the default dropdown list when I click on the ComboBox dropdown arrow. Is there a way to catch this message and show my control instead of this?
Thanks in advance.
VPMahank
|
|
|
|
|
|
Draders23,
Thanks so much for the link . I tried overriding the WndProc for the control and show my own customcontrol instead of regular dropdown.
Thanks,
VPMahank
|
|
|
|
|
Hey
First I would like to say that this is a VERY GOOD site! Jesus, I can find anything around here. You always have the solutiion for everyone. hehe. Good job
But I didn' come here for that (only for that).
I'm working in a place where they want me to do a calendar to introduce events... I used the Calendar WebControl from .NET platform but there's a problem. The boss wants me to make a displayable calendar... What he means is that the user can view the dates in various formats...
Per day: only displays the hours
Per week: displays the dates of that week
Per month: don't have to say!
Per year: Display all month at once
I want to know if there's I way to do this using the Calendar Web Control. If not how can I do this?!
I know this is stretchy but I really need this done... In C# if possible!
Many thanks and have a nice work everybody
andrecarrilho
|
|
|
|
|
I have a program that has 5 worker threads constantly monitoring and changing a static DataTable. The DataTable is in a DataSet and is bound to a main DataGrid in this manner.
MainGrid.SetDataBinding(DSet,DBox.TableName);
The binding works fine and will add and change data with no problem. The problem comes when one of the worker threads removes a row from the DataTable. About 50% of the time I get an IndexOutOfRangeException thrown in the OnPaint of the main DataGrid. Each time there is a different row that caused the problem. ie "No Index at Row 5" This is how I am removing the rows.
if(MasterLock.Available(-1,10))<br />
{<br />
try<br />
{<br />
this.Rows.Remove(row);<br />
this.AcceptChanges();<br />
}<br />
catch(Exception _i)<br />
{<br />
_i.ToString();<br />
}<br />
finally<br />
{<br />
MasterLock.Release();<br />
}<br />
}
Any ideas?
|
|
|
|
|
Hi,
The problem could be that you are accessing a control from a worker thread. .Net 2.0 throws an exeption if you try this, but I guess you are using .Net 1.1 which allows the call but fails randomly.
You can test this my using this.InvokeRequired . If this is the case, then wrap your control access in an this.Invoke or this.BeginInvoke call.
----------------------------
Be excellent to each other
|
|
|
|
|
Hello,
How can I write the DataSet Contents into a CSV file?
Thank you.
|
|
|
|
|
Assuming there is only one DataTable in the DataSet then you can just iterate through the rows of the DataTable, then iterate through each of the columns writing the information to a file. Each column iteration loop writes a comma after the value, except the last iteration. Each iteration of the rows writes a newline after writing out the columns, except for the last row.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Hi,
I'm just starting out with DirectX and am running into some trouble (I've been piecing parts of examples together). I have a couple rectangles that yaw, roll, and pitch as they zoom in. When they come back to face the front (so it only looks 2d), I stop the movement and add a couple triangles. Up to here it works just fine. Now I'd like to add a bitmap under the rectangles but run into trouble. I have:
private override OnPaint()<br />
{
some twirling of boxes for a few seconds that become still with this line:
DrawBox(0.0f, 0.0f, 0.0f, -0.45f, 0.8f, 9.5f); (code for DrawBox below)
then I add a couple triangles...
CustomVertex.TransformedColored[] vert = new CustomVertex.TransformedColored[3];
... describe the vert ...
device.VertexFormat = CustomVertex.TransformedColored.Format;<br />
device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vert);
Things work fine up to here. At this point I'd like to add my bitmap (Texture tex). I change the VertexFormat and call DrawBitmapBox (this is how one example added a texture to a box):
device.VertexFormat = CustomVertex.PositionTextured.Format;<br />
device.SetStreamSource(0, vb, 0); vb is the VertexBuffer - also below
DrawBitmapBox(0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 9.5f, tex); (code also below)
}
Instead of drawing the bitmap image, the original rectangles themselves kind of blink (not at any contant rate), while the triangles just sit there like everything's ok. I know I'm probably making some obvious mistake(s), but any help in getting this bitmap up would be great!!!
Mel
DrawBox
private void DrawBox(float yaw, float pitch, float roll, float x, float y, float z)<br />
{<br />
angle += 0.01f;<br />
device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);<br />
Material boxMaterial = new Material();<br />
device.Lights[0].Type = LightType.Directional;<br />
device.Lights[0].Diffuse = Color.Red;<br />
device.Lights[0].Direction = new Vector3(0,-1,-1);<br />
device.Lights[0].Commit();<br />
device.Lights[0].Enabled = true;<br />
boxMaterial.Diffuse = Color.White;<br />
device.Material = boxMaterial;<br />
mesh.DrawSubset(0);<br />
}
DrawBitmapBox
<br />
private void DrawBitmapBox(float yaw, float pitch, float roll, float x, float y, float z, Texture t)<br />
{<br />
angle += 0.00f;<br />
device.Transform.World = Matrix.RotationYawPitchRoll(yaw, pitch, roll) * Matrix.Translation(x, y, z);<br />
device.SetTexture(0, t);<br />
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 6);<br />
}
VertexBuffer stuff
under InitializeGraphics:
vb = new VertexBuffer(typeof(CustomVertex.PositionTextured), 6, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);<br />
vb.Created += new EventHandler(this.OnVertexBufferCreate);<br />
OnVertexBufferCreate(vb, null);
OnVertexBufferCreate:
private void OnVertexBufferCreate(object sender, EventArgs e)<br />
{<br />
VertexBuffer buffer = (VertexBuffer)sender;<br />
<br />
CustomVertex.PositionTextured[] v = new CustomVertex.PositionTextured[6];<br />
v[i] = ...<br />
buffer.SetData(v, 0, LockFlags.None);<br />
}
|
|
|
|
|
Are the dimensions of your bitmap powers of 2? If I recall correctly they have to be powers of two to work as textures.
I hope this helps.
Deus caritas est
|
|
|
|
|