Can someone please point me out to a short example of how to add and remove a window to a Notebook control in Mono? I have already searched for any examples but was unable to find anything.
Only thing I found meanwhile: http://docs.go-mono.com/index.aspx?link=T%3AGtk.Notebook
I finally found out how to do this in Mono:
Widget1 win1 = new Widget1();
HBox hbox = new HBox();
hbox.PackStart(new Label("Pane 1") );
Button close = new Button("×"); // Set this up with an image or whatever.
close.Relief = ReliefStyle.None;
close.FocusOnClick = false;
close.Clicked += delegate {
hbox.Destroy();
win1.Destroy();
};
hbox.PackStart(close);
hbox.ShowAll();
nbMain.AppendPage(win1, hbox);
win1.Show();
The main trick is that child panes (Widget1 in my case) should inherit from Widget, not from Window!
Related
I'm very new at programming in C# and Xamarin, and now I'm stuck.
I made a menu with some help, now I can do Cut/Copy/Paste which works fine, but now I want to make an Dialog or Window for some User Settings whenever they click on Settings in the menu. (I've made the menu in AppDelegate.cs)
I've look around a lot on Google and Xamarin forums, but al they talk about is to add a new kind of storyboard thingy. Which I guess will work, but I'm not using any storyboard (Just because we want to make everything out of code).
Found on Xamarin:
https://developer.xamarin.com/guides/mac/user-interface/working-with-dialogs/
And then the Preference window (That is what I prefer).
Code I made in AppDelegate.cs (Menu button which has to open an Window or Dialog):
var prefMenuItem = new NSMenuItem("Settings", ",", handler: delegate
{
var prefStyle = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;
var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
prefWindow = new NSWindow(rect, prefStyle, NSBackingStore.Buffered, false);
prefWindow.Title = "Settings";
prefWindow.TitleVisibility = NSWindowTitleVisibility.Hidden;
});
'Settings' Button in the menu is visible btw.
Probably I forgot something, it won't open a thing.
How can I make this work?
Maybe this will work for you.
var prefMenuItem = new NSMenuItem("Settings", ",", handler: delegate
{
var prefStyle = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;
var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
prefWindow = new NSWindow(rect, prefStyle, NSBackingStore.Buffered, false);
prefWindow.Title = "Settings";
prefWindow.TitleVisibility = NSWindowTitleVisibility.Hidden;
NSApplication.SharedApplication.RunModalForWindow(prefWindow);
});
I added NSApplication.SharedApplication.RunModalForWindow(prefWindow); in your code. This will open a new window.
Found this on: https://forums.xamarin.com/discussion/22729/xamarin-mac-how-to-set-position-of-modal-window
I need to create some buttons at runtime. I tried to find a solution online, but there were only old threads. The only thing I've found is the following code:
ViewGroup layout = (ViewGroup)Resource.Layout.Main;
Button btn = new Button(this);
btn.Text = "text";
btn.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
layout.AddView(btn);
I don't understand how this should work. There are no compile errors, but the app closes instantly after launching. Can you explain why this happens and how to write this code properly?
Doing
ViewGroup layout = (ViewGroup)Resource.Layout.Main;
Won't give you the currently inflated layout. Resource.Layout.Main is just an int pointing at a resource.
Instead give your currently shown layout and id:
android:id="#+id/root"
Now it does matter what type it is. The default templates use LinearLayout. So finding it would be:
var root = FindViewById<LinearLayout>(Resource.Id.root);
Then you can add your button to that:
var button = new Button(this)
{
Text = "hello",
LayoutParameters = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MatchParent,
ViewGroup.LayoutParams.WrapContent)
};
root.AddView(button);
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");
I want to show a new form in the same window from where it was invoked.
I know a way to show this form on PrimaryScreen or Virtual Screen by code similar to as below:
MyForm.Location = Screen.PrimaryScreen.Bounds.Location;
But i want to show it on current screen.
Is there a way to find out and show it on current screen?
I have done something like this to show my form centered to the current screen:
var screen = Screen.FromPoint(Cursor.Position);
myForm.StartPosition = FormStartPosition.Manual;
myForm.Left = screen.Bounds.Left + screen.Bounds.Width / 2 - myForm.Width / 2;
myForm.Top = screen.Bounds.Top + screen.Bounds.Height / 2 - myForm.Height / 2;
You can use the same technique, but instead of using the PrimaryScreen, grab the screen using Screen.FromPoint and Cursor.Position:
Screen screen = Screen.FromPoint(Cursor.Position);
MyForm.Location = screen.Bounds.Location;
It sounds like you aren't setting the StartPosition to Manual.
If you already have a parent form and want to open a new form on the same screen, give the ShowDialog method a reference to the parent form: newForm.ShowDialog(this); Without owner parameter ("this") the new form may open on the main screen even when your parent form is on another screen.
Click on the Form in design mode.
Change the StartPosition property to CenterScreen .
This should open up the form on the active screen. Refer
this for more values of StartPosition.
I know this is late, but still, post my answer hope that it will help someone else. After several tries, I got this work with 3 monitors
var currentScreen = Screen.FromControl(this);
if (!currentScreen.Primary)
{
var hCenter = currentScreen.Bounds.Left + (((currentScreen.Bounds.Right - currentScreen.Bounds.Left) / 2) - ((Width) / 2));
var vCenter = (currentScreen.Bounds.Bottom / 2) - ((Height) / 2);
StartPosition = FormStartPosition.Manual;
Location = new Point(hCenter, vCenter);
}
else
{
CenterToScreen();
}
Many years later, but no item was marked as the appropriate answer and I combined two comments to get it working (namely from Reed Copsey and Jason).
I haven't tried any of the other methods described, since this worked without problem and got the Form to open on the monitor my cursor is at, as intended.
Here's my working code:
Screen screen = Screen.FromPoint(Cursor.Position);
Application.Run(new Form1()
{
StartPosition = FormStartPosition.Manual, //Summary in VS actually mentions this as needed to make use of Location
Location = screen.Bounds.Location,
WindowState = FormWindowState.Maximized
});
ChildWindow1 wnd1 = new ChildWindow1();
ChildWindow2 wnd2 = new ChildWindow2();
wnd1.Show();
//**Is there a way to pause thread here until wnd1 is closed???**
wnd2.Show();
Use code like this:-
ChildWindow1 wnd1 = new ChildWindow1;
wnd1.Closed += (s, args) =>
{
ChildWindow2 wnd2 = new ChildWindow2;
wnd2.Show();
}
wnd1.Show();
// Note code here will run as soon as wnd1 has displayed, Show does not block.
I assume you are talking about modal child window. Yes it possible and real simple. Use Child Window control from Silverlight ToolKit # http://silverlight.codeplex.com/.