How do I make the context menu appear only when clicked at certain portions of the Control?
You can listen to the Popup event, determine where the mouse was clicked and selectively make the menu items visible in the menu as follows: // In C# private void contextMenu1_Popup(object sender, System.EventArgs e) { // Get current mouse click position in the control (assuming pictureBox1 is the control): Point ptClick = this.pictureBox1.PointToClient(Control.MousePosition); // Get the rectangle where you want to show the context menu. Rectangle preferredClickRect = new Rectangle(0, 0, 50, 50); if(preferredClickRect.Contains(ptClick)) { // Show all the menu items so that the menu will appear foreach(MenuItem item in this.contextMenu1.MenuItems) item.Visible = true; } else { // Hide all the menu items so that the menu will not appear foreach(MenuItem item in this.contextMenu1.MenuItems) item.Visible = false; } } ’ In VB.Net Private Sub contextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) ’ Get current mouse click position in the control (assuming pictureBox1 is the control): Dim ptClick As Point = Me.pictureBox1.PointToClient(Control.MousePosition) ’ Get the rectangle where you want to show the context menu. Dim preferredClickRect As Rectangle = New Rectangle(0,0,50,50) If preferredClickRect.Contains(ptClick) Then ’ Show all the menu items so that the menu will appear Dim item As MenuItem For Each item In Me.contextMenu1.MenuItems item.Visible = True Next Else ’ Hide all the menu items so that the menu will not appear Dim item As MenuItem For Each item In Me.contextMenu1.MenuItems item.Visible = False Next End If End Sub
What are some common UI limitations while running code in the Internet Zone?
1) Cannot override methods like WndProc, ProcessCmdKey, etc in a derived Control. The class ref for a particular property will let you know about the permission requirements. 2) Cannot call Control.Parent. 3) Cannot call Control.Focus() method.
What are some common gotchas while trying to embed a Windows Forms Control in IE?
The issues listed here are pertaining to code running in IE in the default Internet Zone. 1) You cannot view Controls inside IE using the 1.0 framework (when running with the permissions in the default Internet Zone). This is however possible with the 1.1 (Everett) framework. 2) Use only one . in the assembly file name and ‘Assembly Name'(in Project Properties Dialog). For example, ‘Syncfusion.Shared.dll’ is an invalid dll name, but ‘Shared.dll’ is valid. 3) Signed assemblies couldn’t be loaded.
Why do I have to use the STAThread attribute for my main method in my app.?
While the STAThread is required (as the documentation states) and pertinent only to applications that use COM interop, 1.0 version of the .Net framework has some bugs that makes it necessary for you to specify the STAThread attribute: 1) Ole Drag Drop will not work without STA. You can check this by turning on drag and drop in a form and try to run it. 2) Invoking a method in a type using Reflection will not work either. These bugs have however been resolved in the 1.1 version of the framework (Everett). Which means you then do not have to specify this attribute for your main method.
How can I use a WinForms Control in IE?
You cannot use a WinForms Control directly in IE, you will have to instead derive from it and then use the derived instance from a custom assembly.