|
Hi
I have a code which prints to the printer using the PrintDocument & PrintPreviewDialog classes.
I need to specify at run time which paper size I want to use: A4, Letter, A3 etc. These are not custome sizes but rather standard sizes, listed in the PaperKind enum.
How can I force a certain paper size at run time? The PaperSize.Kind property is read only.
I tried using the PageSetupDialog too, hoping that I could simply pass it the requierd page size without having to display the dialog, but could not make it work.
thanks
|
|
|
|
|
Again, as I recommended before - and as MSDN recommends - enumerate the PrintDocument.PrinterSettings.PaperSizes (one the PrintDocument.PrinterSettings.PrinterName is set to the desired printer). If you look at the documentation for PrintDocument , the best place to set the PaperSize is in the handler for the PrintDocument.QueryPageSettings event, which occurs before each PrintDocument.PrintPage event:
private PaperSize paperSize;
private PaperSize GetPaperSize(PrinterSettings printer, PaperKind kind)
{
if (printer == null) throw new ArgumentNullException("printer");
if (this.paperSize == null)
{
foreach (PaperSize size in printer.PaperSizes
{
if (size.Kind == kind)
{
this.paperSize = size;
return this.paperSize;
}
}
}
else return this.paperSize;
throw new ArgumentException("The requested paper size is not supported " +
"by this printer.", "kind");
}
private void printDocument_QueryPageSettings(object sender,
QueryPageSettingsEventHandler e)
{
try
{
e.PageSettings.PaperSize =
this.GetPaperSize(e.PageSettings.PrinterSettings, PaperKind.A3);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Could not print the document: {0}",
ex.Message), "Print Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
e.Cancel = true;
}
} This should work; if not, read the documentation for PrintDocument , PageSettings , and PrinterSettings .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
Hello
I ned create a form dynamically from an XML document, the xml file must contain the control type, the variable name asociated to this control, ..., i.e.
<Parameter>
<Param name="Age">
<ControlType>Editbox</ControlType>
<Desc>Client age</Desc>
<Type>Integer</Type>
<Min>21</Min>
<Max>40</Max>
<Value>25</Value>
</Param>
</Parameter>
Please help me
|
|
|
|
|
|
An example here[^]. I think it's written with VB.NET, but that shouldn't be a problem.
RSS feed
|
|
|
|
|
Hello
I ned create a form dynamically from an XML document, the xml file must contain the control type, the variable name asociated to this control, ..., i.e.
<parameter>
<param name="Age" />
<controltype>Editbox
<desc>Client age
<type>Integer
<min>21
<max>40
<value>25
Please help me
|
|
|
|
|
I have a number with a decimal place and I need to round it does anyone know how?
|
|
|
|
|
Decimal.Round()
Mazy
No sig. available now.
|
|
|
|
|
|
I have the next code:
.
.
StreamReader inp = new StreamReader(@"c:\inp.txt");
Tx1.Text = inp.ReadLine();
inp.Close();
.
.
inp.txt contains "¡¡¿¿Test??!!"
and after reading line, Tx1 has = "Test??!!"
The ¡ and ¿ were ignored!! The same thing occurs with ñ, á, etc.
What is happenning?
Best regards
|
|
|
|
|
I guess the problem is come from Unicode Encding. Use other cunstructors of StreamReader which you can specify Encoding type in them.
Mazy
No sig. available now.
|
|
|
|
|
I made:
StreamReader inp = new StreamReader(@"c:\inp.txt",System.Text.Encoding.UTF7);
Tx1.Text = inp.ReadLine();
Inp.Close();
and it worked. Thanks.
However, it is the firts time I experienced this kind of problem. I live in South America. Now, ¿should I change all my thousands of programs to include this encoding parameter? or is this possible to change it any kind of global parameter?
Thanks for your help
|
|
|
|
|
Rostrox wrote:
However, it is the firts time I experienced this kind of problem. I live in South America. Now, ¿should I change all my thousands of programs to include this encoding parameter?
As far as your programs wants to work with Unicode world ,I think you should apply these change to them.
Mazy
No sig. available now.
|
|
|
|
|
I have two apps Test.exe, Server.exe
I'm using BinaryFormatter.Serialize() to Serialize my own class in the Test.exe App and send the resultant byte array across a socket to Server.exe and use BinaryFormatter.Deserialize() to recreate my class. But I'm getting the following Error on Deserialize in Server.exe
{"Cannot find the assembly Test, Version=1.0.1460.21386, Culture=neutral, PublicKeyToken=null." }
This seems to me that either:
1. I cannot Serialize with one app and deserialize with another.
Or
2. I'm missing something
I think its #2, any ideas ?
|
|
|
|
|
You are trying to deserialise a class that resides in another assembly.
If you define two identical classes, with the same name in two different assemblies, they are NOT the same class.
The solution to this would be to create the class in a DLL, thereby removing the assembly from the serilaistion (or something, but it makes it assembly independent), refference the object in the DLL from both assemblies, and run it from there.
Then you can deserialize without problems.
That should solve it m8.
Regards, and happy new year
Cata
|
|
|
|
|
Thanks for the reply,
That seems like overkill for a class that has three byte[] arrays.
Perhaps using the serliaization is not the correct approach then.
How would you send a storage class like this one over a socket between two different apps ?
Here is the class:
[Serializable]
class CipherMessage
{
public byte[] cipherBytes; // RC2 encrypted message text
public byte[] rc2Key; // RSA encrypted rc2 key
public byte[] rc2IV; // RC2 initialization vector
}
|
|
|
|
|
Remember a DLL is a library. If you have multiple classes you want to transfer between your apps, you could declare them all in there.
The alternative is break down the class into Byte arrays, serialize them, and send them as that, then deserialize and reasemble them at the other end. But that seens even more long winded than buidling a DLL.
Seriously, a DLL isn't hard, and it's probably the most sensible way to go. Just declare the type in a DLL and build it. Then add it through the refferences. You can add more classes later if you want. Alternatively, build the DLL in the same project as the other two executables, and refference it direct.
Cata
|
|
|
|
|
Just FYI...
If you're exchanging keys, you should take a look at the AsymmetricKeyExchangeFormatter class. Do a google search to find a good example of using it.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Thanks for the advice, but If I'm using Public/Private Key RSA(which I am) do I still need to use this class ? It appears to encrypt private key exchanges.
|
|
|
|
|
It's "recommended" according to the docs. I wrote a library that used a stream to send RSA encrypted files across a it, and I used that class to exchange the key. I then wrote a client and server that created network streams to send files across sockets.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
You could also create a SerializationBinder that can bind one Type (based on a string) to another Type. Cata's advice is best, though, and is common - especially when doing .NET Remoting. You have a shared assembly that contains the Types (which is a name, assembly, version, culture, and public key token) that both client and server use. This is the correct approach. Using a SerializationBinder is more for upgrading serialized documents between versions, or when you absolutely have to use a Type that you can get access to otherwise.
Search the C# forum for SerializationBinder for a previous discussion I was involved in some time back.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
If anyone has an idea what rubber banding is, and how you can introduce it to a drawing program. Please contact me
email2miles@yahoo.com
|
|
|
|
|
Why not look it up in google?
Cata
|
|
|
|
|