Allow user to zoom with mousewheel using the cefsharp browser - cefsharp

I am running cefsharp/75. I want to turn on zooming with the ctrl key and the mousewheel. My event handler is never triggered. And if you hold ctrl and use the mouse will the screen doesn't move. So something inside the control and handling the event. Is there just a setting I am missing?

I added mouse and keyboard zoom. In init section subscribe for events
cefBrowser.PreviewMouseWheel += CefBrowser_PreviewMouseWheel;
cefBrowser.KeyUp += CefBrowser_KeyUp;
I used PreviewMouseWheel to avoid scrolling during zoom (e.Handled = true).
private void CefBrowser_PreviewMouseWheel(object sender, MouseWheelEventArgs e) {
if (Keyboard.Modifiers != ModifierKeys.Control)
return;
if (e.Delta > 0)
cefBrowser.ZoomInCommand.Execute(null);
else
cefBrowser.ZoomOutCommand.Execute(null);
e.Handled = true;
}
private void CefBrowser_KeyUp(object sender, KeyEventArgs e) {
if (Keyboard.Modifiers != ModifierKeys.Control)
return;
if (e.Key == Key.Add)
cefBrowser.ZoomInCommand.Execute(null);
if (e.Key == Key.Subtract)
cefBrowser.ZoomOutCommand.Execute(null);
if (e.Key == Key.NumPad0)
cefBrowser.ZoomLevel = 0;
}
So now cef zooming almost like chrome

Related

changing mouse cursor in chromiumwebbrowser DragEnter event in WPF

we are using chromiumwebbrowser in WPf application, added DragEnter event handler to the chromiumwebbrowser and call come to us.
wanted to change the cursor,
private void Browser_DragEnter(object sender, DragEventArgs e)
{
var currCursor = Browser.Cursor;
if (e.Effects == DragDropEffects.Move)
{
//Mouse.OverrideCursor = Cursors.Hand;
// Mouse.SetCursor(Cursors.Hand);
Debug.Write("DragDropEffects.Move\n");
}
else
Mouse.SetCursor(Cursors.Hand);
Mouse.OverrideCursor = Cursors.Pen;
Browser.Cursor = Cursors.Pen;
//Mouse.Capture(Browse);
e.Handled = true;
}
nothing works, could some help would solve this issue

How to make Xamarin.Forms.Editor scrollable/auto resizable?

I have an scrollabe layout with an Editor inside that I'd like to make scrollable or auto resizable to fit the contents.
I can't find how to do it.
I tried a custom renderer but I can't find how to set InputMethods to the Control.
Any ideas?
With the help of this post: https://forums.xamarin.com/discussion/80360/editor-inside-scrollview-not-scrolling
That fixed the scrolling on Android (iOS works by default). It avoids the parent scroll event when touching inside the Editor, triggering only the Editor scroll.
First a class on Android project:
using Android.Views;
namespace MyApp.Droid
{
public class DroidTouchListener : Java.Lang.Object, View.IOnTouchListener
{
public bool OnTouch(View v, MotionEvent e)
{
v.Parent?.RequestDisallowInterceptTouchEvent(true);
if ((e.Action & MotionEventActions.Up) != 0 && (e.ActionMasked & MotionEventActions.Up) != 0)
{
v.Parent?.RequestDisallowInterceptTouchEvent(false);
}
return false;
}
}
}
And then use it on the Android Custom EditorRenderer:
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
var nativeEditText = (global::Android.Widget.EditText)Control;
//While scrolling inside Editor stop scrolling parent view.
nativeEditText.OverScrollMode = OverScrollMode.Always;
nativeEditText.ScrollBarStyle = ScrollbarStyles.InsideInset;
nativeEditText.SetOnTouchListener(new DroidTouchListener());
//For Scrolling in Editor innner area
Control.VerticalScrollBarEnabled = true;
Control.MovementMethod = ScrollingMovementMethod.Instance;
Control.ScrollBarStyle = Android.Views.ScrollbarStyles.InsideInset;
//Force scrollbars to be displayed
Android.Content.Res.TypedArray a = Control.Context.Theme.ObtainStyledAttributes(new int[0]);
InitializeScrollbars(a);
a.Recycle();
}
}

How to disable back button When ActivityIndicator Is Running

I am using Xamrin.forms PLC Project,
So,I am trying to disable back button when Activity Indicator is Running then I will enable back button when Activity Indicator is finished.
this is My Code:
protected override void OnAppearing()
{
activityIndicator.IsRunning = true;
activityIndicator.IsVisible = true;
//I need to disable back button here
activityIndicator.IsRunning = false;
activityIndicator.IsVisible = false;
//I need to enable back button here
}
You can use the static NavigationPage.SetHasBackButton method (See here) to hide the back button of your page.
Furthermore you can override OnBackButtonPressed
protected override bool OnBackButtonPressed()
{
if(activityIndicator.IsRunning = true)
{
return true;
}
return false;
}
(see here) to prevent going back when the user presses the hardware back button.

Why is OnPreRender being called over and over again?

In my Sharepoint 2010 WebPart, I have this code:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (this.dpsvisWebPart != null && this.dpsvisWebPart.CustomTitleProp != null)
{
lbl_Title.Text = String.Format("<h1>{0}</h1>", this.dpsvisWebPart.CustomTitleProp.ToString());
if (this.dpsvisWebPart.CheckboxGenSection1)
{
GenerateSection1();
}
if (this.dpsvisWebPart.CheckboxGenSection2)
{
GenerateSection2();
}
if (this.dpsvisWebPart.CheckboxGenSection3)
{
GenerateSection3();
}
if (this.dpsvisWebPart.CheckboxGenSection4)
{
GenerateSection4();
}
if (this.dpsvisWebPart.CheckboxGenSection5)
{
GenerateSection5();
}
if (this.dpsvisWebPart.CheckboxGenSection6)
{
GenerateSection6();
}
if (this.dpsvisWebPart.CheckboxGenSection7)
{
GenerateSection7();
}
if (AnyCheckboxSelected())
{
// Create Save button
this.Controls.Add(new LiteralControl("<br />"));
Button btnSave = new Button();
btnSave.Text = "Save";
btnSave.Click += new EventHandler(btnSave_Click);
this.Controls.Add(btnSave);
AddVerticalSpace();
}
}
}
On testing my WebPart (clicking the button, thus - presumably - executing the btnSave_Click handler, I found that nothing was being saved.
Stepping through the code, I see that OnPreRender is being reached - in fact, over and over again.
So, I added this to the WebPart class:
private bool PreRenderAlreadyRun = false;
...and then changed the beginning of OnPreRender() to this:
protected override void OnPreRender(EventArgs e)
{
if (PreRenderAlreadyRun) return;
PreRenderAlreadyRun = true;
base.OnPreRender(e);
. . .
...but PreRenderAlreadyRun is always false when OnPreRender is entered, which happens over and over. Other breakpoints are not reached (the button click, etc.) presumably because the page is in an endless loop.
How can I get OnPreRender() to run only once? Or should this code be in Page_Load() instead of OnPreRender(), or...???
The solution was to move the code that was in OnPreRender() to Page_Load()
Apparently, just like at the stockyard, rendering happens many times, while the page is only loaded once. That's my theory, and I'm stickin' to it (for now, anyway).

Enable Opposite

Why won't this work?
void RatingWidget::mouseDoubleClickEvent(QMouseEvent * e)
{
this->setEnabled(!this->Enabled);
}
// I also tried...
void RatingWidget::mouseDoubleClickEvent(QMouseEvent * e)
{
if(this->isEnabled())
this->setEnabled(false);
else
this->setEnabled true;
}
It works the first time, but after that it remains disabled.
To quote the documentation..
An enabled widget handles keyboard and mouse events; a disabled widget
does not.
So once you disable it, you aren't going to get any more mouse events :)

Resources