Currently I am using an application which play ppt and flash in WebBrowser Control.
In WebBrowser I am able to hide context menu by using
this.IsWebBrowserContextMenuEnabled = false;
and capture key event by using
this.PreviewKeyDown += new PreviewKeyDownEventHandler(IWebBrowser_PreviewKeyDown);
but while playing the ppt, both context menu and keypress events are not functioning i.e. I can see context menu and arrow key force the ppt to change the slide.
Again while playing flash, context menu is visible and I can handle key event. is there any other setting to it can same for whatever (HTML, PPT, Flash, PDF) is playing in webBrowser?
Edit :1
Here is my existing code
class IWebBrowser : WebBrowser
public IWebBrowser(RegionOptions options)
{
try
{
this.Width = 600;
this.Height = 400;
this.IsWebBrowserContextMenuEnabled = false;
this.ScrollBarsEnabled = false;
this.ScriptErrorsSuppressed = true;
this.WebBrowserShortcutsEnabled = false;
this.AllowNavigation = true;
CreateContextMenu();
this.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(IWebBrowser_DocumentCompleted);
this.PreviewKeyDown += new PreviewKeyDownEventHandler(IWebBrowser_PreviewKeyDown);
}
catch (Exception ex)
{
log.Error("IWebBrowser - ctor ", ex);
}
}
private void CreateContextMenu()
{
ContextMenuStrip myContextMenu = new ContextMenuStrip();
this.ContextMenuStrip = myContextMenu;
ToolStripMenuItem myFirstTooltip = new ToolStripMenuItem();
ToolStripMenuItem mySecondTooltip = new ToolStripMenuItem();
ToolStripMenuItem myThirdTooltip = new ToolStripMenuItem();
myFirstTooltip.Text = "Item One";
mySecondTooltip.Text = "Item Two";
myThirdTooltip.Text = "Item Three";
myContextMenu.Items.Add(myFirstTooltip);
myContextMenu.Items.Add(mySecondTooltip);
myContextMenu.Items.Add(myThirdTooltip);
}
context menu Images for different controls played in webbrowser
Display a webpage..................
flash played in webbrowser.................
ppt played in webbrowser.....................
Follow these steps to get rid of the default context menu
Do what you've done to hide default context menu
this.IsWebBrowserContextMenuEnabled = false;
Add a ContextMenuStrip control to your window and give a name (let's say MyMenu)
Set your browser control's ContextMenuStrip property to MyMenu
Now, whatever the document type you display on your Browser control it'll only display your custom menu.
Hope this helped!
All the best
Override all the mouse event flags Here is an example I hope this example will help you
You've to catch the PreviewKeyDown event in your WebControl where is playing your ppt/flash and rise it to the content page or whatever.
You can check how:
define Custom Event for WebControl in asp.net
Related
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
create custom tooltip C#
Does anyone know of a way to make a box 'popup' when the user cursors over a certain item?
For example, I want to have a PictureBox on a C# forms application and when the user cursors over it, a box of text will pop up.
I'm aware of ToolTip however I was thinking of something more customisable; in my mind I'm thinking of the kind of popup boxes you see in World of WarCraft when you cursor over an item in your inventory (obviously it doesn't have to be THAT flashy, but at least one where the text colour, background colour, text etc. are all modifiable).
You can use a ToolStripControlHost to host a control (for instance a panel) and add the content you want. Then you add that control to a ToolStripDropDown using the Items collection, and use the Show(Control,Point) method to show the control.
Thought I'd add an example
public class Form1 {
public Form1() {
ToolStripDropDown customToolTip = new ToolStripDropDown();
customToolTip.Items.Add(new CustomPopupControl("Hello", "world"));
MouseMove += (o, e) => {
Point location = e.Location;
location.Offset(0, 16);
customToolTip.Show(this, location);
};
}
class CustomPopupControl : ToolStripControlHost {
public CustomPopupControl(string title, string message)
: base(new Panel()) {
Label titleLabel = new Label();
titleLabel.BackColor = SystemColors.Control;
titleLabel.Text = title;
titleLabel.Dock = DockStyle.Top;
Label messageLabel = new Label();
messageLabel.BackColor = SystemColors.ControlLightLight;
messageLabel.Text = message;
messageLabel.Dock = DockStyle.Fill;
Control.MinimumSize = new Size(90, 64);
Control.Controls.Add(messageLabel);
Control.Controls.Add(titleLabel);
}
}
}
I mean if it a button or an image button you can add something like MouseHover action and then show your message
private void button1_MouseHover(object sender, System.EventArgs e)
{
MessageBox.Show("yourmessage");
}
you need to customize the tooltip. refer to
http://www.codeproject.com/Articles/98967/A-ToolTip-with-Title-Multiline-Contents-and-Image
There are some other articles there, but this one works fine for me.
You may need to add code for your requirement.
I'm trying to create a DevEx drop down button. Unfortunately, I'm running into two problems I can't figure out:
1) I can't get the popup menu to skin correctly, i.e. it doesn't skin as "Office 2010 Blue". The code I'm using is shown below:
private void InitializeSendToPricingSheetButton()
{
var barManager = new BarManager();
if (barManager.Controller == null) barManager.Controller = new BarAndDockingController();
barManager.Controller.PaintStyleName = "Skin";
barManager.Controller.LookAndFeel.UseDefaultLookAndFeel = false;
barManager.Controller.LookAndFeel.SkinName = "Office 2010 Blue";
barManager.ItemClick += HandleSendToPricingSheetClick;
barManager.Items.AddRange(new[] { new BarButtonItem(barManager, "Foo"), new BarButtonItem(barManager, "Bar"), new BarButtonItem(barManager, "Baz") });
var popupMenu = new PopupMenu { Manager = barManager };
foreach (var barItem in barManager.Items) popupMenu.ItemLinks.Add((BarItem)barItem);
popupMenu.ItemLinks[1].BeginGroup = true;
dropDownButtonSendToPricingSheet.DropDownControl = popupMenu;
}
2) This button is on a form. If the form loses focus (e.g. I click on Firefox), the pop-up menu still remains on-top. It won't go away until clicked.
Any suggestions would be much appreciated. Thanks for helping me deal with DevEx insanity.
I have solution to your second question.
You should add drop down button event handler as below:
dropDownButton1.LostFocus += new EventHandler(HidePopUp);
Handler method should be as below:
private void HidePopUp(object sender,object e)
{
dropDownButton1.HideDropDown();
}
For your second question, you should assign value to the bar manager property as:
BarManager manager = new BarManager();
manager.Form = this; // refers to current form
Find below link for reference
https://www.devexpress.com/Support/Center/Question/Details/Q274641
It is probably simpler to use DefaultLookAndFeel
Add this comp to your form and set the theme you'd like to use.
There is no need to set the theme for individual components.
defaultLookAndFeel1.LookAndFeel.SetSkinStyle("Office 2010 Blue");
I am trying to add an activeX control in an user control in a C# windows form based project.
Now if I add that activeX component from the tools menu then by simply using drag and drop I am able use the activeX control.
But when I try to add that one at run time using C# code then it throw following exception:
"Exception of Type
'System.Windows.Forms.AxHost=InvalidActiveXStateException' was
thrown".
Using CreateControl() I am able to get rid of this exception but now the activeX control does not appear on the form.
When are you adding the control and where are you adding it on the form?
You would normally load the control in the constructor just after the component is initialized:
public FormRecalculation()
{
InitializeComponent();
loadDataSelector();
}
If there are any associated license keys you will need to set them and add them to the appropriate container on the form:
private void loadDataSelector()
{
//Initialize the DataSelector
DataSelector = new AXQDataSelector(getClsidFromProgId("QDataSelLib.QDataSel"));
if (DataSelector != null)
{
System.Reflection.FieldInfo f =
typeof(AxHost).GetField("licenseKey",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
f.SetValue(DataSelector, "license-here");
splitContainer1.Panel2.Controls.Add(DataSelector);
((System.ComponentModel.ISupportInitialize)(DataSelector)).BeginInit();
this.DataSelector.Dock = System.Windows.Forms.DockStyle.Fill;
this.DataSelector.Enabled = true;
this.DataSelector.Location = new System.Drawing.Point(0, 0);
this.DataSelector.Name = "DataSelector";
this.DataSelector.Size = new System.Drawing.Size(324, 773);
this.DataSelector.TabIndex = 0;
splitContainer1.Panel2.ResumeLayout();
((System.ComponentModel.ISupportInitialize)(DataSelector)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
else
{
return;
}
}
This is actually for a wrapped OCX but you get the idea...
ok, after some changes the code looks like this. Here at runtime four tabs are created. Initially, on first tab the control is displayed. When user clicks on other tabs page activex control added on those pages dynamically. (This code is written for a .net usercontrol. On run time this usercontrol is added to the form)
private void Populate()
{
int position;
int i = 0;
//here children in list of string type
foreach (string child in children)
{
this.productLineTabs.TabPages.Add(child);
AxSftTree treeadd = loadtree(this.productLineTabs.TabPages[i]);
this.tree.Add(treeadd);
this.tree[i].Columns = 2;
this.tree[i].set_ColumnText(0, "Col1");
this.tree[i].set_ColumnText(1, "Col2");
position = this.tree[i].AddItem(child);
i++;
}
form plv = new form();
plv.Controls.Add(this);
plv.Show();
}
private AxSftTree loadtree(TabPage tab)
{
AxSftTree treeobject = new AxSftTree();
((System.ComponentModel.ISupportInitialize)(treeobject)).BeginInit();
SuspendLayout();
tab.Controls.Add(treeobject);
treeobject.Dock = DockStyle.Fill;
ResumeLayout();
((System.ComponentModel.ISupportInitialize)(treeobject)).EndInit();
return treeobject;
}
You can find some details about this implementation on this page:
http://newapputil.blogspot.in/2013/11/how-to-add-activex-control-at-run-time.html
I have a form done in WPF which has a custom control already on it called RateView. This custom control has 4 textboxes (which are all working as they should be). It also contains a button.
I have a second custom control called Extended Margin Info, which also has a XAML Form which will just show output data only.
How can I by clicking the button on the custom control called Rateview bring up the XAML canvas onto my Main window of the extendedmargin info XAML, in the same position everytime? Rateview control exists 5 times on the main window therfore there will be 5 buttons that when clicked, will need to output the popup of ExtendedMargin Info to the main screen in the same position each time with the content of extendedmargin info.
Your button, when clicked, should call a Command which updates a Property of some ViewModel that exposes the ViewModel of the current ExtendedMarginInfo you want to display. Then you can bind this property to the Content Property of a ContentControl in the target view. You can select the View you want the Control to display by using the ContentControl.ContentTemplateSelector property.
I guess you want show one popup and change it's content placing in it different controls.
At 1st create your custom control:
balloon = new LogEntryInfoBalloon();
balloon.SetMainWindow(this);
balloon.DataContext = vm.NotificationViewModel;
Then create Popup control (System.Windows.Controls.Primitives):
localPop = new Popup();
localPop.AllowsTransparency = true;
localPop.Placement = PlacementMode.AbsolutePoint;
localPop.StaysOpen = true;
localPop.PlacementTarget = this;
localPop.Child = balloon;
Placement target points to MainWindow.
Define timer that will close(hide) balloon:
localPopTimer = new Timer(new TimerCallback(CloseLocalPopup));
Close func:
private void CloseLocalPopup(object args)
{
var act = new Action(() =>
{
localPop.IsOpen = false;
});
Dispatcher.BeginInvoke(act, null);
}
Show balloon code looks like this:
private void ShowNotifyBaloon(NotifyBaloonViewModel vm)
{
var act = new Action(() =>
{
localPop.IsOpen = true;
localPopTimer.Change(4000, Timeout.Infinite);
});
Dispatcher.BeginInvoke(act, null);
}
I would like to display a ToolTip for when the mouse is hovering over a control.
How does one create a tooltip in code, but also in the designer?
Here is your article for doing it with code
private void Form1_Load(object sender, System.EventArgs e)
{
// Create the ToolTip and associate with the Form container.
ToolTip toolTip1 = new ToolTip();
// Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(this.button1, "My button1");
toolTip1.SetToolTip(this.checkBox1, "My checkBox1");
}
Drag a tooltip control from the toolbox onto your form. You don't really need to give it any properties other than a name. Then, in the properties of the control you wish to have a tooltip on, look for a new property with the name of the tooltip control you just added. It will by default give you a tooltip when the cursor hovers the control.
Add a ToolTip component to your form
Select one of the controls that you want a tool tip for
Open the property grid (F4), in the list you will find a property called "ToolTip on toolTip1" (or something similar). Set the desired tooltip text on that property.
Repeat 2-3 for the other controls
Done.
The trick here is that the ToolTip control is an extender control, which means that it will extend the set of properties for other controls on the form. Behind the scenes this is achieved by generating code like in Svetlozar's answer. There are other controls working in the same manner (such as the HelpProvider).
ToolTip in C# is very easy to add to almost all UI controls. You don't need to add any MouseHover event for this.
This is how to do it-
Add a ToolTip object to your form. One object is enough for the entire form.
ToolTip toolTip = new ToolTip();
Add the control to the tooltip with the desired text.
toolTip.SetToolTip(Button1,"Click here");
I did it this way: Just add the event to any control, set the control's tag, and add a conditional to handle the tooltip for the appropriate control/tag.
private void Info_MouseHover(object sender, EventArgs e)
{
Control senderObject = sender as Control;
string hoveredControl = senderObject.Tag.ToString();
// only instantiate a tooltip if the control's tag contains data
if (hoveredControl != "")
{
ToolTip info = new ToolTip
{
AutomaticDelay = 500
};
string tooltipMessage = string.Empty;
// add all conditionals here to modify message based on the tag
// of the hovered control
if (hoveredControl == "save button")
{
tooltipMessage = "This button will save stuff.";
}
info.SetToolTip(senderObject, tooltipMessage);
}
}
Just subscribe to the control's ToolTipTextNeeded event, and return e.TooltipText, much simpler.