|
I have a C# 2005 program with Page Setup, Print & Preview Dialogs. Only problem is that if I invoke Page Setup repeatedly, (even without doing anything else) the margins are halved each time! If I run the print WITHOUT invoking Page Setup, it uses larger margins (on which I fail the print 'cos of insufficient space). I have downloaded and run a Microsoft MSDN example - and that does the same. I thought that Page Setup should start with the defaults and retain changes. What am I missing (please!)?
Pensioner Graham Dean
|
|
|
|
|
Nothing. That's a bug. I think it is culture dependant - are the borders displayd in millimeters instead of inch on your machine? The dialog is just not able to handle this cleanly.
Here is the workaround (with a slight rounding error):
PageSettings pageSettings;
PageSetupDialog dlg = new PageSetupDialog();
Margins curMargin = pageSettings.Margins;
pageSettings.Margins = new Margins(
ConvInchToMm(curMargin.Left), ConvInchToMm(curMargin.Right),
ConvInchToMm(curMargin.Top), ConvInchToMm(curMargin.Bottom));
dlg.PageSettings = pageSettings;
dlg.PrinterSettings = pageSettings.PrinterSettings;
if (dlg.ShowDialog() != DialogResult.OK)
{
pageSettings.Margins = curMargin;
}
Basically the dialog converts the metrics when leaving the dialog (only with Ok not with Cancel) but doesn't do it when entering which is causing the decrease.
If you have any other metric then millimeter you surely have to adjust the conversion:
private int ConvInchToMm(int hundrInch)
{
return (int)(hundrInch * 2.54);
}
|
|
|
|
|
Thanks a lot Robert - exlains everything, and I am glad it's Microsoft not me that got it wrong!
Yes, my machine settings are in mm. Problem is to know what the measurements are on the 'client' machine, and I also note that the Dialog has an Enable Metric property.
Gives me plenty to look at, and hopefully will now get everything working. Thanks again.
Pensioner Graham Dean
|
|
|
|
|
hello every body, I usually work with sql server so if anybody may help with MS Access I'd be thankful.
here 's my C# potion of code:
string selectId = "select categoryId from Category where categoryName = @catName";
myCommand = new OdbcCommand(selectId,myConn);
myCommand.Parameters.Add("@catName",categoryName.ToString());
myCommand.prepare();
myReader = myCommand.ExecuteReader();
at this level an exeption is thrown at the level of the odbc driver it says not enough parameters or something. 1 parameter missing. In my string i'm having only one parameter and it's @catName.
in the definition of the Add()function it says that the second parameter is the value of the named parameter. The function that contains this code receives the value of categoryName however it's not set! can anybody help pls
|
|
|
|
|
Should be this...?
myCommand.Parameters.Add("catName",categoryName.ToString());
|
|
|
|
|
I'm having a problem with the XmlSerializer in .NET 2.0 (I never had this problem in 1.1).
I have a class which currently contains only a bool property and a string property that I'm trying to serialize using the XmlSerializer. My Serialization code is simple and I've used it 100 times before:
XmlSerializer xout = new XmlSerializer(typeof(MyClass));
StreamWriter sout = new StreamWriter(fname);
xout.Serialize(sout, this);
sout.Close();
The problem is that as soon as I try and execute the first line the program hangs. I even tried to use [XmlIgnore] attributes on both of my properties to try and track down if one of them is causing a problem but that doesn't even work. I'm totally mystified. My class has two public properties (bool and string), two private fields (bool and string) a default parameterless constructor and two methods (one to serialize and one to deserialize). What could possibly be wrong?
|
|
|
|
|
Jon, try replacing typeof(MyClass) with new(MyClass)MyClass().GetType() and see if that helps?
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
-- modified at 9:49 Sunday 30th April, 2006
|
|
|
|
|
|
|
Thanks for the suggestion. I tried this.GetType() instead of typeof(MyClass) and that didn't seem to work either. I can't figure out what it's got against my class?
|
|
|
|
|
|
The XmlSerializer always worked for me in .NET 1.1 (or at least I could eventually get it working after figuring out all the tiny problems that tended to cause it to throw exceptions). This is the first time I've tried it in .NET 2.0 and it isn't even throwing an exception, it just hangs.
|
|
|
|
|
I'm using RNGCrytpoServiceProvider to generate a 4-byte random number, and then dividing that by Int32.MaxValue to get a Double between 0 and 1.0. Is the resulting number still random, or has it been compromised? Is there a better way to do this?
Jon Sagara
Look at him. He runs like a Welshman. Doesn't he run like a Welshman? Doesn't he? I think he runs like a Welshman.
My Site | My Blog | My Articles
|
|
|
|
|
There is also Random.NextDouble of course!
|
|
|
|
|
I'd prefer to use RNGCryptoServiceProvider, but if the way I'm performing the calculation compromises the number, I may as well use System.Random.NextDouble.
Jon Sagara
Look at him. He runs like a Welshman. Doesn't he run like a Welshman? Doesn't he? I think he runs like a Welshman.
My Site | My Blog | My Articles
|
|
|
|
|
I'm no expert but:
1. From a mathematical point of view: No as you are dividing just by a factor.
2. From a technical point of view: Yes, as a conversion to double normally also means that some rouding errors are introduced which MIGHT cause trouble (in means of security).
|
|
|
|
|
If you just want a normal random number you should use the Random class.
The random generators in the encryption engines is for creating encryption keys, as the Random class is way too predictable for that. Of course that means that the algorithm is more complex and therefore more time consuming.
---
b { font-weight: normal; }
|
|
|
|
|
The better way would be to use the BitConverter or go stylish
unsafe
{
fixed (int* p = &randomint)
{
return (float) *p;
}
}
|
|
|
|
|
Hi,
I would appreciate if somebody could post some links (or sample code) to transform a ADO resultset to string using XSL.
Thanks.
|
|
|
|
|
Prashant, see listing 2 in the .zip file on this[^] page. You don't need to register/subscribe in order to download the file.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I have a file that is being written to using stream writer. The file is written in frequent, random intervals. If I were to use a seperate application to grab a copy of this file (using File.Copy), would there be a chance the two applications would collide, while trying to perform operations on the same file? Or is the File.Copy method independant of whether the file is in use.. meaning I'd get the most recent copy from the last stream writer update?
Any help would be appreciated!
|
|
|
|
|
cmarcus wrote: have a file that is being written to using stream writer. The file is written in frequent, random intervals. If I were to use a seperate application to grab a copy of this file (using File.Copy), would there be a chance the two applications would collide, while trying to perform operations on the same file?
Assuming the stream writer has only locked the file for write operations (i.e. read operations are still allowed), then there should be no problem with the other application using File.Copy. It is essentially only reading the file.
cmarcus wrote: Or is the File.Copy method independant of whether the file is in use.. meaning I'd get the most recent copy from the last stream writer update?
It will get the version that was last updated by stream writer as a result of flushing the buffer.
|
|
|
|
|
pleas i want to know how to record a voice from the mic and play it back when i need
some one told me to try NBass i try it and i got these problem
====================
An unhandled exception of type 'System.NullReferenceException' occurred in nbass.dll
Additional information: Object reference not set to an instance of an object.
====================
it dosenot work i don't know why
all i need is code to record and play
simple code
|
|
|
|
|
|
i don't know what information you need
tell me like what ?
|
|
|
|