I am trying to make a fully-featured web browser in C# using the chromium embedded framework also known as CefSharp. For the tab control, I am using EasyTabs.
I want to have a custom context menu strip that has a "Open link in new tab" menu item.
This is what I have tried, but nothing happens when you run the application and click Open link in new tab.
I'd appreciate any help I can get.
if (commandId == (CefMenuCommand)OpenLinkInNewTab )
{
ResistBrowser.frmMain form;
ResistBrowser.AppContainer appcontainer1;
appcontainer1 = new ResistBrowser.AppContainer();
form = new ResistBrowser.frmMain();
browserControl.Load(parameters.SelectionText);
appcontainer1.Tabs.Add(
// Our First Tab created by default in the Application will have as content the Form1
new TitleBarTab(appcontainer1)
{
Content = new ResistBrowser.frmMain
{
Text = form.Text
}
}
);
}
Related
My scenario is, I have a Tabbed page in Xamarin Forms:
public partial class MainPage : TabbedPage
{
public MainPage()
{
InitializeComponent();
var playPage = new NavigationPage(new PlayPage())
{
Title = "Play",
Icon = "play.png"
};
var settingsPage = new NavigationPage(new SettingsPage())
{
Title = "Settings",
Icon = "settings.png"
};
var favoritesPage = new NavigationPage(new FavoritesPage())
{
Title = "Favorites",
Icon = "fave.png"
};
var aboutPage = new NavigationPage(new AboutPage())
{
Title = "About",
Icon = "info.png"
};
Children.Add(playPage);
Children.Add(favoritesPage);
Children.Add(settingsPage);
Children.Add(aboutPage);
}
}
I want to add a pause and play function to my app. On start up, the PlayPage would initially have the play.png icon and when I click on the PlayPage again it would change the icon to pause.png. Page is not changing just the page icon. Anyone has any idea how this could be done?
Edit:
So I have created a custom renderer, in OnElementChanged I utilize the ViewControllerSelected:
var tabbarController = (UITabBarController)this.ViewController;
if (null != tabbarController)
{
tabbarController.ViewControllerSelected += OnTabBarReselected;
}
And my OnTabBarReselected I have:
private void OnTabBarReselected(object sender, UITabBarSelectionEventArgs e)
{
switch (TabBar.SelectedItem.Title)
{
case "Play":
TabBar.SelectedItem.Title = "Pause";
TabBar.SelectedItem.Image = UIImage.FromFile("pause.png");
break;
}
}
This only does half of the work. It changes the Title of the selected tab bar from Play to Pause after I click on the same tab but not the Icon. The icon remains "play.png" until I get out of that tab page (selecting another tab). Anyone has any idea why?
You will need to implement a custom renderer to pull this off. There are some implementations on James Montemagno's blog where he talks about changing the icons.
iOS:
http://motzcod.es/post/138225183932/tintcolor-selectedimage-xamarin-forms-ios
Droid:
http://motzcod.es/post/157544468267/xamarin-forms-android-selected-and-unselected-tab-colors
This is however not necessarily related to your requirement of tapping the icon and changing that specific icon since all this code only runs when the page initially loads. It could be a nice starting point though. Check in there if there's a property on TabbedPage that changes when you tap on the current tab and change the icon at that point.
You also have a OnCurrentPageChanged event you can override in TabbedPage, but that isn't called when the page is already active.
How to enable toolbar in new popup window where the toolbar is disabled.
I mean if the window is created using window.open("","toolbar=no") then that window don't have toolbar enabled.I want to enable toolbar in that.Is there any way to programmatically/manually achieve that
this would do the trick.But I dont know why this code dint show up in any forum.
It is so simple all you have to do is find all the InternetExplorer instance and set the Toolbar flag to true
internal static void enableToolbar()
{
ShellWindows shellWindows = new ShellWindows();
foreach (InternetExplorer ie in shellWindows)
{
String filename = ie.Name;
if (filename.Contains("Internet Explorer"))
{
ie.ToolBar = 1;
}
}
}
I want to ask what should i do to open form with the help or class name in winform c#?
I have three different forms
UserManagement
GroupsManagement
LocationManagement
I get permission from database for these three forms
in menu click i fill tag Property with the name of form like this
tsmMain.Tag = item.PermissionName
tsmMain.Click += new EventHandler(tsmMain_Click);
what i want to do is to open form dynamically in button click and to remove these if condition?
Can i do this with reflection or else??
ToolStripMenuItem aa = sender as ToolStripMenuItem;
var tag = aa.Tag;
if (tag == "User Management")
{
UserManagement oUserForm = new UserManagement();
oUserForm.Show();
}
if (tag == "Groups Management")
{
GroupManagement oGroupForm = new GroupManagement();
oGroupForm.Show();
}
You may be able to do something like this, using the name of your form, as a string argument:
var form = (Form)Activator.CreateInstance(Type.GetType("YourNameSpace.UserManagement"));
form.Show();
One straightforward, but not necessarily very clean solution would be to store the forms right there in the Tag property of your menu items, rather than the strings.
Somewhere at the beginning of your application, you'd have to assign these instances:
myUserManagementItem.Tag = new UserManagement();
myGroupsManagementItem.Tag = new GroupManagement();
Then, in the click event, you could shorten your code to:
ToolStripMenuItem aa = sender as ToolStripMenuItem;
Form form = aa.Tag as Form;
form.Show();
Cleaner solutions would include the following:
Provide separate event handlers for different menu items.
Derive your own menu item types that store the form to show in a strongly-typed property.
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");
When I click on a link in my test, it opens a new tab.
I want ChromeDriver to then focus on that tab. I have tried the following code to get ChromeDriver to change tabas using the ctrl+tab shortcut:
Actions builder = new Actions(driver);
builder.KeyDown(Keys.Control).KeyDown(Keys.Tab).KeyUp(Keys.Tab).KeyUp(Keys.Control);//switch tabs
IAction switchTabs = builder.Build();
switchTabs.Perform();
But this throws the following exception:
ekmLiveChat.tests.UITests.EndToEndTest.EndToEnd:
System.ArgumentException : key must be a modifier key (Keys.Shift, Keys.Control, or Keys.Alt)
Parameter name: key
Is there a way to switch tabs using ChromeDriver?
This is what worked for me:
var popup = driver.WindowHandles[1]; // handler for the new tab
Assert.IsTrue(!string.IsNullOrEmpty(popup)); // tab was opened
Assert.AreEqual(driver.SwitchTo().Window(popup).Url, "http://blah"); // url is OK
driver.SwitchTo().Window(driver.WindowHandles[1]).Close(); // close the tab
driver.SwitchTo().Window(driver.WindowHandles[0]); // get back to the main window
As mentioned in my comment on your post, I'm not sure if the Chrome driver handles tabs the same way as it handles windows.
This code works in Firefox when opening new windows, so hopefully it works in your case as well:
public void SwitchToWindow(Expression<Func<IWebDriver, bool>> predicateExp)
{
var predicate = predicateExp.Compile();
foreach (var handle in driver.WindowHandles)
{
driver.SwitchTo().Window(handle);
if (predicate(driver))
{
return;
}
}
throw new ArgumentException(string.Format("Unable to find window with condition: '{0}'", predicateExp.Body));
}
SwitchToWindow(driver => driver.Title == "Title of your new tab");
(I hope my edits to the code for this answer didn't introduce any errors...)
Just make sure you don't start looking for the new tab before Chrome has had the chance to open it :)
On my code I click a button and opens a tab (so it is already on the new tab, I don't need to do something to go to that new tab) and run this so it recognize the new tab and worked:
driver.SwitchTo().Window(driver.WindowHandles.Last());
After a long fight with this I was able to get this working with chrome driver. The alert message is not visible but brings tab to front and accept closes it immediately.
//Rotate Tabs
seleniumDriver.SwitchTo().Window(seleniumDriver.WindowHandles[currentUrlIndex]);
IJavaScriptExecutor jscript = seleniumDriver as IJavaScriptExecutor;
jscript.ExecuteScript("alert('Focus')");
seleniumDriver.SwitchTo().Alert().Accept();
In C# I used the below lines to switch between the two tab.
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.open();");
IList<string> tabs = new List<string>(driver.WindowHandles);
driver.SwitchTo().Window(tabs[1]);
driver.Navigate().GoToUrl("http://www.google.com");