CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #2
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646

    Re: little gliche in complex mouse tracking program

    First of all I would suggest you break down your code into classes, this way it would be much easier to localized the problem, don't put all your codes into one form.

    In my attached class I've broken down the drawing routine to the colorbox class, you can extend this class to allow mouse detection as well.

    Then you can use the attached colorbox class in your form like this (I'm using .NET 2 btw)

    Code:
    Collection<ColorBox> colorBoxes = new Collection<ColorBox>();//you can change this to arraylist if you're using .net 1
            public Form1()
            {
                InitializeComponent();
                this.AutoScroll = true;
                this.AutoScrollMinSize = new Size(800, 600);
                colorBoxes.Add(new ColorBox(Color.Red, new Point(0, 0), 100, 30));            
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);            
                foreach (ColorBox colorBox in colorBoxes)
                {
                    colorBox.Draw(e.Graphics, this.AutoScrollPosition);
                }
            }
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured