|
Since JPEG doesn't support an alpha channel (ever considered saving as a GIF or PNG instead?) and you can't just say "set a background color". You can make colors transparent, but that's not your problem (quite the opposite, in fact).
Instead you'll need to parse the ICO format that is documented in http://msdn.microsoft.com/library[^] to get the palette, then get the transparency mask (IIRC, it's the first color in the palette). Finally, use Bitmap.LockBits , enumerate each pixel and use Bitmap.GetPixel to determine if that color is the same as the mask, then use Bitmap.SetPixel to set the color for the transparent pixel. When you're all done, use Bitmap.UnlockBits and save the image.
Another way is to create a Bitmap of the same size, set the background color, then get a Graphics object for the Bitmap and draw the icon onto the new bitmap. Save it as whatever format you like.
Honestly, saving this as a GIF or PNG (supports true alpha channels; GIF supports only masks and only 256 colors) would be much easier and are also widely used formats.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all,
I have created an application in which i use the window form's Autoscroll feature to scroll the window. Within the form's Paint event handler i am drawing some objects on the form. When i scroll the window using the scroll bar, all the objects are getting scrolled properly. I have a ruler, which is drawn on the top of the form. This should not get moved while scrolling the window using the scoll bar..How can i always fix it (the Ruler) to top of the client area of the form .. Please give any input....
thanks,
Pradeep
|
|
|
|
|
Two easy ways:
1. Draw the ruler on another, non-scrolled window (I think this is the best way). This has the advantage of creating a reusable ruler control.
2. Draw the ruler, but consider AutoScrollPosition to calculate its position. See the docs of AutoScrollPosition property for more details.
Yes, even I am blogging now!
|
|
|
|
|
Hi,
I am writing a concole application in which the user should be able to edit already entered/obsolete information. What I would like to do is to have Console.ReadLine read the obsolete information as if it was entered by the user and thereafter process keyboard input as usual. Like this:
:>edit entry1
entry1: obsolete information_
In DOS, this could for example involve writing each character to the keyboard buffer. Can I force characters into an input stream or somehow modify the stream's underlying structure?
Thanks!
|
|
|
|
|
SebbaP wrote:
Hi,
I am writing a concole application in which the user should be able to edit already entered/obsolete information. What I would like to do is to have Console.ReadLine read the obsolete information as if it was entered by the user and thereafter process keyboard input as usual. Like this:
:>edit entry1
entry1: obsolete information_
In DOS, this could for example involve writing each character to the keyboard buffer. Can I force characters into an input stream or somehow modify the stream's underlying structure?
While you could do the same things using the Console API via DLLImport, this would be a huge hassle, just to avoid doing a GUI. Usually, you use console applications where user interaction is not needed (e.g., batch files).
You'll spend lots and lots of lines of code trying to emulate a textbox in a console application and you'll end up with a poor interface: all of this is already done, and with a better face.
Yes, even I am blogging now!
|
|
|
|
|
I want to compare to strings, where one contains wildcards.
i.e. String.Compare("LongWord", "*ongW*", true)
I would want this expression to be true (Hence return 0).
How to a compare two strings using wildcards?
Thanks
|
|
|
|
|
|
Hi,
I've implemented global mouse and keyboard hooks in C#, however, once I set the hook type to WH_CBT and run the application, an ugly black command prompt screen prompts out saying there was an error in CLR at runtime
Has anybody been able to implement system-wide CBT hooks in any .NET language?
If I keep getting stuck in this, can I make a c++ DLL that does all the hooking and use it in my C#/VB.NET app?
Thanks
|
|
|
|
|
Without any more details than that, it's impossible to help you. What was the exact error? Debug your application (if you're using VS.NET, you should be prompted to attach a debugger) and find out what the offending code is, as well as the exception. That, too, could be greatly beneficial to us when trying to help you.
A word of extreme caution: global system hooks are dangerous. Write clean, efficient, error-handling code that does what it needs quickly. Managed code isn't already the best idea for this (at the very least, there is a performance penalty for marshaling between native and managed code), but it is possible.
As far as using a native DLL (which I recommend for the reason I gave above), yes you can use it. The question is how. .NET can interoperate with COM using RCWs (runtime-callable wrappers), otherwise known as "interop assemblies". .NET applications (actually, only those languages supporting it; CLS-compliant only (like JScript.NET) will not) can also P/Invoke native functions. The problem with that - unless you're using global memory in your native system hook DLL - is that you're not accessing that instance.
You should use either global memory (which .NET could actually access itself instead of P/Invoking native functions, although that would make for a clean, self-contained design) or some sort of IPC to communicate with your native and managed code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The hook worked fine globally with keyboard and mouse hooking. Once i set the hooking type to WH_CBT and run the code: at first the app runs normally...my cbt procedure seems to receive messages normally when I open new windows inside my app's thread. Once I give the focus to a window outside the app, the command prompt black (ugly btw) screen pops giving a message title: Microsoft Common Language Runtime Minidump Utility (with no error message whatsoever) and the system freezes for a while, before closing VS.NET and the app itself (i'm running it in debug mode of course).
I was wondering what the problem could be...if it had run smoothly with keyboard/mouse hooks...why is it only with the WH_CBT that I get the hard things?
I've tried to implement the same code in C++ and again, it ran smoothly with keyboard/mouse hooks, yet with CBT it gives the same trouble, although I had unset /clr and the code was supposed to be unmanaged...still the CLR Minidump Utility ruins the thing...why is that?
|
|
|
|
|
Hadi Fakhreddine wrote:
Once i set the hooking type to WH_CBT and run the code...
I hope - and assume - that you're not just registering the same hook proc with a different type. Perhaps a little code snippet of your CBTProc (or however you defined your delegate and the handler) would be handy.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I'm using cutting edge's code from MSDN Mag found here http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/ [^]
He uses the code for a local hook, I used it for system-wide by just changing from
m_hhook = SetWindowsHookEx(<br />
m_hookType, <br />
m_filterFunc, <br />
IntPtr.Zero, <br />
(int) AppDomain.GetCurrentThreadId());
to
m_hhook = SetWindowsHookEx(<br />
m_hookType, <br />
m_filterFunc,<br />
Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), <br />
0);
I kept the CBTProc the same as is...
|
|
|
|
|
when I usea datagrid to update dataset tables primary keys,It always has errors,How Do I?
|
|
|
|
|
|
When you update a row, the row state is set to DataRowState.Modified and the DataAdapter derivative you're using will use the UpdateCommand along with the primary key to update the row in your data store. If you change the primary key, the UpdateCommand will fail because there is no row (most likely) that contains that key (now that you've changed it).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi
Well i am using Microsoft Internet Explorer Tree view WebControls.
I am working on ASP.net with C# as the language.
Well i want to Have no node selected or Hide Tree view first Node when we load the tree.
how do we go abt doing this?
plz rely ASAP
if any body can help it will be gr8.
Regrds
Tejas
|
|
|
|
|
|
Yes tried that dose not work
still the Selected node index=0 when the tree is rendered
Thanx
|
|
|
|
|
Both the above ways return the line spacing that includes the blank space between lines along with the height of the character itself.
When I use the return value to calculate number of text lines to be inserted in the document that I am creating, lets say it is 74 lines per page. But after creating the page only 54 text lines get inserted in a page and rest of the text lines get passed to next page.
In other words, word processor inserts its page break after 54 lines.
The font I am using is MS Gothic, size 11.0. When I convert it in Twips its is 225 and Lenght of A4 size paper is 16833 Twips.
Thus to insert 54 lines per page the font height should be 311 Twips, where as I get 225.
Please guide.
|
|
|
|
|
Measuring a font without regard to a device context (HDC in native code; encapsulated by the Graphics class in managed code or an IntPtr if you P/Invoke native Windows APIs) can yield invalid results.
Instead, either use a Graphics object passed to you (if provided; for example, from PaintEventArgs.Graphics in your Paint event handler or your OnPaint override) and call MeasureString to measure the font height for a line of text (with plenty of hanging glyphs).
You can also P/Invoke native functions like GetDeviceCaps (which hopefully you're doing already to make sure you're calculating twips correctly and not assuming 96 DPI; if you are, search for GetDeviceCaps in this forum and you'll find a handy little class I posted for correctly converting without taking a dependency on Microsoft.VisualBasic.Compatibility.dll) and use GetFontData . You can also get an HDC (as an IntPtr from the Graphics class for a control. If you need the HWND (window handle) for a control use its Handle property.
You can also create a Graphics class for a control at anytime using Control.CreateGraphics . Just be sure in that case to call Dispose on the Graphics object when you're done, otherwise it'll handle around in memory until the GC decides to clean it up.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
Is there any way possible that I can use the same hotkeys on different pages of a tab control (for example, both pages having a button that responds to Alt+S)?
The thing is that my two tab pages share some identical controls and I would like the UI to be consistent between the pages.
I tried having the same hotkeys but the results were not as expected. Im hoping that I am missing something though
Thanx,
-Flack
|
|
|
|
|
I suspect you'd have to manually switch the hotkeys in code every time the user clicks on a different tab
Either that or instead of having duplicated controls, just have a single set, and put them as children of the form, rather than children of the tab page (you'll have to manually show/hide them when the tabs change, though)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Im new to using Excel with C# and I ccant seem to get this seemingly simple task done.
What I want to do is get a range of cells from an Excel sheet and put the resulting cell values in a string array. (I know that the values are all strings).
The code I have that gets the job done is this:
<br />
string workbookPath = fileName_;<br />
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"",false,false,0,true,false,false);<br />
Excel.Sheets excelSheets = excelWorkbook.Worksheets;<br />
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(1);<br />
Excel.Range excelCells = (Excel.Range)excelWorksheet.get_Range("A1","H1");<br />
System.Object[,] result = (System.Object[,])excelCells.EntireRow.Value2;<br />
Now, this code gives me a two-dimensional array with all of the values included, along with every other null item in that row (giving me an array with a second dimension length of 256).
I tried doing:
<br />
System.String[] result = (System.String[])excelCells.Value2;<br />
because I can see that excelCells.Value2 is an array. Unfortunately, this line gives me an invalid cast exception.
Is this way the only way I can get an Excel row into an array (without going through each cell manually, getting its value, and adding it to an array)?
How about if I wanted to multiple rows, like ("A1","H7")?
Thanks,
-Flack
|
|
|
|
|
Value2 - as well as many other properties and methods - return a VARIANT or single- or multi-dimensional arrays of VARIANT s (a native struct). These marshal as object s. Casting an object to a string (BTW, use the type aliases like object and string instead of Object or String for more readable code, and don't qualify all your types; use the using Namespace; statement at the top of your source file) is possible, but casting an array of variants to a string[] array isn't valid (unless you write a custom marshaler that does it for you). You're also assuming that the cells in such a range will all marshal as strings. Depending on what type you set the type format of in Excel, it may marshal as different types of data.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Does anyone know a software that converte VB to C# code ???
|
|
|
|
|