Mostly Bollogs, I'm afraid

But occasionally, a glimmer of truth.
If you find one, please let me know.



Monday, 9 June 2014

C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BuildRack
{
    public partial class Form1 : Form
    {
        public Color[] cTable={Color.Black, Color.Brown, Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Gray, Color.White};
        public int ix = 0;
        TableLayoutPanel Rack;
        public Form1()
        {
            InitializeComponent();
            this.Rack = new System.Windows.Forms.TableLayoutPanel();
            Padding pad = new Padding(0);
            Rack.Margin = pad;
            Rack.Enabled = true;
            Rack.Location = this.ClientRectangle.Location;
            Rack.Size = this.ClientRectangle.Size;
            Rack.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;

            for (ix = 0; ix < 10; ix++)
            {
                this.Rack.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 10.0F));
                this.Rack.RowStyles.Add(new RowStyle(SizeType.Percent, 10.0F));
                Label b = new Label();
                b.Text = ix.ToString();
                b.BackColor = cTable[ix];
                Rack.Controls.Add(b, 0, ix);
                Rack.SetColumnSpan(b, ix+1);
                b.Size = b.Parent.Size;
                b.MouseDown += b_MouseDown;
            }
            Rack.DragDrop += Rack_DragDrop;
            Rack.DragOver += Rack_DragOver;
            Rack.DragEnter += Rack_DragEnter;
            this.Controls.Add(Rack);
            Rack.Show();
        }

        void Rack_DragEnter(object sender, DragEventArgs e)
        {
            throw new NotImplementedException();
        }

        void Rack_DragOver(object sender, DragEventArgs e)
        {
            throw new NotImplementedException();
        }

        void Rack_DragDrop(object sender, DragEventArgs e)
        {
            throw new NotImplementedException();
        }

        void b_MouseDown(object sender, MouseEventArgs e)
        {
            Rack.AllowDrop = true;
            ((Label)sender).DoDragDrop(sender, DragDropEffects.Move);
        }
    }
}

3 comments:

David Sinfield said...

I can't see anything wrong here. I am loading it into VS so I can try to debug it. It might take a while. How much of a hurry are you in?

The only comments I have off hand are:

*I don't think you need to add the events again. they are there by default.

*The cast to a label looks odd I would use (label)sender. etc Can't see why your way doesn't work though.

Uncle Marvo said...

I put the events there so they'd fail and I'd see they were being fired.

Adam Feather said...

What are you trying to achieve? The moving of labels? You need to handle the MouseMove event of the label if that's the case.