Example #1
0
		VBox GenerateFrameContents (bool useMnemonics)
		{
			var statusText = useMnemonics ? "with mnemonic" : "without mnemonic";
			var vbox = new VBox ();

			var button = new Button ("_Button");
			button.UseMnemonic = useMnemonics;
			button.Clicked += (sender, e) => MessageDialog.ShowMessage (string.Format ("Button {0} clicked.", statusText));
			vbox.PackStart (button);

			var toggleButton = new ToggleButton ("_Toggle Button");
			toggleButton.UseMnemonic = useMnemonics;
			toggleButton.Clicked += (sender, e) => MessageDialog.ShowMessage (string.Format ("Toggle Button {0} clicked.", statusText));
			vbox.PackStart (toggleButton);

			var menuButton = new MenuButton ("_Menu Button");
			menuButton.UseMnemonic = useMnemonics;
			menuButton.Label = "_Menu Button";
			var firstMenuItem = new MenuItem ("_First");
			firstMenuItem.UseMnemonic = useMnemonics;
			firstMenuItem.Clicked += (sender, e) => MessageDialog.ShowMessage (string.Format ("First Menu Item {0} clicked.", statusText));
			var secondMenuItem = new MenuItem ("_Second");
			secondMenuItem.UseMnemonic = useMnemonics;
			secondMenuItem.Clicked += (sender, e) => MessageDialog.ShowMessage (string.Format ("Second Menu Item {0} clicked.", statusText));
			var menu = new Menu ();
			menu.Items.Add (firstMenuItem);
			menu.Items.Add (secondMenuItem);
			menuButton.Menu = menu;
			vbox.PackStart (menuButton);

			return vbox;
		}
Example #2
0
 /// <summary>
 /// constructor
 /// </summary>
 public AppStartWidget()
 {
     _startButton = new ToggleButton { WidthRequest = 100 };
     _startButton.Clicked += CallStart;
     Add (_startButton, 0, 0);
     _startButton.Image = Icons.Start;
 }
Example #3
0
        public ButtonSample()
        {
            Button b1 = new Button ("Click me");
            b1.Clicked += delegate {
                b1.Label = "Clicked!";
            };
            PackStart (b1);

            Button b2 = new Button ("Click me");
            b2.Style = ButtonStyle.Flat;
            b2.Clicked += delegate {
                b2.Label = "Clicked!";
            };
            PackStart (b2);

            PackStart (new Button (Image.FromIcon (StockIcons.ZoomIn, IconSize.Medium)));

            MenuButton mb = new MenuButton ("This is a Menu Button");
            Menu men = new Menu ();
            men.Items.Add (new MenuItem ("First"));
            men.Items.Add (new MenuItem ("Second"));
            men.Items.Add (new MenuItem ("Third"));
            men.Items.Add (new MenuItem ("Check") { Type = MenuItemType.CheckBox, Checked = true });
            men.Items.Add (new MenuItem ("Radio") { Type = MenuItemType.RadioButton, Checked = true });
            men.Items.Add (new MenuItem ("With image") { Image = Image.FromResource (typeof(App), "class.png") });

            mb.Menu = men;
            PackStart (mb);
            foreach (var mi in men.Items) {
                var cmi = mi;
                mi.Clicked += delegate {
                    mb.Label = cmi.Label + " Clicked";
                };
            }

            ToggleButton tb = new ToggleButton ("Toggle me");
            PackStart (tb);
        }
Example #4
0
        private Widget CreateTopBar()
        {
            var topBox = new HBox();

            lblTitle = new Label {
                Text = Card.Title,
                Font = Font.WithWeight(FontWeight.Bold).WithSize(20),
                TextAlignment = Alignment.Center,
                Wrap = WrapMode.Word,
                Visible = false
            };
            topBox.PackStart(lblTitle, true);

            txtTitle = new TextEntry {
                Text = Card.Title,
                Font = lblTitle.Font,
                TextAlignment = Alignment.Center,
                Visible = false
            };
            topBox.PackStart(txtTitle, true);

            btnEdit = new ToggleButton(ResourcesManager.GetImage("pencil.png"));
            topBox.PackEnd(btnEdit);

            return topBox;
        }
Example #5
0
        public ButtonSample()
        {
            Button b1 = new Button ("Click me");
            b1.Clicked += delegate {
                b1.Label = "Clicked!";
            };
            PackStart (b1);

            Button b2 = new Button ("Click me");
            b2.Style = ButtonStyle.Flat;
            b2.Clicked += delegate {
                b2.Label = "Clicked!";
            };
            PackStart (b2);

            PackStart (new Button (Image.FromIcon (StockIcons.ZoomIn, IconSize.Medium)));

            MenuButton mb = new MenuButton ("This is a Menu Button");
            Menu men = new Menu ();
            men.Items.Add (new MenuItem ("First"));
            men.Items.Add (new MenuItem ("Second"));
            men.Items.Add (new MenuItem ("Third"));
            men.Items.Add (new SeparatorMenuItem ());
            men.Items.Add (new CheckBoxMenuItem ("Check") { Checked = true });
            men.Items.Add (new RadioButtonMenuItem ("Radio") { Checked = true });
            men.Items.Add (new MenuItem ("With image") { Image = Image.FromResource (typeof(App), "class.png") });

            mb.Menu = men;
            PackStart (mb);
            foreach (var mi in men.Items) {
                var cmi = mi;
                mi.Clicked += delegate {
                    mb.Label = cmi.Label + " Clicked";
                };
            }

            ToggleButton tb = new ToggleButton ("Toggle me");
            PackStart (tb);

            var b = new Button ("Mini button");
            b.Style = ButtonStyle.Borderless;
            PackStart (b);

            tb = new ToggleButton ("Mini toggle");
            tb.Style = ButtonStyle.Borderless;
            PackStart (tb);

            var child = new VBox ();
            var container = new MyWidget { Content = child };

            var button = new Xwt.Button ("Click to add a child");
            button.Clicked += delegate {
                child.PackStart (new Xwt.Label ("Child" + child.Children.Count ()), BoxMode.Fill);
            };

            var content = new Xwt.VBox ();
            content.PackStart (button, BoxMode.Fill);
            content.PackStart (container, BoxMode.Fill);

            PackStart (content);
        }
Example #6
0
        public ButtonSample()
        {
            Button b1 = new Button("Click me");
            b1.Clicked += delegate
            {
                b1.Label = "Clicked!";
            };
            PackStart(b1, false, false);

            Button b2 = new Button("Click me");
            b2.Style = ButtonStyle.Flat;
            b2.Clicked += delegate
            {
                b2.Label = "Clicked!";
            };
            PackStart(b2);

            PackStart(new Button(StockIcons.ZoomIn.WithSize(22)));
            PackStart(new Button(StockIcons.ZoomIn.WithSize(32), "Custom Size") { WidthRequest = 110, MinHeight = 50 });

            var hbox = new HBox();
            hbox.PackStart(new Button(StockIcons.ZoomIn.WithSize(22), "Zoom In") { ImagePosition = ContentPosition.Top });
            hbox.PackStart(new Button(StockIcons.ZoomOut.WithSize(22), "Zoom Out") { ImagePosition = ContentPosition.Bottom });
            hbox.PackStart(new Button(StockIcons.Information.WithSize(48), "Info") { ImagePosition = ContentPosition.Top }, true);
            hbox.PackEnd(new Button("Custom" + Environment.NewLine + "Width") { MinWidth = 110 });
            PackStart(hbox);

            PackStart(new Button(new CustomImage().WithSize(22), "with red background") { BackgroundColor = Colors.Red });

            MenuButton mb = new MenuButton("This is a Menu Button");
            Menu men = new Menu();
            men.Items.Add(new MenuItem("First"));
            men.Items.Add(new MenuItem("Second"));
            men.Items.Add(new MenuItem("Third"));
            men.Items.Add(new SeparatorMenuItem());
            men.Items.Add(new CheckBoxMenuItem("Check") { Checked = true });
            men.Items.Add(new RadioButtonMenuItem("Radio") { Checked = true });
            men.Items.Add(new MenuItem("With image") { Image = Image.FromResource(typeof(App), "class.png") });

            mb.Menu = men;
            PackStart(mb);
            foreach (var mi in men.Items)
            {
                var cmi = mi;
                mi.Clicked += delegate
                {
                    mb.Label = cmi.Label + " Clicked";
                };
            }

            ToggleButton tb1 = new ToggleButton("Toggle me");
            ToggleButton tb2 = new ToggleButton("Mini toggle");
            tb1.Toggled += delegate(object sender, EventArgs e)
            {
                if (tb1.Active)
                    tb1.Label = "Toggled";
                else
                    tb1.Label = "Untoggled";
                tb2.Active = tb1.Active;
            };
            PackStart(tb1);

            var b = new Button("Mini button");
            b.Style = ButtonStyle.Borderless;
            PackStart(b);

            tb2.Style = ButtonStyle.Borderless;
            tb2.Toggled += delegate(object sender, EventArgs e)
            {
                if (tb2.Active)
                    tb2.Label = "Toggled";
                else
                    tb2.Label = "Untoggled";
                tb1.Active = tb2.Active;
            };
            PackStart(tb2);

            b = new Button(" ? ");
            b.Type = ButtonType.Help;
            PackStart(b);

            var child = new VBox();
            var container = new MyWidget { Content = child };

            var button = new Xwt.Button("Click to add a child");
            /*
            button.Clicked += delegate {
                child.PackStart (new Xwt.Label ("Child" + child.Children.Count ()));
            };
            */
            var content = new Xwt.VBox();
            content.PackStart(button);
            content.PackStart(container);

            PackStart(content);
        }
Example #7
0
		public MultithreadingSample ()
		{
			int r = 0;
			var tbl = new Table ();
			PackStart (tbl);

			tbl.Add (new Label("Application.Invoke:"), 0, r);
			tbl.Add (l1 = new Label ("0"), 1, r);
			tbl.Add (btn1 = new ToggleButton("Run"), 2, r++);

			Task worker1;
			CancellationTokenSource worker1cancel = new CancellationTokenSource ();;
			btn1.Toggled += delegate {
				if (btn1.Active) {

					worker1cancel = new CancellationTokenSource ();
					worker1 = Task.Factory.StartNew (delegate {

						int cnt = 0;
						while (!worker1cancel.Token.IsCancellationRequested) {
							Thread.Sleep (50);
							cnt++;
							string txt = cnt.ToString ();
							Application.Invoke (() => l1.Text = txt);
						}
					}, worker1cancel.Token, TaskCreationOptions.LongRunning);
				}
				else
					worker1cancel.Cancel();
			};


			tbl.Add (new Label("Application.UITaskScheduler:"), 0, r);
			tbl.Add (l2 = new Label ("0"), 1, r);
			tbl.Add (btn2 = new ToggleButton("Run"), 2, r++);

			Task worker2;
			CancellationTokenSource worker2cancel = new CancellationTokenSource ();;
			btn2.Toggled += delegate {
				if (btn2.Active) {

					worker2cancel = new CancellationTokenSource ();
					worker2 = Task.Factory.StartNew (delegate {

						int cnt = 0;
						while (!worker2cancel.Token.IsCancellationRequested) {
							Thread.Sleep (50);
							cnt++;
							var txt = cnt.ToString ();
							Task.Factory.StartNew(delegate {
								l2.Text = txt;
							}, worker2cancel.Token, TaskCreationOptions.None, Application.UITaskScheduler);
						}
					}, worker2cancel.Token, TaskCreationOptions.LongRunning);
				}
				else
					worker2cancel.Cancel();
			};


			tbl.Add (new Label("BackgroundWorker:\n(XwtSynchronizationContext.Post)"), 0, r);
			tbl.Add (l3 = new Label ("0"), 1, r);
			tbl.Add (btn3 = new ToggleButton("Run"), 2, r++);

			var worker3 = new BackgroundWorker ();
			worker3.WorkerReportsProgress = true;
			worker3.WorkerSupportsCancellation = true;
			worker3.DoWork += BackgroundWorkerDoWork;
			worker3.ProgressChanged += (sender, e) => l3.Text = e.ProgressPercentage.ToString ();

			btn3.Toggled += delegate {
				if (btn3.Active)
					worker3.RunWorkerAsync ();
				else
					worker3.CancelAsync ();
			};


			tbl.Add (new Label("XwtSynchronizationContext.Send:"), 0, r);
			tbl.Add (l4 = new Label ("0"), 1, r);
			tbl.Add (btn4 = new ToggleButton("Run"), 2, r++);

			worker4 = new SampleBGWorker ();
			worker4.SynchronizationContext = SynchronizationContext.Current;
			worker4.InvokeSynchronized = true;
			worker4.Count += HandleCount4;

			btn4.Toggled += delegate {
				if (btn4.Active)
					worker4.Start ();
				else
					worker4.Stop ();
			};


			tbl.Add (new Label("ISynchronizeInvoke.BeginInvoke:"), 0, r);
			tbl.Add (l5 = new Label ("0"), 1, r);
			tbl.Add (btn5 = new ToggleButton("Run"), 2, r++);

			worker5 = new SampleBGWorker ();
			worker5.InvokeSynchronized = false;
			worker5.Count += HandleCount5;

			btn5.Toggled += delegate {
				if (btn5.Active)
					worker5.Start ();
				else
					worker5.Stop ();
			};


			tbl.Add (new Label("ISynchronizeInvoke.Invoke:"), 0, r);
			tbl.Add (l6 = new Label ("0"), 1, r);
			tbl.Add (btn6 = new ToggleButton("Run"), 2, r++);

			worker6 = new SampleBGWorker ();
			worker6.InvokeSynchronized = true;
			worker6.Count += HandleCount6;

			btn6.Toggled += delegate {
				if (btn6.Active)
					worker6.Start ();
				else
					worker6.Stop ();
			};
		}