Thanks, now I understand what you meant. You create "off-screen" controls like:
Code: Select all
var btn = new Button();
var lb1 = new ListBox();
You can work with the controls, even if they are not assigned to a window.
Later on you add those controls to a window/layout manager.
Moving a control to another window/layout manager is simply done by removing it from current parent control
and add it to another window/layout manager (not possible with plain PB, something like SetParent_() with WinAPI).
Code: Select all
using System;
namespace WpfApplication
{
class Window : System.Windows.Window
{
private System.Windows.Controls.Canvas grid;
public Window(int x, int y, int width, int height, string title)
{
Left = x;
Top = y;
Width = width;
Height = height;
Title = title;
grid = new System.Windows.Controls.Canvas();
Content = grid;
}
public void Add(System.Windows.UIElement e)
{
grid.Children.Add(e);
}
public void Remove(System.Windows.UIElement e)
{
grid.Children.Remove(e);
}
}
class Button : System.Windows.Controls.Button
{
public Button(int x, int y, int width, int height, string title)
{
Content = title;
Width = width;
Height = height;
System.Windows.Controls.Canvas.SetLeft(this, x);
System.Windows.Controls.Canvas.SetTop(this, y);
}
}
class ListBox : System.Windows.Controls.ListBox
{
public ListBox(int x, int y, int width, int height)
{
Width = width;
Height = height;
System.Windows.Controls.Canvas.SetLeft(this, x);
System.Windows.Controls.Canvas.SetTop(this, y);
}
}
class Program
{
[STAThread]
public static void Main(string[] args)
{
var w1 = new Window(10, 10, 800, 600, "Window 1");
var w2 = new Window(400, 100, 800, 600, "Window 2");
//
// create controls, they are not bound to a window ("off-screen")
//
var btn = new Button(10, 10, 100, 25, "Exit");
var btn2 = new Button(10, 50, 100, 25, "Button 2");
var btn3 = new Button(10, 10, 100, 25, "Button 3");
var btn4 = new Button(10, 50, 100, 25, "Button 4");
var lb1 = new ListBox(120,10,200,200);
for(var i=1;i<100;i++)
lb1.Items.Add("Line " + i.ToString());
btn.Click += Shutdown;
w1.Closed += Shutdown;
//
// add the controls to a window/layout manager
//
w1.Add(btn);
w1.Add(btn2);
w2.Add(btn3);
w2.Add(btn4);
w2.Add(lb1);
//
// remove lb1 from w2, then add lb1 to w1
//
w2.Remove(lb1);
w1.Add(lb1);
w1.Show();
w2.Show();
DoEvents();
}
static void DoEvents()
{
System.Windows.Threading.Dispatcher.Run();
}
static void Shutdown(object o, System.Windows.RoutedEventArgs e)
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
}
static void Shutdown(object o, System.EventArgs e)
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
}
}
}
If PB had something similar to SetParent_() on Windows, for moving gadgets to another window/container at runtime,
most of your wishes could be emulated (combination of HideWindow/SetGadgetParent). CopyGadget/CloneGadget isn't that easy
at runtime. Determine gadget type, create new gadget of same type and copy all attributes/items from old to new gadget.