|
I've done a bit more research, and found out that I was wrong about things work.
There isn't, as far as I can tell, a way to create an assembly from the netmodules that's identical to what you'd get if you went straight to an assembly.
|
|
|
|
|
I've seen a couple of applications that put Icons in the system tray and display text in the icon. Specifically I'm thinking of WeatherBug, which displays current temperature in the system tray. Is there a way to do that using c#? The NotifyIcon class has a Text property, but that controls what's displayed in the balloon, not text shown in the icon itself.
Thanks
|
|
|
|
|
sasdav wrote:
WeatherBug, which displays current temperature in the system tray
I would guess it is just usual icons that is shown in the system tray. You can't put text to the system tray (I think, I'm sure)... perhaps in XP, I don't know!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Yes. At least I think so.
I think what you'd need to do is create a new Image, get a Graphics object from it, draw to that Graphics object, and then save it out as an icon.
Then, open that file as an Icon instance and set the Icon property to that instance.
If you haven't written your app yet, I did a column on one last month. See http://www.gotdotnet.com/team/csharp
|
|
|
|
|
That's a good article, thanks for the link. But (you knew there would be a but, didn't you) I've already got an application that uses a static icon in the System Tray. I built a talking clock that tells me the time every so many minutes that I'm pretty proud of.
Do you have any more detail on adding text to the icon while the program is running?
By the way, you didn't happen to see my question about TAPI, did you? I haven't gotten a single reply on it.
Thanks again.
|
|
|
|
|
I'm not sure what extra detail you need. All you need to do is:
Image i = new Bitmap(16, 16);
Graphics g = Graphics.FromImage(i);
g.DrawString(...);
g.Dispose();
i.Save("test.ico", ImageFormat.Icon);
Icon icon = new Icon("test.ico");
notifyIcon.Icon = icon;
As for the TAPI question, I don't know the answer.
|
|
|
|
|
Well, maybe it's not. This code:
Image i = new Bitmap(16, 16);
Graphics g = Graphics.FromImage(i);
SolidBrush blackBrush = new SolidBrush(Color.Black);
g.DrawString("00",this.Font,blackBrush,new Point(0));
g.Dispose();
i.Save("test.ico",ImageFormat.Icon);
Icon icon = new Icon("test.ico");
notifyIcon.Icon = icon;
Generates this error:
System.ArgumentException: The argument 'picture' must be a picture that can be used as a Icon.
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(String fileName)
There is a file called test.ico being created, but when I load it into the icon editor it's just gibberish.
|
|
|
|
|
Another idea:
* When you create the bitmap, use the ImageFormat.Icon format. Create to a Bitmap rather than an Image,
* After you've done the drawing, use:
Icon icon = Icon.FromHandle(bitmap.GetHicon());
I *think* that should work; the docs from GetHicon imply that this should work. Please let me know.
|
|
|
|
|
Excellent! And it doesn't generate the test.ico file either. Thanks very much.
Here's the code I ended up with:
Bitmap i = new Bitmap(16, 16);
Graphics g = Graphics.FromImage(i);
SolidBrush blackBrush = new SolidBrush(Color.Black);
g.DrawString("text",this.Font,blackBrush,new Point(0));
g.Dispose();
Icon icon = Icon.FromHandle(i.GetHicon());
notifyIcon.Icon = icon;
|
|
|
|
|
Hi all, just a small question:
What is the correct way to try-catch in foreach loop?
I have , and it seems to work OK, but it looks like it should break the loop, which we dont want.
try
{
foreach (MyClass myclass in anArrayList)
{
DoStuff();
}
}catch (System.InvalidCastException e) {}
Anyone?
READ MSDN
|
|
|
|
|
In the above code snippet it appears that you are wary about 'anArrayList' not containing classes that are or inherit from MyClass. Unfortunately the only way to get it to continue through the loop is to write the foreach code yourself.
IEnumerator ie = anArrayList.GetEnumerator();
while(ie.MoveNext())
{
MyClass myclass = ie.Current as MyClass;
if( myclass != null )
{
DoStuff();
}
else
{
}
} A bit uglier, but it allows you to avoid an exception and you can continue processing the loop.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
|
Yes, that is ok.
There is one problem you may run into; and that is if you want to actually execute DoStuff on instances of MyClass as well as instances of a class that inherits from MyClass.
The above technique also won't work with all interfaces because of the way that the GetType() method works in regard to them.
Both cases can be solved by using the is and as operators. Essentially (not what really happens but the effect is the same) the is operator returns true of the left operand can be cast to the right operand. The as operator casts the operand to the type of the right operand, but returns null if the cast cannot be performed. If is returns true, then as will not return null and vice versa.
public class MyClass {}
public interface IMyInterface {}
public class Foo : MyClass {}
public class Bar : MyInterface {}
public class Baz : MyClass, IMyInterface {}
...
MyClass mc;
Foo foo;
Bar bar;
Baz baz;
mc is MyClass == true
mc is IMyInterface == false
foo is MyClass == true
foo is IMyInterface == false
bar is MyClass == false
bar is IMyInterface == true
baz is MyClass == true
baz is IMyInterface == true To me the is and as operators are more versitile than simply comparing the Type returned from GetType()/typeof.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Thx, James
James T. Johnson wrote:
There is one problem you may run into; and that is if you want to actually execute DoStuff on instances of MyClass as well as instances of a class that inherits from MyClass.
Thats exactly what I ran into, but simplified the code when I posted (me bad).
So is / as should be used like:
class Player{}
class Dealer : Player {}
class Players : ArrayList {}
...
Players players = new Players();
void Method()
{
foreach (Player player in players)
{
if (player is Dealer)
{
Dealer dealer = player as Dealer;
dealer.DoDealerStuff();
}
}
}
Seems to make alot more sense after writing it myself, dunno if the post is neccesary, but its here now Submit shall be clicked .
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Yep, you got it!
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Tad bit nitpicky but this code could be a little bit faster.
<br />
if (player is Dealer) <br />
{ <br />
Dealer dealer = player as Dealer; <br />
dealer.DoDealerStuff(); <br />
}<br />
In this code the CLR must determine the type of player twice. The first time it will check when you call "player is Dealer". Then it has to check again which you do player as Dealer. It would be slightly more efficient to write it this way.
<br />
Dealer dealer = player as Dealer;<br />
if ( dealer != null ) {<br />
dealer.DoStuff();<br />
}<br />
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
|
I am creating a custom control called DropDownGroup that is similar to the functionality found in the main screen of Money 2002 (its basically a GroupBox that has a minimize and hide button in the header area).
I managed to create a functional version that inherits from Control that does all of its painting in OnPaint, and overrides DisplayRectangle so that a fully-docked child control will not cover the header area. However, just overriding DisplayRectangle doesn't disallow an undocked child control from being positioned on the header area (the GroupBox control has this unwanted feature as well).
To try and remedy this I decided to paint my header in the non-client area of the control. I overrode WndProc and intercepted WM_NCCALCSIZE, WM_HITTEST, WM_NCPAINT, and the WM_NC mouse messages. My WM_NCCALCSIZE handler modifies the client rectangle so that I have room for my header at the top. The WM_HITTEST handler returns a value for the caption or the client area. I paint my header in response to WM_NCPAINT, and I use the NC mouse messages in place of the OnMouse... handlers...
Everything was working fine (I have a custom designer class for the control, and when you try to drag a child to the header area it displays the 'no' icon just like with the title bar of a Form), except my buttons (not controls, just drawn ones) were not highlighting in response to the WM_NCMOUSEMOVE message when the cursor was over them. The functionality worked in that everything responded to the WM_NC button messages as expected. I just couldn't get the non-client area to redraw. I've tried a ton of things (sending WM_NCPAINTs, WM_PAINTs, and calling Invalidate, in various orders) but nothing seems to work.
Does anyone know how to get the non-client area of a Windows.Forms Control to repaint itself?
Why does sending WM_NCPAINT not actually cause a repaint of the non-client area (my WM_NCPAINT handler gets called and does its work, but nothing changes on the display)?
I have the ControlStyles AllPaintingInWmPaint, DoubleBuffer, and UserPaint all set. Could that be affecting it (by my testing it doesn't seem to since I've tried all combinations of the three)?
Thanks in advance for any help or guidance.
|
|
|
|
|
I need a control similar to the Property Grid, but that I can use without an object. I would like to set my own "properties" with code and be able to retrieve what the user entered.
Short of writing my own (which I don't have time, this is an urgent project), does anybody have an idea??
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
You could use the Reflection.Emit API to create classes at runtime.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
James T. Johnson wrote:
You could use the Reflection.Emit API to create classes at runtime.
That sounds way too hard for a simple beginner like me! this is my first program in C#/.NET! But anyway, I'll take a look at it!
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Yeah, its definately not for the faint of heart; I haven't looked at the emit classes yet either
But unless you create your own PropertyGrid to work with an array of values thats the only option I can think of to use the existing grid.
If you don't mind not getting the look and feel of the property grid you could use a DataTable and a DataGrid to let the user enter data. It really loses its effectivness if you have more than a few different items to enter because of all the scrolling involved.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Luis Alonso Ramos wrote:
Short of writing my own (which I don't have time, this is an urgent project), does anybody have an idea??
Hi, just write a simple Seetings Class, thats what I do!
public class Settings {
string name;
string password;
public string Name {get{return name;}set{name=value;}
public string Password {get{return password;}set{password=value;}
}
Then just seriallize to object to a stream and deserialize to open. Note if u change your classes properties, you cannot deserialize an "old" version of the class to a "new" version of the class. Alternatively, you can reflect all the properties to an XML file and read it from there (not too sure how to handle non-primative class there, still looking).
If you dont have time to do this, then you really dont have time
Hope this helps
READ MSDN
|
|
|
|
|
This sounds interesting... I now have a property grid with the object I want (more or less working)... In the object I have properties like "Name", "SubName", "Phone"... how can I make the control display "Commercial Name", "Branch Name" and "Phone Number" in the grid (not at the bottom in the help panel)???
Also, any way to set this at runtime (so I can get them from the resources for localization purposes)?
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Global Property Grid
This should help you out.
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|