|
It's quite simple if you know the trick, but it's rarely mentioned. It took me almost a day to find that out
You can find this information at the bottom of each type's MSDN topic.
www.troschuetz.de
|
|
|
|
|
It's no trick, that's just the way it is. Just like in C/C++ you can reference types if you don't include the headers (though that's more analogous to using in C# or import in Java), and you can't link without referencing certain libs. In Java you can't compile without having classes in your class path. In VB you can't use an object if you don't reference the typelib and have the object's class registered on the system. The list of examples go on.
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]
|
|
|
|
|
Yeah, I know it's not really a trick. Maybe this term was a bit inappropriate.
I meant that you have to know how you can reference the libraries and where you can find the information, which library has to be referenced. It's slightly different in each programming language and IDE, so you have to know "the trick" how to do it.
www.troschuetz.de
|
|
|
|
|
Why not just read the class library documentation and look at the bottom of the page that describes the class (or other type) itself? It will tell you what assembly in which the type is defined.
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 know that.
But you see, that's exactly what I meant. If you know what to do, it's so easy that you take this for granted. But if you don't know, it's not such a natural thing.
www.troschuetz.de
|
|
|
|
|
Hi,
I want to change the color and width of my panel's border.
I created a class which inherits from panel, and override the onPaint() method. In that method, I called to ControlPaint.DrawBorder().
When I debug it,I see that it enter the function and perform the ControlPaint.DrawBorder(), but I don't see any change in the color of width of the panel border.
I attached the code.
Please help..
thanks
y.
public class BorderPanel : Panel
{
private Color m_borderColor;// The color of the border
private int m_borderWidth;//the width of the border
private BorderStyle m_BorderStyle;//the border style
public BorderPanel()
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int borderWidth = 1;
Color borderColor = Color.Blue;
ControlPaint.DrawBorder(e.Graphics, new Rectangle(100, 100, 500, 100), borderColor,
borderWidth, ButtonBorderStyle.Solid, borderColor, 15,
ButtonBorderStyle.Solid, borderColor, 15, ButtonBorderStyle.Solid,
borderColor, 15, ButtonBorderStyle.Solid);
}
//Property of the border color
public Color BorderColor
{
get
{
return m_borderColor;
}
set
{
m_borderColor = value;
}
}
//Property of the border width
public int BorderWidth
{
get
{
return m_borderWidth;
}
set
{
m_borderWidth = value;
}
}
//Property of the border Style
public BorderStyle PanelBorderStyle
{
get
{
return m_BorderStyle;
}
set
{
m_BorderStyle = value;
this.BorderStyle = value;
}
}
|
|
|
|
|
Off-hand I'd say you're trying to draw the border outside the client area. Those coordinates (which, BTW, you shouldn't hard code for something that can be dynamically sized) are relative to the control's (Panel 's) upper-left corner. If you're panel is smaller, you won't see the border.
If even you use the Panel 's Bounds property, you'll still have a problem based on the direction of the path. IIRC, you'll see the top and left borders but not the right and bottom borders (because of culling). You'll need to shrink the Rectangle by the width of your pen on both the right and bottom sides.
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,
I changed the coordinates to get the bounds of the panel, but it still doesn't work.I see the border of the panel ,but with default values - always with color black and width 1 (without considering the values I gave). I'm working with .Net designers,Can this be the reason for the problem? I can't find any reason that it doesn't work.
I tried the same thing with label (that doesn't work with designer) and it worked perfect.
Thanks,
|
|
|
|
|
In order to override what the designers do - which are going to draw their own borders at design-time - you need to implement your own designer and decide what gets painted and how. Read Enhancing Design-Time Support[^] in the .NET Framework SDK - especially those topics about designers - for more information.
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
If i copy both text & image with the same selection (e.g copying some text followed by an image from a word document), can I get the data from the clipboard seperated (i.e. is there some way to recognise that certain part of the clipboard object is text & the rest of it is an image??)
Anxiuos to get the answer
Thanx!!
|
|
|
|
|
You're about to venture down a road that will require a lot of reading.
The clipboard and drag-n'-drop functionality use OLE heavily. If you copy both text and image, it really matters how they were packed into the IDataObject (the native interface, not the managed System.Windows.Forms.IDataObject interface) and if you can get it out. Since the .NET BCL doesn't expose all the types necessary for full drag-n'-drop, you're stuck with what the .NET BCL does expose (like getting RTF, text, an image (separately), and a few more things) or writing a lot of P/Invoke calls and declaring and implementing a lot of interfaces declared natively.
So, if you want the easy road, please tell me what application you copied text and image(s) from. If it was Word or WordPad or something similar, chances are that it copied multiple formats including RTF, which .NET supports (see the DataFormats class, specifically the DataFormats.Rtf field).
If you want to get data from the clipboard, use the Clipboard.GetDataObject static method.
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 am using the Windows API to get ICO from a file. I place that image in a PictureBox. I wan't to save that image to a Jpeg so I use the the PictureBox.Image.Save(strFile,ImageFormat.Jpeg) method and it does save but the background is black. I would like to control what color that background is.
Thanks,
Cyber
|
|
|
|
|
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?
|
|
|
|
|