|
I don't know how your PopMenu is initialized and attached but what I know is that .NET context menus are automatically shown on right-clicks, and they have to be preably attached to the control with the .ContextMenu property. You never call Show(), or you expose yourself to such things.
Using Show() directly is a hack. The executed code is as follows :
public void Show(Control control, Point pos) {
object[] local0;
if (control == null) {
local0 = new Object[2];
local0[0] = "control";
local0[1] = "null";
throw new ArgumentException(SR.GetString("InvalidArgument", local0));
}
if (!(control.IsHandleCreated) || !(control.Visible))
throw new ArgumentException(SR.GetString("ContextMenuInvalidParent"), "control");
this.sourceControl = control;
this.OnPopup(EventArgs.Empty);
pos = control.PointToScreen(pos);
SafeNativeMethods.TrackPopupMenuEx(this.Handle, 64, pos.X, pos.Y, control.Handle, null);
}
Make sure the associated control .Visible property is set to true. When the code reaches TrackPopupMenuEx, it relies on standard WIN32 menus, and at this point you are sure the context menu displays well.
|
|
|
|
|
Thanks Rod,
The problem I've found out is to do with my subclassing, even using the method you suggested it bombs, but I have now found out that it's a windows message thats bombing it thanks to your advice
|
|
|
|
|
It's WM_CONTEXTMENU that is causing the app to bomb.
When the message is passed down the chain (MyBase.WndProc(message)) it bombs with the not visible error.
I can't find TrackPopupMenuEx in the net framework, do you know where I'd find it?
|
|
|
|
|
LeeDaviesVBSource wrote:
I can't find TrackPopupMenuEx in the net framework, do you know where I'd find it?
That's not TrackPopupMenuEx(...), that's SafeNativeMethods.TrackPopupMenuEx(...), where SafeNativeMethods is a namespace of WIN32 imported functions defined like this :
[DllImport("user32.dll")]
public extern static bool TrackPopupMenuEx(IntPtr hmenu,
int fuFlags,
int x, int y,
IntPtr hwnd,
TPMPARAMS tpm);
which at run-time is interoped to a native WIN32 ::TrackPopupMenuEx(HMENU hmenu, UINT fuFlags, int x, int y, HWND hWnd, LPTPMPARAMS tpm) call.
This method call is proven. What could be wrong at this point is the hmenu (invalid or NULL), or a NULL owning window handle (hWnd). The last parameter can be NULL.
|
|
|
|
|
I have found the problem, not solved it, but found it
It's the subclassing routine I'm using. For some reason the controls are changing their handles. I got the code off here so I'll go bug the AngryCoder and see if he can help!
Thanks
|
|
|
|
|
Is there a way to make a fullscreen form (real not fake) with .NET means (fullscreen like the one in MS Word)?
If there is no pure .NET way how can it be done at all?
|
|
|
|
|
I've got a problem with the XmlSerializer - i can't seem to serialiaze custom types. The XmlSerializer works fine with any BCL type, but my custom types throw this error:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll<br />
<br />
Additional information: There was an error reflecting 'ComponentTestConsole.CustomType'.
I wonder if it's a security thing (even though it's not a security exception), since this is the first project i've created on a network drive and it did warn me when i started the project yesterday. So as a second question, what do i need to do to let .NET know that my network shares are safe as houses?
Thanks in advance,
Paul
|
|
|
|
|
Have you implemented the serializable interface in your classes?
|
|
|
|
|
Hi Lee,
I was just about to post to say i've fixed it. I hadn't looked in the InnerException member of the thrown exception - i'd stupidly not made my custom type public (doh!).
You don't need to implement the serializable interface to use the XmlSerializer - it uses reflection to inspect the type and serialize any publicly accessible members.
Cheers,
Paul
|
|
|
|
|
I beleive that the xml serializer requires the class to have a public parameter-less constructor. Does yours have one?
|
|
|
|
|
Thanks, but i've fixed it now.
see post above.
|
|
|
|
|
I know I can get a string as a char[], but I need to build a string and get it as a byte[]. Can it be done ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
In the System.Text namespace, there are a bunch of classes ending with Encoding. They have a method called GetBytes with a bunch of overloads. So in the case of Unicode text, you would use:
byte[] string2byte = System.Text.UnicodeEncoding.GetBytes("This is a string");
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
Why do you need it as a byte[]?
|
|
|
|
|
I didn't in the end. I am using a StringBuilder to build a report from a DataSet, which I then want the browser to save to the users HDD. The code I was basing it on streamed all sorts of things and so used Response.BinaryWrite. I only need Response.Write, as it is always a string ( obviously ). It all works now, with the exception that it insists on ignoring the directive to set the filename, instead saving my test with the name of my aspx.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Great! So my hard work was for nothing?
[edit]Actually, I have noticed that Response.Write doesn't pay attention to the filename, which is a real shame, cause then the user isn't able to open it automatically. I have seen it several times, but still have no idea how to fix it. /edit]
Hey, what can I say? I'm a chick magnet...a babe conductor...a logarithm for the ladies.
-Strong Bad from HomeStarRunner.com
Essential Tips for Web Developers
|
|
|
|
|
David Stone wrote:
Great! So my hard work was for nothing?
No, I was really pleased to know the answer, and filed it away for future reference.
Current thought has it that my IIS is stuffed, because the same code works on other peoples machines.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
I create a new control inherited from TextBox, all the TextBox's property are inherited. but I don't want some property, e.g. BorderStyle, BackColor... How do I do it?
linjie
|
|
|
|
|
I don't think it's possible to get rid of these properties but you can do a fairly effective job of hiding them with
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)] .
Paul
Pleasently caving in, I come undone - Queens of the Stone Age, No One Knows
|
|
|
|
|
I need some reassurance that I'm not blind...
Is there no "Dictionary" class in the System.Collections namespace, but rather only the DictionaryBase class that requires you to code your own derrived class?
Mike Stanbrook
mstanbrook@yahoo.com
|
|
|
|
|
You can use a hashtable like a you would an arraylist, or one of these:
HybridDictionary Implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.
ListDictionary Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.
PropertyCollection Contains the properties of a DirectoryEntry.
PropertyDescriptorCollection Represents a collection of PropertyDescriptor objects.
SortedList Represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index.
Eish I must get sleep You would swear South Afican time was GMT - 6
WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.
|
|
|
|
|
look in System.Collections.Specialized
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Developing a network file backup application and need to
be able to see all machines on a network, select
drives/dirs/files for backup.... currently, I have an app
similar to Windows Explorer, with a treeview to look at
my own computer's data, with no problems... need to
add "My Network Places" to this (similar to Windows Explorer)
and be able to go out on
the network and get similar info for other
workstations.. plus I need to be able to create folders
and copy files to these PCs... I think I'm kinda close
with System.DirectoryServices and System.Management, but
can't seem to find what I'm looking for... any help or
suggestions would be much appreciated... thank you.
|
|
|
|
|
Has anybody written a reflection routine that can clone a control? For Copy & Paste of a control...
And before anybody mentions it again, Yes I am programming in VB.Net, but you guys know more system level stuff. Answers accepted in c#
|
|
|
|