I have an issue with Winforms and touch inputs via a Microsoft Surface tablet. I know that winforms does not support touch input, but maybe there is something there can be done about this. So in my Winforms application i have a Form with two controls. A simple List Box and CefSharp ChromiumWebBrowser Control.
When I open the application the HTML is loaded and everything works fine with normal mouse input. I can click the textboxes and I can type. But when i do the same thing with touch controls on a MS Surface it seems the the ChromiumWebBrowser Control dows not get focus. The HTML Textboxes inside the Browser have focus, but the ChromiumWebBrowser Control does not. So whem i type, no input is send to the textboxes.
I tried to set focus manually whit C# in winforms, but those click events do not get fired in touch mode except for the Enter event. But this is fired only once. So i dont know how to get around this.
The user needs to be able to click outside the Browser Controle and do something there and then get back to the Browser and type into those textboxes.
Maybe someone had a similar issue and knows a workaround. If other Info is needed, please tell me.
Here is a gif to illustrate, hope it helps: https://i.stack.imgur.com/8J0EZ.gif
Thanks
private void Form1_Load(object sender, EventArgs e)
{
var asForm = System.Windows.Automation.AutomationElement.FromHandle(this.Handle);
wbMap = initBrowser();
this.panel1.Enabled = true;
this.panel1.Controls.Add(wbMap);
wbMap.FrameLoadEnd += WbMap_FrameLoadEnd;
wbMap.Click += WbMap_Click;
wbMap.Enter += WbMap_Enter;
wbMap.MouseClick += WbMap_MouseClick;
wbMap.DoubleClick += WbMap_DoubleClick;
wbMap.Leave += WbMap_Leave;
wbMap.LostFocus += WbMap_LostFocus;
wbMap.GotFocus += WbMap_GotFocus;
wbMap.PreviewKeyDown += WbMap_PreviewKeyDown;
}
private ChromiumWebBrowser initBrowser()
{
ChromiumWebBrowser wbMap = new ChromiumWebBrowser();
BrowserSettings browserSettings = new BrowserSettings();
browserSettings.FileAccessFromFileUrls = CefState.Enabled;
browserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
wbMap.BrowserSettings = browserSettings;
wbMap.LoadHtml("<!DOCTYPE html><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta charset=\"utf-8\" /><title></title></head><body><input type=\"text\"><input /></body></html>");
wbMap.Dock = DockStyle.Fill;
return wbMap;
}
private void WbMap_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
{
Console.WriteLine("QGIS_WbMap_FrameLoadEnd");
}
Related
So i'am working with tabControl in windows forms application and i want to make the tabs get full width regardless whether the application window is maximized or not.
When the window isn't maximized everything appears great:
But when the window gets maximized the tabs doesn't get the full width:
Is there any known way to fix this problem?
Thanks in advance
You can achieve this in some way by modifying the ItemSize property as described bellow, else you'd have to draw the tab page selectors yourself.
public Form1()
{
InitializeComponent();
tabControl1.SizeMode = TabSizeMode.Fixed;
tabControl1.ItemSize = new Size((tabControl1.Width / tabControl1.TabPages.Count) - 1, tabControl1.ItemSize.Height);
}
//Hook to form or parent container Resize event, either Resize or ResizeEnd.
private void Form1_ResizeEnd(object sender, EventArgs e)
{
tabControl1.ItemSize = new Size((tabControl1.Width / tabControl1.TabPages.Count) - 1, tabControl1.ItemSize.Height);
}
I'm currently working on a WPF application which will run on Windows 8.1 tablet and I don't find any posts about the following issue :
My application needs to be full screen, so, I set for my views :
WindowState="Maximized"
WindowStyle="ToolWindow"
All right - my application will be displayed in full screen mode:
But, if I rotate the tablet a space is allocated and the application is not in full screen.
I don't want this scenario to happen, the application should stay always in full screen.
I tried to listen SystemEvents.DisplaySettingsChanged event and manually set full screen:
SystemEvents.DisplaySettingsChanged += Current_SizeChanged;
private void Current_SizeChanged(object sender, EventArgs eventArgs)
{
this.WindowStyle = WindowStyle.None;
this.ResizeMode = ResizeMode.NoResize;
this.WindowState = WindowState.Maximized;
this.UpdateLayout();
}
As you can see, i tried even to update layout, but still, not working!
What is strange, is the fact that if you start the application in any position but not in the normal one, it will work. For ex: if the application is started in portrait mode, rotation will not change the dimensions of the window, but if you run the application starting from landscape mode... the bug appears.
You can debug this issue using Ctrl + Alt + Arrows.
Any suggestions?
Edit: It seems that the problem is caused by keyboard. The reserved zone is for keyboard, but i don't find a way to resize to full screen. Actual width, Width and Desired Width are all the same...
Edit2: This bug can be reproduced only on Windows 8.1
You can use DisplaySettingsChanged event of the SystemEvents class. Here is an example -> How to Detect Screen Rotation
Use a property in viewmodel which will set in the Current_SizeChanged method. Then put a data trigger on this boolean and apply RotateTransform 90deg to your LayoutTransform.
A workaraund for this bug is to listen to DisplaySettingsChanged and manually set windows state to normal and after windows state to maximized, like below :
SystemEvents.DisplaySettingsChanged += Current_SizeChanged;
private void Current_SizeChanged(object sender, EventArgs eventArgs)
{
this.WindowState = WindowState.Normal;
this.WindowState = WindowState.Maximized;
}
This is caused by :
WindowStyle="ToolWindow"
Hope microsoft will solve this bug (I submitted the bug on WPF threads on MSDN). Thank you for your help!
Like in web page using css we can show a div on mouse enter or hover, in the same way i want to show a panel on mouse enter event of a button, but i am unable to do this. I am trying like this.
private void btn2_MouseEnter(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.BackColor = System.Drawing.Color.MistyRose; //this is executed on mouse enter
Point locationOnForm = btn.FindForm().PointToClient(
btn.Parent.PointToScreen(btn.Location));
Panel pnl = new Panel();
Label lbl = new Label();
lbl.Text = "anything";
pnl.Controls.Add(lbl);
pnl.Location = new Point(locationOnForm.X, locationOnForm.Y);
pnl.Size = new Size(500, 500);
pnl.BackColor = Color.SkyBlue;
pnl.Visible = true;
pnl.Show();
}
I am not getting how to solve this. I want to know that
1) Is this the right approach or there is any other way of doing this?
2) If this is ok then what is the mistake i am doing here ?
Thanks.
Don't create the panel on mouse enter, rather have the panel created already then just show and hide it.
private void button1_MouseEnter(object sender, EventArgs e)
{
panel1.Show();
}
You have to add the panel to the Form controls
Form1.Controls.Add(pnl);
If you plan to have a panel hover over the button like a <div> in Web, you will have to call
BringToFront() to ensure that the panel does not appear behind the button or other controls on the form -
pnl.BringToFront();
Also like the previous answer, it may be better to have a panel placed on the form already and just set visible to true or false as well as the panel location otherwise you may end up adding multiple panels to the Form controls.
If you plan on just showing plain text in the panel, it may be easier to use Tooltip control -
MSDN - Tooltip Control
I have a modal pop up window in my wpf application. After showing that window, in some (rare) situations the window disappeared from the UI. But we can find that using “alt + tab” and can’t make it active.
Please find below the code i used,
//WindowInteropHelper assists interoperation between Windows Presentation Foundation (WPF) and Win32 code.
private void OnControlClick(object sender, RoutedEventArgs e)
{
System.Drawing.Point p = System.Windows.Forms.Control.MousePosition;
MyPopup popup = new MyPopup();
_windowInteropHelper = new System.Windows.Interop.WindowInteropHelper(popup);
_windowInteropHelper.Owner = this._owner;
popup.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
popup.Left = p.X;
popup.Top = p.Y;
popup.Closing += new System.ComponentModel.CancelEventHandler(OnPopupClosing);
popup.ShowDialog();
}
Try to use the IsOpen property to show/hide the popup.
I have a Winforms project with a bunch of User controls. I'd like the user control to move itself to be at the 1,1 position relative to its container (whether it's a form or a Panel control). And resize itself to be able to fit half the container.
What event can I respond to in the UserControl to be able to do this without any code having to be written in the container (e.g. the form or panel).
You could use the basic Load event.
The code could be like this:
private void UserControl1_Load(object sender, EventArgs e)
{
Control parent = this.Parent;
if (parent != null)
{
this.Location = new Point(1, 1);
this.Width = (parent.Width / 2);
this.Height = (parent.Height / 2);
}
}
The Paint event should work, unless I'm missing something.