// this should only be executed once per Form
    	public static API_WebScarab syncGuiPositionWithControl(this API_WebScarab webScarab, Control control)
    	{
		    Action moveToControl = 
				()=>{
						webScarab.alwaysOnTop(true); 
						var xPos =  control.PointToScreen(System.Drawing.Point.Empty).X;
						var yPos =  control.PointToScreen(System.Drawing.Point.Empty).Y;
						var width = control.width();
						var height = control.height();
						webScarab.moveWindow(xPos, yPos, width, height);  
					};	
						
			control.parentForm().Move += 
				(sender,e)=> moveToControl();
			 
			control.Resize +=  
				(sender,e)=> moveToControl();
			moveToControl();							
			return webScarab;
		}
        public Control showEditGui(Control hostControl, string title1, string title2, Func<List<string>> getContent)
        {   
        	hostControl.clear();
        	var usersGui = hostControl.add_1x1(title1,title2,true, hostControl.width()/3);
        	
        	var pageEditor = usersGui[1].add_Control<ascx_MediaWiki_PageEditor_Simple>().buildGui(WikiApi); 
        	
        	Action<Control> loadData = 
        		(control)=>{
        						control.clear();
        						control.enabled(false);
        						O2Thread.mtaThread(
        						()=>{        				
			        					var content = getContent();
			        					var treeView = control.add_TreeViewWithFilter(content)
			        					       				  .afterSelect<string>((userPage)=> pageEditor.openPage(userPage)); 
			        					addEditMenuItemsToTreeView(treeView);
			        					control.enabled(true);       
			        				});
        					};
        	
			        	
			        	
			usersGui[0].insert_Below<Panel>(20)
					   .add_Link("Reload data",0,0,
							()=> loadData(usersGui[0]))
						.click();
			return hostControl;						        
        }                
        public void createGui_EditUsingCategories(Control hostControl, string title1, string title2)
        {
        	hostControl.clear();
        	var usersGui = hostControl.add_1x1(title1,title2,true,hostControl.width()/3);
        	
        	var pageEditor = usersGui[1].Parent.clear().add_Control<ascx_MediaWiki_PageEditor_Simple>().buildGui(WikiApi); 
        	
			var controls = usersGui[0].Parent.clear().add_1x1("Category Names","Pages in Selected Category",false);
			var Categories_TreeView = controls[0].add_TreeView();
			var PagesInCategories_TreeView = controls[1].add_TreeView();

        	MethodInvoker loadData = 
        		()=>{
						//Categories_TreeView.clear();
						Categories_TreeView =  controls[0].add_TreeViewWithFilter(WikiApi.categoryPages())
														    .afterSelect<string>(
							(value)=>{
										PagesInCategories_TreeView = controls[1].add_TreeViewWithFilter(WikiApi.pagesInCategory(value))
														    					.afterSelect<string>((page)=>pageEditor.openPage(page));
									 
						
										pageEditor.openPage(value); 
										addEditMenuItemsToTreeView(PagesInCategories_TreeView);	
									 });
									 
						addEditMenuItemsToTreeView(Categories_TreeView);
						
					 };
						//PagesInCategories_TreeView.clear();
						//Categories_TreeView.add_Nodes(WikiApi.categoryPages());					
					
			controls[1].insert_Below<Panel>(20)
					   .add_Link("Reload data",0,0,()=> loadData())
						.click();        					 
        }
		public static IntPtr resizeWindowToControlSize(this IntPtr handle, Control controlToSync, int x, int y)
		{
			if (handle != IntPtr.Zero)
            {
                var width = controlToSync.width();
                var height = controlToSync.height();                    
                handle.window_Move(x, y, width,height);
                "Setting window with handle {0} to {0}x{1} : {2}x{3}".info(handle, x, y, width, height);
            }
            return handle;                                
		}