|
I am having problems making my app print multiple pages. I was hoping you could help me. This is what I have done:
private void button1_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
PrintDialog dlg = new PrintDialog();
dlg.Document = pd;
dlg.ShowDialog();
pd.DocumentName = "HasMorePages";
dlg.PrinterSettings.FromPage = 1;
dlg.PrinterSettings.ToPage = 2;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
iPageNumber = 1;
pd.Print();
}
public void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
Graphics g = ev.Graphics;
g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor),
256, 32);
g.DrawString(label2.Text, label2.Font, new SolidBrush(label2.ForeColor),
256, 1400);
ev.HasMorePages = iPageNumber < iNumberPages;
iPageNumber += 1;
}//pd_PrintPage
This code prints out label1 but not label2. If I change the y-coordinates of label2 to 140 it gets printed but on the first page. I would like to be able to make my app print label1 on the first page and label2 on the second page at coordinates of my choosing. Can you please spare the time to help me? How can I make label2 get printed on page 2.
Thank you and happy new year,
FJ
|
|
|
|
|
The PrintPageEventArgs.PageBounds is the bound for each page so it does not continue on. If PrintPageEventArgs.HasMorePages is not sufficient enough you'll have to keep track of pages printed yourself and check against that. You also shouldn't have your event handler public.
private int iPageNumber = 1;
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
if (iPageNumber == 1)
{
}
else if (iPageNumber == 2)
{
}
e.HasMorePages = iPageNumber == 1;
iPageNumber++;
}
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]
|
|
|
|
|
Hi, thanks for your answer.
This is a very elegant and nice solution, so obvious once I see it and that is the hallmark of good soulutions.
Thanks a lot and a happy new year
FJ
|
|
|
|
|
Hi there.
Thanks very much for your help. I did encounter something strange though when I did what you suggested.
When I print out what comes out of the printer is not the same as what I see on screen. If I see on the screen "27" or "3)" what gets printed is only the first character, "2" or "3". Why is that? The lines and curves I want to print out get printed out the way I want them to.
Thank you,
FJ
|
|
|
|
|
Without seeing any code I can't tell you, but be sure to call Graphics.MeasureString to know how big of a region to print in.
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]
|
|
|
|
|
Hi.
Well what I did is this. I created some Labels, added text and numbers to them and placed them on the form. When a selection is made from a menu, labels are put on the form and lines get drawn. With one of the selections everything comes out right both on screen and when I print it out. Then I just repeated what I did but I have chars missing from the text in the labels. This is very strange since I simply duplicated what I did before and it worked fine before.
Then this is what happens:
private void pd_PrintPageDeiling(object sender, PrintPageEventArgs e)
{
Graphics d = e.Graphics;
d.DrawString(nafn.Text, nafn.Font, new SolidBrush(nafn.ForeColor),(RectangleF)nafn.Bounds); //this comes out right
d.DrawString(nr1.Text, nr1.Font, new SolidBrush(nr1.ForeColor),
(RectangleF)nr1.Bounds); //this is where part of the text is missing and I just don´t understand why. The control nr1 has 2 chars (and only one gets printed) but the nafn control has 5 chars and they get printed out as they are seen on screen but not the nr1 label control.
Best regards,
FJ
|
|
|
|
|
i have host at brinkster in the host controlpanal i can make new email and edit, delete
but i need to know how can i make new email and delete in my windows applaction ?
Palestine
|
|
|
|
|
You can use the MailMessage class documented at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebmailmailmessageclasstopic.asp[^] along with the SmtpServer class documented at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebMailSmtpMailClassTopic.asp[^] which uses CDO, which is installed as a client by default on Windows 2000, XP, 2003, and newer. This class will work with .NET 1.0 and newer.
If you want more control over the content of mail you can use the new mail classes in .NET 2.0, document at http://msdn2.microsoft.com/library/System.Net.Mail[^].
Note that sending mail is different than receiving it. SMTP transfers mail between servers and from clients to servers, but protocols like POP and IMAP are what you typically use from a client to get mail from a server. What you see on Brinkster's site is a web interface. You need to see if they even allow for POP or IMAP. If they do, you can get libraries to get email and delete it (you're other desire from your second sentance).
Just search for "C# POP" or "C# IMAP" to find examples. This site should also have several tutorials and even source code. Just use the article search at the top of every page below the logo to search.
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]
|
|
|
|
|
hi guys,
i'm writing a software to control some telnet server, to achieve a sort of batch control for that. i got the communication running and i am able to send command bytewise to the server. the main problem are some menus where it is neccessary to press down the ENTER KEY (when logged in via commandline) to acknowledge. i ain't got any idea how to send the ENTER command to the telnet server. here is my sendcode
Byte[] byteDateLine = Encoding.ASCII.GetBytes(sendBox.Text.ToCharArray());
but how do i convert the enterkey keyvalue to byte, that it is recognized as a pressed enterkey?
can anybody help me?
|
|
|
|
|
You need to send a new line and/or carriage return character depending on the server. Most times just encode the \n character like in the following example:
byte[] data = Encoding.ASCII.GetBytes("dir\n"); The characters follow:- \n - new line
- \r - carriage return
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 develop web service with extensions that encrypt and compress some parameters of web method.
So I need get certain node("soap:Envelope/soap:Body/SendServiceDataInHeader/Body") in SOAP
message(got by serialization of web method) with XPath expression.
Here is SOAP message:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<ProtocolData xmlns="http://tempuri.org/">
<IsEncrypted>true</IsEncrypted>
<IsCompressed>true</IsCompressed>
</ProtocolData>
</soap:Header>
<soap:Body>
<SendServiceDataInHeader xmlns="http://tempuri.org/">
<To>zhornick@mail.ru</To>
<Cc />
<Subject>Subj</Subject>
<Body>Body</Body>
</SendServiceDataInHeader>
</soap:Body>
</soap:Envelope>
I tried with below code snippet but it doesn't work. It may be due to default namespace.
XmlDocument xd = new XmlDocument();
xd.Load("d:\\x.xml");
XmlNamespaceManager nm = new XmlNamespaceManager(xd.NameTable);
nm.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
nm.AddNamespace(String.Empty, "http://tempuri.org/");
XmlNode n =
xd.SelectSingleNode("soap:Envelope/soap:Body/SendServiceDataInHeader/Body", nm);
Of course I can get this node by writing:
XmlNode n =
xd.SelectSingleNode("soap:Envelope/soap:Body",
nm).FirstChild.FirstChild.NextSibling.NextSibling;
but it is not reliable and I want through direct XPath expression.
Help me resolve task please!
Andriy Zhornyk
|
|
|
|
|
IIRC you can fix this by adding a 'fake' namespace entry for the default.
nm.AddNamespace("foo", "http://tempuri.org/");
xd.SelectSingleNode("soap:Envelope/soap:Body/foo:SendServiceDataInHeader/foo:Body", nm); :->
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
Thank, it works.
Andriy Zhornyk
|
|
|
|
|
Glad I could help, it's one of those issues that can haunt you for days
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
hi all, can someone please help me to use this class in my application.
this is what i have so far.
<br />
[DllImport("Netapi32.dll")]<br />
extern static int NetLocalGroupAddMembers(<br />
[MarshalAs(UnmanagedType.LPWStr)] string servername,<br />
[MarshalAs(UnmanagedType.LPWStr)] string groupname,<br />
int level,<br />
ref LOCALGROUP_MEMBERS_INFO_3[] buf,<br />
int totalentries<br />
);<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]<br />
public struct LOCALGROUP_MEMBERS_INFO_3<br />
{<br />
public string domainandname;<br />
}<br />
<br />
private enum NERR_GROUP_MEMBER_ADD<br />
{<br />
NERR_Success = 0,<br />
<br />
NERR_GroupNotFound = 1,<br />
<br />
ERROR_ACCESS_DENIED = 2,<br />
<br />
ERROR_NO_SUCH_MEMBER = 3,<br />
<br />
ERROR_MEMBER_IN_ALIAS = 4,<br />
<br />
ERROR_INVALID_MEMBER = 5<br />
}<br />
then i call it with this
<br />
public bool NetLocalGroupAddMember(string groupname, string username)<br />
{ <br />
LOCALGROUP_MEMBERS_INFO_3 member = new LOCALGROUP_MEMBERS_INFO_3();<br />
member.domainandname = Environment.UserDomainName + @"\" + username;<br />
<br />
LOCALGROUP_MEMBERS_INFO_3[] members = new LOCALGROUP_MEMBERS_INFO_3[] { member };<br />
<br />
int retVal = NetLocalGroupAddMembers(SERVER_NAME, UserManager.DEFAULT_GROUPNAME, 3, ref members, 1);<br />
<br />
if (retVal != (int)NERR_GROUP_MEMBER_ADD.NERR_Success)<br />
{<br />
MessageBox.Show("Error Adding Member to Group",<br />
"Error",<br />
MessageBoxButtons.OK,<br />
MessageBoxIcon.Error);<br />
return false;<br />
}<br />
return true;<br />
}<br />
this returns the messagebox, and the retVal is 1387
this is the interface
<br />
NET_API_STATUS NetLocalGroupAddMembers(<br />
LPCWSTR servername,<br />
LPCWSTR groupname,<br />
DWORD level,<br />
LPBYTE buf,<br />
DWORD totalentries<br />
);<br />
i was unsure about the LPBYTE buf, whether it should be an IntPtr or not, if so, i cannot figure out the syntax.
can someone please help with this.
kind regards,
g00fy
|
|
|
|
|
|
yes i have.
the MS API says that the buf is '... The buf parameter points to an array of LOCALGROUP_MEMBERS_INFO_3 structures. ...'
thats why i tried the LOCALGROUP_MEMBERS_INFO_3[] in the signature
i think the problem is that the buf should be an IntPtr and not what is in that signature, but i need someone to clarify this. if it is suppose to be an IntPtr then how do i allocate the size of the LOCALGROUP_MEMBERS_INFO_3 as byte[] in mem ?
this is what i have now
<br />
[DllImport("Netapi32.dll")]<br />
extern static int NetLocalGroupAddMembers(<br />
[MarshalAs(UnmanagedType.LPWStr)] string servername,<br />
[MarshalAs(UnmanagedType.LPWStr)] string groupname,<br />
int level,<br />
ref LOCALGROUP_MEMBERS_INFO_3 buf,<br />
int totalentries<br />
);<br />
<br />
public bool NetLocalGroupAddMember(string groupname, string username)<br />
{ <br />
LOCALGROUP_MEMBERS_INFO_3 member = new LOCALGROUP_MEMBERS_INFO_3();<br />
member.domainandname = Environment.UserDomainName + @"\" + username;<br />
<br />
<br />
<br />
int retVal = NetLocalGroupAddMembers(SERVER_NAME, LocalUserManager.DEFAULT_GROUPNAME, 3, ref member, 1);<br />
<br />
if (retVal != (int)NERR_GROUP_MEMBER_ADD.NERR_Success)<br />
{<br />
MessageBox.Show("Error Adding Member to Group",<br />
"Error",<br />
MessageBoxButtons.OK,<br />
MessageBoxIcon.Error);<br />
return false;<br />
}<br />
return true;<br />
}<br />
kind regards,
g00fy
|
|
|
|
|
I've run out of ideas. I looked up 1387 and the description says ERROR_NO_SUCH_MEMBER (One or more of the members specified do not exist. Therefore, no new members were added.). You sure your parameters are logically correct?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
i am sure that my input is correct.
where did you look this constant up at ?
i googled for it and got nothing
kind regards,
g00fy
|
|
|
|
|
ok i found this list on msdn
but it doesnt have the 1380 err code, do you have a link to that resource please ?
i got it going to by the way, thank you for your help.
this is what i ended up with, im sure i had this at some point, maybe i was lacking sleep or something
<br />
public bool NetLocalGroupAddMember(string groupname, string domain, string username)<br />
{ <br />
LOCALGROUP_MEMBERS_INFO_3 member = new LOCALGROUP_MEMBERS_INFO_3();<br />
member.domainandname = domain + @"\" + username;<br />
<br />
int retVal = NetLocalGroupAddMembers(SERVER_NAME, LocalUserManager.DEFAULT_GROUPNAME, 3, ref member, 1);<br />
<br />
if (retVal != (int)NERR_GROUP_MEMBER_ADD.NERR_Success)<br />
{<br />
MessageBox.Show("Error Adding Member to Group: " + retVal,<br />
"Error",<br />
MessageBoxButtons.OK,<br />
MessageBoxIcon.Error);<br />
return false;<br />
}<br />
return true;<br />
}<br />
kind regards,
g00fy
|
|
|
|
|
I pasted the constant and hit "Go to Definition" in Visual Studio It's in winerror.h, in case you want to look it up.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Got to this link and register free for
training your self for VS2005
https://www.microsoftelearning.com/visualstudio2005/
or
http://www.financialexpress.com/latest_full_story.php?content_id=107645
Microsoft dont give anything free except training
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Funny, but I can't get ANY of these FREE courses. Every time error is returned:
"We’re sorry, but we were unable to service your request". Something tells me that it will happen until Nuvember 17'th when the free period will be over.
|
|
|
|
|
Got to this link and register free for
training your self for VS2005
https://www.microsoftelearning.com/visualstudio2005/
or
http://www.financialexpress.com/latest_full_story.php?content_id=107645
Microsoft dont give anything free except training
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
I've written classes for cards, hands, and decks. The hand constructor takes an array of cards as it's paremeter, like so:
public Hand(Card[] Cards)
{
... perform actions
}
But here's the thing. When I create a new hand, I'm current doing this:
Card[] cards = { deck.TopCard, deck.TopCard, deck.TopCard };
Hand hand1 = new Hand(cards);
Rather, I should be doing something like the following, only I can't figure out the correct syntax:
Hand hand1 = new Hand( { deck.TopCard, deck.TopCard, deck.TopCard } );
... Obviously, that throws an error, but I'm pretty sure you see what I want to do. I want to implicitly create the card array in the constructor paremeter. Is this possible?
|
|
|
|
|