Mark Michaelis' Weblog :
Updated: 9/1/2004; 6:55:16 AM.

 








Subscribe to "Mark Michaelis' Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

Subscribe To
Mark's Weblog

 
 

Monday, January 13, 2003

While investigating the  lame Runtime Control Moving (An Initial Forms Designer Attempt) I come across a couple interesting articles.  Firstly, there is a pretty cool sample designer.  To grasp how cool this is check out the following screen shot from the article:

 

I also came across a mention by Mark Boulter that there would be a sample on .NET of how to use the Forms Designer stand alone but based on my search no such sample has materialized. :)


11:58:25 PM   []    comment []

Runtime Control Moving (An Initial Forms Designer Attempt)
Google Search It

As is typical with me, what started out as a seemingly achievable project has quickly snowballed out of control. I was talking to some of the Itron developers in Vancouver and them mentioned the desire to have a designer that would allow users to create custom screens or to customize existing screens.  "No problem," says me.  Just implement drag and drop on the form controls.  I proceeded to do this and once I realized that the X and Y coordinates of the MouseEventArgs parameter of the MouseDown event were relative to the sending control (not the Form) I was set.  I simply passed the Form.MousePostion as the data parameter for DoDragDrop method.  Inside the DragDrop event I then subtracted the old location from the new location (using the X and Y coordinates since the Point class does not support arithmetic) and determined the distance to move the control.  To figure out which control was moved I used the forms GetChildAtPoint( ) method using the original MouseDown point and converting it to client coordinates with the PointToClient() function.  I have been deliberately brief in this discussion because as I delved further into the idea I realized how many complexities I would have to add.  Here are just a few of them:

  1. Determining when to copy and when to paste.
  2. If copying creating the controls on the fly.
  3. Linking the controls to data.... what data?
  4. Adding new controls.
  5. Linking the new controls to data.
  6. Undo support
  7. Cut and Paste support
  8. Show control while dragging (easily supported via the MouseMove event.)

As you can see, this list quickly gets out of hand.  Not that this isn't possible or that some of these items aren't reasonable on their own even.  In combination, however, this is more than a simple spike I could complete in and evening or even two weeks of evenings.  I think I will wait until I have a real need.

Anyway, here is the code:

        public MyForm()
        {

            // ...
 
            //*******************************
            // NOTE: Add this call
            InitializeForm();
            //*******************************
 
            // ...
 
    
        //

            // Required for Windows Form Designer support
            //
            InitializeComponent(); 

        }

 
        //*******************************
        #region Form Design Support
        //*******************************
        // Initialize to true to demo code.  Normally this would be set by a menu
        // option or some such.
        private bool m_DesignModeActive = true;
        public bool DesignModeActive
        {
            get
            {
                return m_DesignModeActive;
            }
            set
            {
                m_DesignModeActive = value;
            }
        }
 
        private void InitializeForm()
        {
            this.AllowDrop = true;
            this.ControlAdded +=
                new ControlEventHandler(this.Control_Added);
            this.DragDrop +=
                new DragEventHandler(this.ControlDragDrop);
            this.DragEnter +=
                new DragEventHandler(this.ControlDragEnter);
        }
 
        private void ControlMouseEnter(object sender,
            System.EventArgs e)
        {
            Control control;
            control = this.GetChildAtPoint(
                this.PointToClient(Form.MousePosition));
            if(control != null)
            {
                if(DesignModeActive)
                {
                    control.Cursor = Cursors.SizeAll;
                }
                else
                {
                    control.Cursor = Cursors.Default;
                }
            }
        }
 
 
        private void ControlMouseDown(object sender,
            System.Windows.Forms.MouseEventArgs e)
        {        
            if(DesignModeActive)
            {
                Control control =  this.GetChildAtPoint(
                    this.PointToClient(Form.MousePosition));
                if(control != null)
                    control.DoDragDrop(Form.MousePosition,
                        DragDropEffects.Copy | DragDropEffects.Move);
            }
        }
 
        private void Control_Added(object sender,
            System.Windows.Forms.ControlEventArgs e)
        {
            e.Control.MouseDown +=
                new MouseEventHandler(this.ControlMouseDown);
            e.Control.DragDrop +=
                new DragEventHandler(this.ControlDragDrop);
            e.Control.MouseEnter +=
                new EventHandler(this.ControlMouseEnter);
            this.AllowDrop = true;
        }
  
        private void ControlDragDrop(object sender,
            System.Windows.Forms.DragEventArgs e)
        {
            Control control;   
            Point mouseDownPoint;
            if(e.Data.GetDataPresent(typeof(Point))
                && DesignModeActive)
            {
                
                mouseDownPoint = (Point) e.Data.GetData(typeof(Point));
                control = this.GetChildAtPoint(
                    this.PointToClient(mouseDownPoint));
                if(control !=null)
                {
                    Point dropPoint = Form.MousePosition;
                    control.Left = control.Left +
                        (dropPoint.X - mouseDownPoint.X);                
                    control.Top = control.Top +
                        (dropPoint.Y - mouseDownPoint.Y);
                }
            }
        }
 
        private void ControlDragEnter(object sender,
            System.Windows.Forms.DragEventArgs e)
        {
            if(e.Data.GetDataPresent(typeof(Point)) && DesignModeActive)
                e.Effect = DragDropEffects.Move; //DragDropEffects.Copy;
        }
 
        private void ControlQueryContinueDrag(object sender,
            System.Windows.Forms.QueryContinueDragEventArgs e)
        {
            // TODO
        }
        //*******************************
        #endregion // Form Designer Support

Note that this code was written generically so adding it to any form will enable moving of all controls on that form.  To do this simply paste the Form Designer Support region to your form and call InitializeForm() from inside your constructor.  Admittedly this isn't fully flushed out and I have already commented about all that is missing but hopefully this will provide a good start for those of you wishing to do a subset of what I list.  Sorry about the abundance of comments.

P.S.  Is there some way to get radio to stop changing the color when I use double back slashes?


11:56:13 PM   []    comment []

Gallery Websites
Google Search It

I came across another gallery program today at http://www.ex-designz.net/gallery/default.asp.  This is an ASP based version which is at least closer to what I am looking for as it uses ASP rather than PHP.  The solution can be downloaded from here.  So far I have successfully installed it but not been able to administer it because the instruction.txt file provides the admin password but not the user name.  Presumably this is obvious but I haven't figured it out yet.

After my brother selected gallery I have been looking around for a replacement as I found gallery lacking.  I am looking for a utility that will essentially replicate an HTML version of My Pictures folder such that backing up the My Pictures folder will backup what is displayed on the server.  Multi-user support with replication would be a bonus.  One frustration with gallery is the upload process and gallery remote doesn't make that any better.  . and since I don't know PHP (and don't believe I have the time to learn at the moment) I couldn't customize it to suit my needs.  Another frustration is the fact that one can't just create sub folders and have them be sub-albums.

In recent weeks I have installed SharePoint at work and I am tempted to provide a webpart for pictures.  Security is already provided in SharePoint and folder/album support is there.  This seems the most appealing solution at the moment.  Furthermore, it has category, keyword and author support.


12:01:47 AM   []    comment []

© Copyright 2004 Mark Michaelis.



 


January 2003
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Dec   Feb


Recent Posts