changing mouse cursor in chromiumwebbrowser DragEnter event in WPF - cefsharp

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

Related

Draggable windows forms bar

I am making a windows forms app just to test out my designing skills, but I find that the outline is ugly, so I made my own Minimise and Close buttons, but I'm not sure how to make a pannel that you can drag around. Can anyone help me?
By the way, the code is C#.
Using events we can take the current location when we leftclick (MouseDown) and on MouseMove, we take the current window location minus where we were before and add the distance we've dragged our mouse.
public partial class Form1 : Form
{
private Point windowLocation;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
this.windowLocation = e.Location;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Refers to the Form location (or whatever you trigger the event on)
this.Location = new Point(
(this.Location.X - windowLocation.X) + e.X,
(this.Location.Y - windowLocation.Y) + e.Y
);
this.Update();
}
}
}

Allow user to zoom with mousewheel using the cefsharp browser

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

How to get UIButton from a Xamarin.Froms.Button?

I'm using Xamarin.Forms mixed with some native Xamarin code. Now I'd like to get a UIButton instance from a Xamarin.Forms.Button. How can I do that?
In the Clicked event handler, I can see
void Share_Clicked(object sender, System.EventArgs e)
{
var button = sender as Xamarin.Forms.Button;
if(button.EffectControlProvider != null)
{
}
}
I can see EffectControlProvider.Controller is actually of UIButton type but I can't convert to it.
Is there any funciton like ToNative to get the UIButton?
Refer to Referring to Native Views from Code.
#if __IOS__
var wrapper = (Xamarin.Forms.Platform.iOS.NativeViewWrapper)contentViewButtonParent.Content;
var button = (UIKit.UIButton)wrapper.NativeView;
button.SetTitle("Scale and Rotate Text", UIKit.UIControlState.Normal);
button.SetTitleColor(UIKit.UIColor.Black, UIKit.UIControlState.Normal);
#endif
Notice:this code is only used in Shared Access Project.

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).

Silverlight Listbox: Binding does not get updated

I have a Wizard control that has multiple steps. Controls that are not visible get removed from the visual tree. I have a ListBox on one page, that binds to an ObservableCollection<T>. When items get added or removed to that ListBoxon one page, the ListBox on another page (with the same ItemsSource), the binding on the other page does not get updated. I hope this explains my problem clearly enough.
How do I get this binding to update when the page gets added to the visual tree again ?
I cannot reproduce your problem. I was able to remove a ListBox from the visual tree, add objects to the ObservableCollection, and when I add it to the visual tree, items are actually updated.
Try working around your problem by setting visibility to Collapsed rather than removing from Visual Tree.
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.listBox1.ItemsSource = o;
this.listBox2.ItemsSource = o;
}
ObservableCollection<int> o = new ObservableCollection<int>();
private void buttonList1_Click(object sender, RoutedEventArgs e)
{
if (this.listBox1.Parent == null)
this.LayoutRoot.Children.Add(this.listBox1);
else
this.LayoutRoot.Children.Remove(this.listBox1);
//this.listBox1.Visibility = this.listBox1.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
private void buttonList2_Click(object sender, RoutedEventArgs e)
{
if (this.listBox2.Parent == null)
this.LayoutRoot.Children.Add(this.listBox2);
else
this.LayoutRoot.Children.Remove(this.listBox2);
//this.listBox2.Visibility = this.listBox2.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}
private void ButtonAddMore_Click(object sender, RoutedEventArgs e)
{
o.Add(o.Count);
}
}

Resources