|
how do i tell if my filestream is at the end of the file
char[] holder=new char[256];
FileStream fs=new FileStream("c:\\temp.txt",FileAccessmode.Read)
while ()//don know what to put there
{
fs.read(holder,0,256)
}
thanks
chad
|
|
|
|
|
while (fs.Position < fs.Length)
for instance.
--
Henrik Stuart (http://www.unprompted.com/hstuart/)
|
|
|
|
|
while (fs.read(holder,0,256) > 0)
{
}
|
|
|
|
|
|
FileStream.Read will return 0 when it gets to the end of the stream so you should test for the return value being > 0 and exit the loop on it being == 0 .
James
|
|
|
|
|
You can do it in loop and out of loop by checking to see if Stream.Length is equal to Stream.Position or checking the return value of Stream.Read/Byte for 0.
|
|
|
|
|
While installing Roman Kiss Remoting Management Console tool[^], I get the following error.
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name Remote, or one of its dependencies, was not found.
What could be the problem?
I got .NET 1.1 and Windows XP Pro.
TIA
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
The proper place to ask about this is in the article's message forum. It's specific to that article and sample code. BTW - this isn't a remoting problem. The exception just states that the assembly Remote.dll - or one of its dependencies - cannot be found.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
The proper place to ask about this is in the article's message forum.
I thought of posting there, but given the article date it will be awhile before I get the reply.
Heath Stewart wrote:
The exception just states that the assembly Remote.dll - or one of its dependencies - cannot be found.
You mean I have to install 'Remoting' separately? Isn't that part of .NET Framework install or VS.NET install?
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
The date on the article has nothing to do with messages! Notification emails are automatically send to article authors when you post a new message, just like they are by default to messages here in the forums.
.NET Remoting is part of the .NET Framework base class libraries, but Remoting.dll is some other assembly (not from the .NET Framework) that is missing. This could be an assembly containing the shared interfaces or any other Types used by the application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
This could be an assembly containing the shared interfaces or any other Types used by the application.
Got it. Thanks for the clarification. I thought it's related to .NET Framework Remoting.
BTW, I posted the question at Roman's article.
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
You might be running into the problem outlined here[^].
---------------------------
He who knows that enough is enough will always
have enough.
-Lao Tsu
|
|
|
|
|
Hi,
I'm creating a control very similar to the ListView in Details mode. I'm confused as to how to go about drawing the column headers at the top.
As the column headers are static and stay in one position (hence, they do not need to be scrolled by the system when the AutoScrollPosition is changed), I do not want to draw them each time the control needs to be repainted or the user scrolls down.
The only way I can think of to do this right now is to create a top-docked panel and use this panel to draw the columns on. However, I'd like to stay away from using any controls and write this control from scratch.
Any ideas?
Thanks!
Yaron
|
|
|
|
|
You're assuming you need to repaint everything each time something is invalidated. If you look at the PaintEventArgs , you'll notice that it gives the invalidated region that needs repainting. Back when memory and CPU clock speeds were expensive, this invalidate region was paid more attention. Use it to your advantage.
Sure, you could dock a control and paint that separately, but you just increase the memory requirements and degrade performance by unnecessary processing required for a whole separate control.
Even the List-View common control (which the .NET ListView control encapsulates) paints things separately, from columns to items to sub-items, depending on what has been invalidated. This also is what gives developers control to override certain aspects of painting for specific "items".
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
Thx for the response! But, I still have problems with this...
I know about the invalidated region, but this is exactly what I'm worried about... For example, imagine the user scrolls down (assuming there are enough items). When he scrolls, the invalidated region is probably going to look something like {X=0, Y=300, <control_width>, <control_height -="" 300="">}, since windows will simply move whatever has already been painted up, and ask to draw just the part on the bottom that needs to be drawn. However, if my columns are simply drawn normally, it will scroll the columns up too! If this is the case, that means I need to step outside of the invalidated region (since the columns are all the way at the top, whereas windows wants to draw at the bottom), make a new Graphics object, and draw the columns OVER whatever is now at the top.
Isn't there any way to get around this?
Thx for all the help!
Yaron
|
|
|
|
|
The column headers shouldn't be part of the scrollable region. While the scroll bar control may overlap the column headers, the scrollable region is still the portion under the headers.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How would I specify that the column headers aren't scrollable? Since it's not a control, I'm just painting them, so how would I tell windows not to scroll it along with the rest of the control?
Yaron
|
|
|
|
|
If you control the scrolling, you control which regions are invalidated. Handle all the scroll messages from the scroll bar yourself and invalidate only the regions below the headers, if headers are visible.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
But I'm not using a scrollbar, or at least not technically. I'm letting windows handle the scrolling by using AutoScroll.
|
|
|
|
|
Hi
Someone knows where I could find documentation about how install remote Window Service, like in Dameware (remote administrator) where you can install the dameware service when you are Administrator of the domain, It'll be helpful install a service from my pc to the others, cuz many pcs are in other citys.
Any info will be greatful
Thanks
----
hxxbin
|
|
|
|
|
I have a DataTable (data) that contains 3 rows :
value1 value2
textA 0
textB 1
textC 1
I am placing this DataTable into a DataView and then filtering to get the rows where 'value2' does not equal zero :
DataView dvFiltered = new DataView(this.data, "totalUsed <> 0", "value2", DataViewRowState.CurrentRows);
int filteredCount = dvFiltered.Count;
string summary = string.Format("{0} Item(s)", filteredCount.ToString());
For some reason the count, sometimes returns the correct value but most of the time it doesnt, and I cant see a reason why. I have be stepping through the code to make sure the datatable contains the values it should and all that seems fine, as an example the following is taken from my VS watch list :
this.data.Rows[0]["value2"] - "0"
this.data.Rows[1]["value2"] - "1"
this.data.Rows[2]["value2"] - "2"
dvFiltered.Count - 1
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
In the resources file of Web Matrix, I found that the program is using one long bitmap that contains all the icons for the menu, toolbar, etc.
I would like to do this for my application, but I am not sure how to go about this.
How is the bitmap split into individual images?
Are these individual images added to an imagelist somehow? (if so, how?)
What is the best way for me to duplicate the strategy Web Matrix uses to grab an embedded bitmap (representing many icons) to use for my menu and toolbar?
Thanks in Advance!
|
|
|
|
|
If you want to create an ImageList , you can use ImageList.Images.AddStrip . To do this manually, it really isn't that hard. In most cases, squares are used. If the image is 32 pixels high, bitmaps consisting of 32 pixels wide are copied to individual Bitmap instances. You can use Graphics.DrawImage(Image, Rectangle, Rectangle, GraphicsUnit) or a similar method to assist with this process. Once Rectangle specifies the source bounds (in which case you increment the X coordinate by the height of the strip, if dealing with a horizontal strip) and the other specifies the destination bounds (in which case you use Image.GetBounds or the assumed Size and Point(0, 0) ). Use the same GraphicsUnit , which you'll most likely want to use GraphicsUnit.Pixel .
In most cases, ImageList.Images.AddStrip will do nicely.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am creating a bitmap drawing a pie chart and saving it as a gif in my windows app.
I am then linking and empbedding that gif (in the same process) into another app that generates a pdf on the fly.
However, when I close my windows app, the process does not end and i have to do it manually. Here's the code where i'm creating the gif.
const int width = 500, height = 200;
Bitmap objBitmap = new Bitmap(width, height);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics = Graphics.FromImage(objBitmap);
objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
DrawSpendingPieChart(ref objGraphics, alName, alNumber);
string path = storageFolder + "\\" + clientId + "chart1.gif";
try
{
objBitmap.Save(path, ImageFormat.Gif);
}
catch(Exception ioe)
{
throw ioe;
}
finally
{
// clean up...
objBitmap = null;
objGraphics = null;
}
r.cbChart1 = path;
Without the link to this gif, it works fine. The pdf generator links and embeds other gifs outside my windows app fine.
I have isolated the problem to the gif i'm creating. It seemingly remains in memory(even though i set it to null once saved) and is linked to my windows app process: and if used, it keeps my app open.
Does it have to do with Graphics.FromImage() creating a memory stream and retaining it even after I have set objBitmap to null?
Any help?
Dave
|
|
|
|
|
When a Type implements IDisposable like the Graphics and Bitmap classes, you must call Dispose before nullifying the instance variable (which really isn't necessary):
Bitmap bmp = null;
Graphics g = null;
try
{
bmp = new Bitmap(32, 32);
g = Graphics.FromImage(bmp);
}
finally
{
if (g != null) g.Dispose();
if (bmp != null) bmp.Dispose();
} In C#, you can use the using statement to do the same thing as above:
using (Bitmap bmp = new Bitmap(32, 32))
{
using (Graphics g = Graphics.FromImage(bmp))
{
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|