|
J4amieC wrote: How about a static helper method on your Hand class
Why? Its already Card[] !
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!
|
|
|
|
|
because he couldnt have 2 constructors one as "Card[] cards" and one as "params Card[] cards".
It was just a suggestion, call it syntactic sugar
|
|
|
|
|
The reason is that the methods or constructors would have the same signature and that, of course, isn't allowed for overloads. See the IL for a method defined using the params keyword in C#:
.method public hidebysig instance void Foo(object[] objects) cil managed
{
.param [1]
.custom instance void [mscorlib]System.ParamArrayAttribute::.ctor() = ( 01 00 00 00 )
.maxstack 8
IL_0000: nop
IL_0001: ret
} As you can see, the effect is achieved using an attribute but the parameter itself is just an object[] array.
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 am trying to implement a dynamic system tray icon in C#. There are tons of applications, like FreeRam XP and so forth, that have a system tray that updates with numbers or text. I was curious if anyone knew of a means for implementing such a system tray in C#. I am familiar with the notifyicon methodology in C# but I have never been able to find a means for doing it. Any ideas?
|
|
|
|
|
Depending how dynamic your icon would appear to be, you have a couple of choices. If you really only have a small handful of states - like some CD ripping or burning software I've seen - you could just have a collection of icons that show the different states and loop through them.
If you need more control and dynamic capabilities than that you must draw your own icons. You should find several good articles here on Code Project about drawing icons that should help you.
So, consider whether you need only a few icons to rotate or otherwise show state (like something's open, closed, or not present) and use a static list of icons or draw your own. You don't even need to save them to a file - just cache them in a list in memory and assign them to NotifyIcon.Icon .
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. I did an intensive search and found a posting on CodeProject.com from a couple of years ago, describing how to accomplish this task. Below is the code snippet:
Bitmap i = new Bitmap(16, 16);
Graphics g = Graphics.FromImage(i);
SolidBrush blackBrush = new SolidBrush(Color.Black);
g.DrawString(currentTemp,this.Font,blackBrush,new Point(0));
g.Dispose();
notifyIcon1.Icon = Icon.FromHandle(i.GetHicon());
|
|
|
|
|
You might consider using the using statement for cleaner and safer code to dispose objects because it compiles such that the call to IDisposable.Dispose is in the finally block of a try/finally :
Bitmap i = new Bitmap(16, 16);<br />
using (Graphics g = Graphics.FromImage(i))<br />
{<br />
g.DrawString(currentTemp, this.Font, Brushes.Black, new Point(0, 0));<br />
}<br />
notifyIcon1.Icon = Icon.FromHandle(h.GetHicon()); <br />
<br />
This posting is provided "AS IS" with no warranties, and confers no rights.<br />
<br />
Software Design Engineer<br />
Developer Division Customer Product-lifecycle Experience<br />
<span>Microsoft</span><br />
<br />
[<a href="http://www.codeproject.com/script/articles/list_articles.asp?userid=46969">My Articles</a>] [<a href="http://blogs.msdn.com/heaths/">My Blog</a>]
|
|
|
|
|
Hi there.
I am having problems making a small program I am making print out.
I put some Label controls on a form and also drew a line on the form. Then the plan is to make the program print out the text in the Labels and also the line drawn on the form.
The print_selected method is executed when the user selects Print from a menu. I can´t even get the PrintDialog box to appear
This is what I did so far:
private void print_selected (object sender, EventArgs ea)
{
PrintDocument prndoc = new PrintDocument();
PrintDialog prndlg = new PrintDialog();
prndlg.Document = prndoc;
if (prndlg.ShowDialog() ==DialogResult.OK)
{
prndoc.DocumentName ="Trial";
prndoc.PrintPage += new PrintPageEventHandler(OnPrintPage);
}
prndoc.Print();
}
void OnPrintPage(object obj, PrintPageEventArgs ppea)
{
Graphics grfx = ppea.Graphics;
// I don´t know what code to put here so that the line and also the text
//contained in the Label controls gets printed out.
}
Can someone please help me make the program print out what I want it to print out?
Regards,
FJ
|
|
|
|
|
To get the print dialog you need to use the PrintDialog class documented at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformsprintdialogclasstopic.asp[^]. If you want to show this before printing then your menu handler should show it and continue printing. The documentation has an example.
The code you need to put in there is just like you would draw on a form - use the Graphics object to draw lines, etc. You cannot, however, just print out the controls like you see them without a lot of work (there are tutorials on this site if you search). If you just want to print the text, however, then you can use the coordinates of your label controls and print the text in those label controls like so:
Graphics g = ppea.Graphics;
g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), (RectangleF)label1.Bounds); It's a basic example but hopefully shows you how to print the text. If you wanted to the show the label or any other control as you see it on screen you should search for articles using keywords like "print controls" or something similar on this site using the article search at the top of every page on this site right below the logo.
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.
So to print the other labels I would do like this?:
Graphics g = ppea.Graphics;
g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), (RectangleF)label1.Bounds);
g.DrawString(label2.Text, label2.Font, new SolidBrush(label2.ForeColor), (RectangleF)label2.Bounds); //and so forth?
What about the line/lines and curves that I may want to print out also? Do I code like: g.DrawLine(. . . . )and give the coordinates for each line/curve that I want to draw?
The program I am trying to make will have in some instances lines as well as label controls and in other instances it will have label controls and lines and curves. How do I go about coding for those scenarios? Do I need to code especially (and in a different way) for the scenario where the lines and curves need to be printed as well as the label controls?
I was hoping that to code printing would not be that complicated. I think I get the picture now. Thank you for your help Any further suggestions are very much welcomed if you have the time.
Best regards,
FJ
|
|
|
|
|
For your curves and other lines you do the same thing you're already doing. I recommend refactoring that code into a new method that takes at least a Graphics object as a parameter. Then, you can call that method from your OnPaint override (or Paint event handler, but overriding virtual or abstract methods is faster than even handlers and you have more control) and your printing override (or even handler). This makes your code more maintainable since the same code is used over and any changes affect both painting on screen and to a printer device.
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 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!
|
|
|
|
|