Mono winforms app fullscreen in Ubuntu? - winforms

Just wondering if there's a known way of getting a Mono System.Windows.Forms application to go fullscreen on Ubuntu/Gnome.
Mono is 2.4.2.3
Ubuntu is 9.10
Doing it on Windows requires a pinvoke, clearly not going to work here.
This is what I get setting window border to none, window position to centre, and state to maximised:
alt text http://dl.dropbox.com/u/116092/misc/permalink/joggler/screenshot01.png
Update.
Have also tried:
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
CTRL-F11
Text = string.Empty; // No caption
MaximizeBox = false;
MinimizeBox = false;
ControlBox = false;
FormBorderStyle = None;
WindowState = Maximized;
FormBorderStyle = FormBorderStyle.None;
Location = new Point(0, 0);
Size = Screen.PrimaryScreen.Bounds.Size;
All of which I end up with the same result.
I have come across a lead which involves a pinvoke involving _NET_WM_STATE_FULLSCREEN but that's as far as I've got with it. Any pointers on that would be appreciated.

_NET_WM_STATE_FULLSCREEN will just get rid of the borders. The GNOME panel will still appear.
According to the following post, the secret is to get rid of the minimum/maximum sizes so that the window manager does the resizing itself:
http://linux.derkeiler.com/Mailing-Lists/GNOME/2010-01/msg00035.html
Here is some documentation on the native spec:
http://standards.freedesktop.org/wm-spec/wm-spec-latest.html
http://www.x.org/docs/ICCCM/icccm.pdf
To talk directly to the X Window System you have to pinvoke into XLib. In order to send something like _NET_WM_STATE_FULLSCREEN you have to have a pointer to the window and also to the display.
I am not sure how to find the display but I can help with a pointer to the window. When running on X, the property Form.Handle should be a pointer to the X window.

Not sure what you mean by "Full Screen" - but I've written several Windows.Forms applications that take over the screen, and without a single PInvoke.
Here's how I configure my main form ...
Text = string.Empty; // No caption
MaximizeBox = false;
MinimizeBox = false;
ControlBox = false;
FormBorderStyle = None;
WindowState = Maximized;
Optionally,
TopMost = true;
Hope this helps.

You need to disable visual effects in ubuntu.
edit:
And make sure your form size is at least screen resolution without borders. If borders are on design time and you are removing them in code you will need something like 1030x796 for a 1024x768 display.

I have been suffered by this problem 2 days and finally i got the solution:
click the 1st icon on left tool bar and search compizconfig program. Go to preference-> unity and you will see there is a tick for unity plugin on the left side. Remove that tick and you will see the top menu bar disappeared.
Though this thread is very old but I still hope I can help anyone who gets this problem and seek for help.

Have you tried this?
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
Unfortunately I have no Ubuntu available right now, but I can see old patches for this in old mono versions...

It should be possible to display every app running inside gnome in fullscreen mode with the "CTRL+F11" hotkey.
Maybe you could try
System.Windows.Forms.SendKeys.Send();
but that is just a guess, I haven't got a Linux running atm to try this. But maybe this helps.

I can't test it at the moment, but have you tried a simple resize?
form.FormBorderStyle = FormBorderStyle.None
form.Location = Point(0, 0)
form.Size = Screen.PrimaryScreen.Bounds.Size

I have worked around this for now by setting the autohide property of the panel.
Not ideal because it depends on the user changing their environment to use my application, but better than nothing.

YMMV. http://fixunix.com/xwindows/91585-how-make-xlib-based-window-full-screen.html

The following worked:
(Inspiration was taken from here: https://bugzilla.xamarin.com/show_bug.cgi?id=40997)
1) sudo apt-get install wmctrl
2) In your code:
Form form = new MainWindow();
form.FormBorderStyle = FormBorderStyle.None;
form.WindowState = FormWindowState.Maximized;
form.Load += (s, e) => {
Process process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "wmctrl",
Arguments = $"-r :ACTIVE: -b add,fullscreen",
CreateNoWindow = true
}
};
process.Start();
process.WaitForExit();
};
Application.Run(form);

Related

unable to take screenshot of mouseover in selenium

I am trying to take screenshot of sub menu which happens on hovering in selenium using TakesScreenshot. But this is not working. Screenshot is taken but sub menu is not present in the image.
I have also tried using implicit wait after hover, but nothing worked.
Please suggest a method to capture screenshot of the sub menu.
contactUs.hoverHM();
screenshot = ((TakesScreenshot) PageFactoryBase.getSharedWebDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
This did the trick for me. I am pretty sure it will work for you.
_driver = new FirefoxDriver();
_driver.Navigate().GoToUrl("http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_mouseover_mouseout");
_driver.SwitchTo().Frame(_driver.FindElement(By.Id("iframeResult")));
Actions builder = new Actions(_driver);
builder.MoveToElement(_driver.FindElement(By.TagName("p"))).Build().Perform();
var screenshot = ((ITakesScreenshot)_driver).GetScreenshot();
var filename = new StringBuilder("D:\\");
filename.Append(DateTime.Now.ToString("HH_mm_ss dd-MM-yyyy" + " "));
filename.Append("test");
filename.Append(".png");
screenshot.SaveAsFile(filename.ToString(), System.Drawing.Imaging.ImageFormat.Png);
After hovering mouse on the text, it turns yellow and below is the screen shot that I took.
Below is another approach where you can use 'Print screen' Key in your Test code and get the image from the clipboard in the system.
What is have done is used KeyEvent 'PRTSC' to get the Image into the system clipboard and then get the system clipboard to write it to a file. I hope it will also copy the mouseover.
Robot rob = new Robot();
rob.keyPress(KeyEvent.VK_PRINTSCREEN);
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable content = clip.getContents(null);
BufferedImage img = (BufferedImage)content.getTransferData(DataFlavor.imageFlavor);
ImageIO.write(img, "png", new File("D:\\test.png"));
I have tried the same scenario but for clickAndHold for hover skin. It worked for me with the help of Actions as below:
WebElement elm = driver.findElement(By.id("btn1"));
Actions builder = new Actions(driver);
Action act = builder.clickAndHold(elm).build();
act.perform();
try {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\Img\\screenshot.png"));
} catch (IOException e) {
e.printStackTrace();
}
act = builder.release(elm).build();
act.perform();
You can instead replace clickAndHold with moveToElement Mouse hover the element. take the screenshot then release the element or move away from it.
Thanks everyone for answering on this thread.
I am able to take screenshot using robot as suggested by Vivek.
builder.moveToElement(getSharedWebDriver().findElement(By.xpath("//div[#class='brand section']/ul/li[#class='active hasflyout']"))).perform();
Robot robot = new Robot();
Point point;
point = getSharedWebDriver().findElement(By.xpath("//div[#class='brand section']/ul/li[#class='active hasflyout']")).getLocation();
int x = point.getX();
int y = point.getY();
robot.mouseMove(x,y);
In ideal case, either perform() or mouseMove() should be used. But somehow in my case, i had to use both the functions.

ExtJS 4 - Load Mask giving errors in IE8 and IE9 when used while opening a window

I have a window which opens up on a button click. The window takes time to load and hence I am using load mask in following way:
handler:function(){
var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Loading..."});
myMask.show();
var winAppln = showWin(myMask);
if(winAppln){
var task = new Ext.util.DelayedTask(function(){
winAppln.show();
});
task.delay(2000);
}
}
I am hiding the mask object in the afterrender function of window in following way:
afterrender:function(){
if(maskObj){
maskObj.hide();
}
}
The above code works fine in all the browsers, except IE (version 9 and 8).
In IE9 and IE8, there is an error generated as "Invalid Argument" in ext-all-debug.js at line 8682 which is as following
me.dom.style[ELEMENT.normalize(style)] = value;
Could anyone guide that what can be a possible reason behind this.
Also, my main purpose is to cover the lag between the click of button & opening of window, so that user is aware about something is happening. Is there a better way of doing this other then using Load Mask, or could Load Mask be used in some different manner, then as shown above?
Thanks in advance.
PS: I am using ExtJS Version 4.0.7
As per the things found by me so far, this issue is caused when the window has modal:true set.
IE 8 and 9 create a conflict between loadMask and modal:true and throw an error.
A workaround for this is to take off modal:true from the window and set it to true in the afterrender event of window once the loadmask hide function has been called as below:
afterrender:function(){
if(maskObj){
maskObj.hide();
}
this.modal = true;
}
Hope this helps someone looking for the same.
There is a bug in ExtJS4 Ext.LoadMask which is a problem in Internet Explorer 7 and 8.
When showing a loading mask, ExtJs tries to figure out the zIndex of the parent element, then setting the zIndex of the loading mask. In Internet Explorer 7/8 an element could also have set the zIndex "auto". parseInt of the string "auto" is NaN. Setting the zIndex to NaN causes an error in IE7/IE8.
The solution: override LoadMask
Ext.override(Ext.LoadMask, {
setZIndex: function(index) {
var me = this,
owner = me.activeOwner;
if (owner) {
index = parseInt(owner.el.getStyle('zIndex'), 10) + 1;
}
if (!isNaN(index)) {
me.getMaskEl().setStyle('zIndex', index - 1);
return me.mixins.floating.setZIndex.apply(me, arguments);
} else {
return '';
}
}
});
This topic is discussed also in Sencha Forums:
http://www.sencha.com/forum/showthread.php?228673-LoadMask-and-setZIndex-and-NaN
http://www.sencha.com/forum/showthread.php?246839
Give it a try with
Ext.getBody().mask("Loading")
I use this instead of LoadMask just because in ext you can't mask more than one component with dimmed background color, .mask() does the trick. LoadMask is prettier, but has some issues, so .mask could work.

Continual (rapid) update of WPF Image

There is a website that contains a single image from a webcam. Each time the site is hit, the most current image of the webcam is displayed. I want to make a real time video by hitting the site continuously.
I have searched and tried several things but cannot get it to refresh at a reasonable rate.
public MainWindow()
{
InitializeComponent();
this.picUri = "http://someurl";
this.thWatchVideo = new Thread(new ThreadStart(Watch));
_image = new BitmapImage();
_image.BeginInit();
_image.CacheOption = BitmapCacheOption.None;
_image.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
_image.CacheOption = BitmapCacheOption.OnLoad;
_image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
_image.UriSource = new Uri(this.picUri);
_image.EndInit();
this.imgVideo.Source = _image;
this.thWatchVideo.Start();
}
public void Watch()
{
while(true)
{
UpdateImage();
}
}
public void UpdateImage()
{
if (this.imgVideo.Dispatcher.CheckAccess())
{
_image = new BitmapImage();
_image.BeginInit();
_image.CacheOption = BitmapCacheOption.None;
_image.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
_image.CacheOption = BitmapCacheOption.OnLoad;
_image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
_image.UriSource = new Uri(this.picUri);
_image.EndInit();
this.imgVideo.Source = _image;
}
else
{
UpdateImageCallback del = new UpdateImageCallback(UpdateImage);
this.imgVideo.Dispatcher.Invoke(del);
}
}
Problem is, this is too slow and takes too long to refresh and the app just hangs.
I got this to work in Windows Forms with the PictureBox control but cannot get it to work in WPF. I refuse to believe that WPF is inferior to forms.
This app will always just hang (whether winforms or WPF) because you've got an infinite loop running everything it does on the UI thread. Your app hangs because you're not allowing the UI thread any time to process user input (such as resizing the window or trying to close the app).
With regard to your performance: have you tried profiling your code? I suspect that the problem is to do with you repeatedly hammering a webserver for an image, since you're never likely to get enough requests-per-second to make any kind of real-time video from static images. (There's a reason that we have video streaming codecs!)
instead of recreating whole image try to change only UriSource property.
Check out my answer to this: Showing processed images from an IP camera
Also, make sure the communication is done on a separate thread.
I suggest that the Bitmap image is a dependency object being created on a non-GUI thread. You then invoke UpdateImage on the GUI thread. Since the bitmap image dependency object wasn't created on/(owned by) the GUI thread, you get the "different thread owns it" error.
How about this as a workaround?
Copy the image temporarily to a local file location in your Watch routine.
Add a Thread.Sleep to the watch routine so that you don't hammer the CPU with the endless loop on this thread.
Use BeginInvoke instead of Invoke.
Load and update the image in the UpdateImage routine so that the image and the imgVideo objects are on the GUI thread. Update the image by reading it from your local file copy.
Without knowing the specifics of how you make Watch run on its own thread (using Background worker?) I think this approach will work for you.

WPF WebBrowser - How to Zoom Content?

Trying to test basic browser concepts in a WPF (C#/XAML, .NET 4.0) WebBrowser application. So far, the only problem is programatically zooming. Has anyone had any experience with this?
MSDN lists nothing: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx
Additionally, I have tried various things such as RenderTransform options to no avail. Either this is not possible or not documented. I'm hoping for the latter. Note that a WinForm solution isn't acceptable.
Thanks in advance for any help,
Beems
Maybe you can execute a javascript like this.
document.body.style.zoom = 1.5;
In WPF we can manipulate the document. I Created a Extension Method for you, so you can set the Zoom:
// www.tonysistemas.com.br
public static partial class MyExtensions
{
public static void SetZoom(this System.Windows.Controls.WebBrowser WebBrowser1, double Zoom)
{
// For this code to work: add the Microsoft.mshtml .NET reference
mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";");
}
}
Usage:
WebBrowser1.SetZoom(0.5);
I used bits and pieces from this answer https://stackoverflow.com/a/7326179/17822 to assist with the zoom issue. The key here is the ExecWB method. The zoom on the Windows Desktop is not 1-1 to the zoom on the WebBrowser Control. You will have to play with it. The pseudo-code for the equation looks like this:
zoomLevel = (winDesktopZoom - 100) + _winDesktopZoom + 10
Note that you will need a reference to SHDocVw.dll which can be found in the C:\Windows\SysWOW64 for x64 machines and in C:\Windows\System32 for x86 machines.
This is not pretty, but it is the only thing that I have found, short of upgrading to http://awesomium.com that actually matches IE default zoom settings (which default to the Windows Desktop zoom) to WebBrowser Control. Also note that the Windows Desktop Zoom only exists for Vista, Win 7 and probably 2k8 as well in the Control Panel --> Display, but I didn't check Vista or 2k8. It is not there for XP (any service pack).
To get the Windows Desktop Zoom (this does work on XP for some reason) I did:
var presentSource = PresentationSource.FromVisual(this);
if (presentSource != null && presentSource.CompositionTarget != null
&& presentSource.CompositionTarget.TransformToDevice != null)
{
_zoomPercentage = Convert.ToInt32(100 * presentSource.CompositionTarget.TransformToDevice.M11);
}
This logic is placed in the OnSourceInitialized override for that XAML Window.
You can see this:
http://chriscavanagh.wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/

Random GUI errors using C# Mono on Mac OS X

I'm developing an application in C# (Windows Forms), which uses Mono to run on Mac OS X.
It contains some dynamic controls, for example a custom groupbox which contains some labels and textboxes, a button, etc.These boxes can both be added and removed dynamically.
My CustomGrpBx inherits from GroupBox and this is the contructor I use:
public CustomGrpBx(Point CreateHere,Info Inf)
{
this.Name = Inf.Name;
this.Location = CreateHere;
CreateHere.Y = 10;
CreateHere.X = 10;
CreateHere.Y += 7;
Button btnPress = new Button();
btnPress.Location = CreateHere;
btnPress.Size = new Size(40, 24);
btnPress.Text = Name;
btnPress.Enabled = false;
this.Controls.Add(btnPress);
CreateHere.X += 45;
CreateHere.Y += 2;
TextBox txtName = new TextBox();
txtName.Location = CreateHere;
txtName.Size = new Size(75, 20);
txtName.Text = Name;
txtName.ReadOnly = true;
this.Controls.Add(txtName);
CreateHere.X += 80;
//More code here, but the same pattern as above
this.Size = new Size(CreateHere.X + 30, CreateHere.Y + 35);
}
The problem arises both when they are created, and removed, or even when a messagebox is shown.
What happens is that sometimes on rendering white boxes appears, or some labels are not drawn correctly. And sometimes when a messagebox appears, it first opens up like 5 dummies which are just blank, and which you can't close.
Am I doing something wrong, should I sleep the GUI thread a bit after each creation, or should I invalidate stuff on my own? Or should I try GTK#?
Many thanks on input on this.
It is hard to advise something without seeing actual code, but first of all, check your assembly with MoMa for incompatibility issues (for example, pinvoke's), if you primarily developed your project targeting .NET platform. Then, mono team claims that windows form support in mono is complete:
Support for Windows Forms 2.0 is complete. At this point, we are largely just fixing bugs and polishing our code.
So, you can try to run your project under .NET and see if the bug persists.
As for Gtk#. I think it is better to use gtk# if a primary OS for your project is OSX. At the very least you will be able to use some OSX-specific stuff, for example, integrate in it's toolbar. Look here for an open-source example of Gtk# project which uses some native OSX features and integrates well in it's environment. There also is a support for gtk# in MonoDevelop's designer.
P.S.
Some interesting Gtk# projects to play with:
Beagle,
Tomboy

Resources