|
Does anyone know how to control scrolling programactically, e.g. scroll to the very end of the form?
Thanks!
|
|
|
|
|
P/Invoke SendMessage and send either the WM_HSCROLL (0x0114) or the WM_VSCROLL (0x0115) messages to the control handle (see the Control.Handle property in the .NET Framework SDK).
This has been covered many times here in the C# forum in the past, so I direct you to a previous response and urge you to try searching for answers first by clicking "Search comments" above the message board, or search the articles using the search textbox underneat the CodeProject logo.
See http://www.codeproject.com/script/comments/forums.asp?msg=719589&forumid=1649#xx719589xx[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am developing a NotifyIcon app with C#. I want to show the context menu
when user left-clicks on the icon, the same as he/she right-clicks on it. In
that event handler, myNotifyIcon_Click(), I call
myNotifyIcon.ContextMenu.Show method. But I am not sure what these two
parameters I should feed.
Thanks in advance.
David
|
|
|
|
|
There are many ways of doing this. The NotifyIcon component encapsulates the Shell_NotifyIcon functions and context menu-related functions like TrackPopupMenuEx . While you could simply P/Invoke the latter API as well as a few others, the easiest way would be to use Reflection to invoke the method that already does all this for you:
MethodInfo method = typeof(NotifyIcon).GetMethod("ShowContextMenu",
BindingFlags.Instance | BindingFlags.NonPublic);
if (method != null) method.Invoke(notifyIcon1, null); If you want to know how that method works, use the IL Disassembler (ildasm.exe) that ships with the .NET Framework SDK if you know how to read Intermediate Language (IL), or a good decompiler like .NET Reflector[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please read the code snippets below
snippet 1: Drawing rectangle using Device Context
-------------------------------------------------------------[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool Rectangle(
IntPtr hdc,
int ulCornerX, int ulCornerY,
int lrCornerX, int lrCornerY);
public void GetHdcForGDI(PaintEventArgs e)
{
// Create pen.
Pen redPen = new Pen(Color.Red, 1);
// Draw rectangle with GDI+.
e.Graphics.DrawRectangle(redPen, 10, 10, 100, 50);
// Get handle to device context.
IntPtr hdc = new IntPtr();
hdc = e.Graphics.GetHdc();
// Draw rectangle with GDI using default pen.
Rectangle(hdc, 10, 70, 110, 120);
// Release handle to device context.
e.Graphics.ReleaseHdc(hdc);
}
-------------------------------------------------------------
snippet 2: Drawing rectangle using PrintPageEvntArgs
-------------------------------------------------------------
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Pen redPen = new Pen(Color.Red, 1);
e.Graphics.DrawRectangle(redPen, 100, 100, 100, 100);
}
-------------------------------------------------------------
Please explain what is difference between drawing rectangle using Device Context and PrintPageEvntArgs in terms of the concept and merits
regards
|
|
|
|
|
A device context can be practically any output device, from a monitor to a printer to a virtual screen buffer. You actually have to set up a device context (or get it from an existing source) and translate all the units if necessary. It also requires marshaling to a P/Invoke'd function.
Painting to a printer using the .NET FCL printing capabilities handle everything for you and should be used. Besides, look at what you had to do to draw a simple rectangle using the HDC compared to the Graphics object (which is actually a GDI+ object, where an HDC is used most often for GDI).
If you want to learn more, read about the HDC and GDI functions in the Platform SDK and compare that with the graphics information in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've noticed that some programs have nice smooth icons with lots of colors, whereas others are the regular type with jaggie edges and up to 256 colors.
How is it possible to create such icons and add them to the application in VS.net & C#?
|
|
|
|
|
You need a program that can do that. Typically, these icons are created in a decent graphics program like Adobe Photoshop using alpha channels (not just anti-aliasing, which requires a background color to blend with). You can then use a program to save the images (some can even read PSD files, but you typically save the images, or frames, in a format that supports alpha channels like PNG) as icons, like IconWorkshop, from Axialis[^], which I like and use.
Then, you simply use these in your .NET applications. You can, for instance, create an ImageList with 32-bit colors (to support the alpha channel). There is a problem, though: the ImageList contains a bug where the alpha channel is typically lost. You can help this by placing a .manifest file in the same directory as your executable (using the executable name + .manifest). This binds the GDI+ ImageList to Windows Common Controls 6, which features alpha channels. See my article, Windows XP Visual Styles for Windows Forms[^] for a brief overview of the .manifest file. Other articles here on CodeProject discuss other ways to get around this bug.
You can also load these images or icons yourself using other classes in the System.Drawing namepsace, such as the Bitmap class. Read the .NET Framework SDK documentation for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
There is a problem, though: the ImageList contains a bug where the alpha channel is typically lost. You can help this by placing a .manifest file in the same directory as your executable (using the executable name + .manifest). This binds the GDI+ ImageList to Windows Common Controls 6, which features alpha channels.
The problem then is that the background never gets invalidated, and hence u end with 'halos'. Best just to draw it yourself.
Btw Heath, do you know whether all of these Image related bugs in NET have been fixed in version 2? Especially the ImageList bug, where the implementor never checks the bounds or an image inserted?
top secret xacc-ide 0.0.1
|
|
|
|
|
I haven't actually had a lot of chance to play around with it. I've just been too busy here at work and frankly don't work on my computer much at home anymore (I do it enough hours here at work).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
I've just been too busy here at work and frankly don't work on my computer much at home anymore (I do it enough hours here at work).
I wouldnt have said so!
top secret xacc-ide 0.0.1
|
|
|
|
|
I still accomplish a hell of a lot and am expected to do just about everything, so it needs to get done (though I delegate quite a bit of stuff to my employees. Cummulatively, I probably only spend about 45-60 minutes / 11-13 hour work day, unless there's a crunch for something. With all those hours in a day and what I have to go through, I think I'm entitled to a little personal time.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What about such icons as the application icon?
I notice some programs like AIM and VS use the newer looking icons.
However there doesnt seem to be a way to set something like a PNG image as the application icon.
Is it possible to to that for the app. icon in VS?
Thanks!
|
|
|
|
|
For the icon that gets used as the application's .exe icon, yes, you can use alpha-blended (again, not just anti-aliased) icons with no problem. That actually has nothing to do with .NET. The compiler (during assembly) embeds that icon into the .rsrc section of the PE/COFF executable that also contains the forwarded loader address for mscoree.dll. You will have no problems doing that. It will also work fine if you treat it just as an image and don't stick it in an ImageList , like for the main Form icon or a NotifyIcon icon, etc.
The best way to see is just to try it out: use icons with noticable alpha channels (like anti-aliasing against an alpha channel, so to speak) and use them in different ways. That'll give you a better idea and experience as opposed to trying to answer all the possibilities we can think of.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm writing a little command line regex search and replace doodad. The user can put in some input, either through a file or stdin a search expression via command line or a file, and a replace expression via command line or file. It's the replace expressions that are giving me trouble. I'd like to be able to put a \t in the replace expression and have it place a tab during the replace.
When I put the \t in a string in the code, it gets replaced as a tab, of course. But if I put one in the expression on the command line, it gets read as a literal string. When I read the expression from a file, even if it has hard tabs in it, they somehow get converted to literal /t's somewhere in the replacing. I'm totally stumped. Can someone help me?
EDIT: I ended up using regex to find all the \t's (and \n's) in the replace string and replacing them with tabs and newlines. To actually find a literal \t though, I ended up having to quadruple escape them (\\\\t) :p.
|
|
|
|
|
Because the character '\t' (0x9) is different from "\t". An escape character is just that - a single character. When you read input from the command line, everything is already a string and each character is treated as a separate character.
The only way to really treat this string as the character is to perform a string replacement for known escape characters. You could use string.Replace("\\t", "\t") and other sequences (or use a simple map for fewer lines of code and easier maintenance).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi everybody, this is my first post so please bear with me. Ok here's what I am trying to do, and for the love of me I can't 'see' an implicit conversion happenning, so why the hell is the compiler whining???
here is a class skeleton, similar to what I have
public class X
{
protected void ThisIsKillingMe(byte[] oldABC)
{
byte[] newABC = new byte[100];
// line below reports an implicit complier error
newABC[i] = oldABC[p] ^ xyz[q];
}
private static readonly byte[] xyz = {0x12, 0x5F, ....};
}
Thanks for any and all help.
|
|
|
|
|
I'm presuming that when you perform the ^ on the two byte data types (which are Integers, btw), the compiler performs an implicit conversion to Integer. You are then trying to assign the resultant integer value to the newly declared byte array.
You probably need to cast the result back to byte.
Or I could be totally full of it
|
|
|
|
|
You are the Man. Thanks so much, doing this worked -
newABC[i] = BitConverter.GetBytes(oldABC[p] ^ xyz[q])[0];
|
|
|
|
|
|
Hi. Im -sort of- new to the C# languange and have read a couple of tutorials and such. I think I have the basic knowledge of it but would like something to challange me. Would anyone know of a site that contains just little beginner task.
|
|
|
|
|
No.... hey write i program that finds one!
Just kidding, try some of the sites listed at the bottom of the page.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Note that knowing C# doesn't mean you know .NET. C# is just one of about 30 languages that targets the Common Language Runtime (CLR). It uses the .NET Framework Class Library (FCL), even if only a little (like the primatives). Read through the class library documentation of the .NET Framework SDK. At least get an idea of what's available and how the classes and other types work.
[EDIT] This isn't meant as a slam, merely a suggestion to help you learn about .NET, not just a language. The distinction is important, understanding that the language is merely a syntax (some support more features, mind you) for writing a managed application or library. [/EDIT]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
[EDIT] This isn't meant as a slam, merely a suggestion to help you learn about .NET, not just a language. The distinction is important, understanding that the language is merely a syntax (some support more features, mind you) for writing a managed application or library. [/EDIT]
This is very true. I came here trying to learn C# and realized about a month ago that I need to understand the .NET framework, because it's the framework that all the .NET languages use. Then C# is just learning syntax to acces the underlying system.
Great answer Heath. Voted you a fiver for this one.
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!
|
|
|
|
|