|
well.. why don't you just check if the stream position property equals to the length?
that should solve the problem.
void Open()
{
FileStream stream = File.Open(@"C:\myfile.txt", FileMode.Open);
byte b;
while (stream.Position < stream.Length)
{
(b = (byte)stream.ReadByte()) != 255
Console.WriteLine(b.ToString());
}
}
It will also work if you are using a BinaryReader.
|
|
|
|
|
I want my program downloads an HTML file from a site using a simple address that normaly causes my browser to redirect to a LONG complicated address showing the site im after.
But when i try to access the same page from my program using the same shortened address i download an HTML file but its just basicly a blank html file (head and body) with an error message in the body.
Rather than the page my browser redirects to.
I have tried feeding my program the LONG(actual) address and it reads the file just fine form there. But i cant depend on my program recieving the long direct address when its up and running.
So is there a way to get it to read the page it should be redirected to?
Thanks.
-- modified at 21:30 Wednesday 5th October, 2005
/EDIT: I meant to add im using request.AllowAutoRedirect=true;
|
|
|
|
|
Hmm it seems the redirection does work when used on other pages.... is it possible that some form of spider/bot blocking could be inplace to stop the redireciton or is it somthing as simple as me needing to learn how to enable cookies, etc?
|
|
|
|
|
Hi,
I am doing a project using forms. I want to create a global struct common to all forms. I want to create an array of that struct and to set the values in one form and retrieve in other forms.
How do I do it. I have created the struct but each time when I create an object for the struct the values are lost.
pls help.
|
|
|
|
|
hi there,
Sure everytime u create an obj for the struct, actually it's a new obj so no old values are stored in this obj.
ter81 wrote:
I want to create a global struct common to all fo
just create this in the top parent form's scope so that u can access this later in another forms. And this will be freed from memory when the top form is closed.
Hope this answers
<< >>
|
|
|
|
|
I dont have a parent-child form hierarchy, but individual form that have links to each other.
I have created the structure iinside the namespace. but I was wondering how do I create a global object for this structure.
|
|
|
|
|
You can do whatever u want in ur app. But whenever ur app is still alive, the pointer to the struct should be persistent too.
U can achieve this by using static variable.
<< >>
|
|
|
|
|
There is no such thing as global in C#. Instead, create the array as static within a class you use for that purpose, then you can access it from anywhere.
If it's being used only in one class, then just make it static in that class. Static means that only one exists, no matter how many class instances exist.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I get the currency symbol from just the ISO 4217 standard 3-letter code.
CAD = $
USD = $
GBP = £
YEN = ¥
I tried creating a RegionInfo by stripping out the first two characters of the 3-letter code but is doesn't work for all cases.
Any ideas?
|
|
|
|
|
I have writen a program that extracts data from a source that can be highly ambiguous with its formatting of address lines but the Postcode is always(99.9%) correclty formated. The database my program need to export this compiled data to requires very specific address formatting.
So i was wondering what was the best way look up addresses from UK postcodes in a way that will spit out an address in a consitantly formatted manner so they might be more easily translated into my dataset.
Web services, third party programs, anything?
The free'er the better as this is for some volunteer work I'm undertaking and the budget is ... well.... next to nothing.
Cheers.
|
|
|
|
|
Dear all,
To get familiar with the C# language I have started a project involving Forms, Controls and GDI+. The aim is a sort of curve editor (don't ask me why)
Please have a look at the following screenshot:
http://www.redtricycle.net/code/gamma_curve_unpainted.png[^]
The structure of the program is as follows:
- The window is a standard Windows Form.
- The khaki rectangular area is an inherited Panel which implements a Paint event handler to draw the grid and the curve.
- The point handles inherit from Control objects (which easily facilitate the handling of mouse events). These controls are added to the Panel.
As you might notice, there is this rectangle of 200x100 that won't be painted. Only the controls inside the panel are painted but not the stuff drawn by the Panels Paint event handler.
Since the default size of a panel is 200x100 I've overridden the DefaultSize property and set it to 0,0 but this did not have any effect.
Do any of you have an idea of what could be the problem here? I'm a little puzzled by it.
Thanks for your response in advance!
For those that want to get a feel of the program, the exe is here:
http://www.redtricycle.net/code/GammaCurve2.zip[^]
Red Tricycle
|
|
|
|
|
You need to clip the Panel by either setting its Region property to just the part you draw, or in your OnPaint override (or handling the Paint event, although deriving your own class fosters better reuse of code) or set the Graphics.Clip property.
I do recommend considering not using controls such as Panel for the various drawing elements. Use polymorphism to define a base class for graphical objects that derivative classes override the painting. The panel would simply host a collection of the base class and call the virtual painting method. This requires far fewer system resources because controls are reather heavy-weight objects and you will notice as you get more controls hosted in your process.
There are lots of articles here on CodeProject about supporting this polymorphic model.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the reply and for giving an interesting insight in how to set things up in a light-weight fashion. I'll investigate this option for sure but first I'll try the Region/Clip options.
|
|
|
|
|
Hi!
I'm implement my own calendar class derived from System.Globalization.Calendar.
I need to make my calender with more that 12 months in a year (say 16). But then I use the DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar), it givs me a ArgumentOutOfRangeException. The parameters states that month is 1 through the number of months in calendar and day is 1 through the number of days in month. There is the problem how do I define my own calendar class so I can set ex. DateTime(1800, 15, 10). I thing that DateTime use the abstract mathod ToDateTime(...) to deliver a instance.
May help:
http://www.abgeen.com/JalaliCalendar.cs[^]
http://www.cs.oberlin.edu/~jwalker/calendarReform/GlobalCalendar.cs[^]
Best regards, Gywox
|
|
|
|
|
What's the best way to validate a filename?
In my UI, the user must enter a filename in a Forms.TextBox control.
This would be for a new file for saving data, so checking if it exists is of no use.
I can override the OnValidating event, but what chars do I look for?
Kathy.
|
|
|
|
|
The Path object has an InvalidPathChars property. Look for that in the user-entered string like so:
if(myPath.IndexOfAny(System.IO.Path.InvalidPathChars) == -1)
{
}
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Hi all!
I am writing an windows application using MySQL as the source database. Can anybody tell me how to get the datarow when I select some specified rows from the database please? I try to use the following way to do that, but it doesn't work:
<br />
string commandtext = "select * from machine where price = 100;";<br />
OdbcCommand command = new OdbcCommand(commandtext, connection);<br />
OdbcDataReader reader = command.ExecuteReader();<br />
ArrayList row = new ArrayList();<br />
int i = 0;<br />
while (reader.Read())<br />
{<br />
row.Add((DataRow) reader.GetValue(i++);<br />
}<br />
reader.Close();<br />
Could anybody tell me how to solve this please!!!
Thanks in advance!!!
Asura
|
|
|
|
|
OdbcDataReader.GetValue gets the column specified by the ordinal you supply. So reader.GetValue(i++) only returns one column and if you have multiple rows (more rows than you have columns) you will probably find that your code throws an exception once i is greater than the number of columns in your database.
If you want all the columns you need to use GetValues which will fill an array with all the column values you have.
The easier way to do this though is to use a DataTable.
Also, if you're using MySQL you could consider downloading and using the MySQL Connector for .NET (http://dev.mysql.com/downloads/connector/net/1.0.html[^])
|
|
|
|
|
You can't get DataRow objects from a DataReader. If you wan't DataRow objects, use a DataAdapter to fill a DataSet.
---
b { font-weight: normal; }
|
|
|
|
|
Hi
I have a mainform that opens up another form 'A'. By doing something on form 'A', opens up form 'B'. Both forms 'A' and 'B' should have access to the instance and fields of the mainform. What is the best approach? This is not MDI. Should it be? Can MDI be avoided in this case?
|
|
|
|
|
One way is to have each opening form pass an instance of itself to the form it opens and have that new form store that instance. If you want to access you form class's methods and properties, define the field in the new form as the type of your form and not simply Form (otherwise you'll have to cast your field to the right type before calling non-overridden methods and properties).
Such a property does already exist and allows owned forms to be minimized and restored along with the owning form. Read the documentation[^] for the Form.Owner property for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a two part problem, I'm currently working on.
I have some code which will capture a screenshot of a window, based on the window handle.
However, I don't know how to get the window handle of windows external to my application. Anyone know a simple way to do this? It would be very helpful if I could just simply retrieve an array of all the window handles belonging to windows currently open (minimized or maximized).
I also need to know how to simulate a mouse click in an external window, if I know the window handle.
Thanks!
|
|
|
|
|
You can either enumerate top-leve windows by P/Invoking EnumWindows , or simply use Process.GetProcesses like so:
foreach (Process p in Process.GetProcesses())
{
if (p.MainWindowHandle != IntPtr.Zero)
{
}
} To simulate a mouse click, you can get a window handle (from a top-level window handle, P/Invoke FindWindowEx[^] and post WM_LBUTTONDOWN and WM_LBUTTONUP , which you can find the values for in the Platform SDK.
You could also P/Invoke SendInput[^]. For further help on that, see the Platform SDK on MSDN[^] or search this forum for "SendInput". I have posted this solution a couple of times that I can remember in the past.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I think that's the fastest response I've ever recieved on these forums. And a VERY helpful response. Thank you VERY VERY much.
|
|
|
|
|
After looking at this method for about a day, I've realized it will not do what I need. Using the process object returns processes - and I need applications, that are not listed in the process list. Not just applications, but the window handles to all the windows that are urrently open on the desktop; many applications have more than one window open at a time, I need them as well.
|
|
|
|