8 Replies - 956 Views - Last Post: 10 July 2011 - 02:17 PM Rate Topic: -----

#1 morphuisogrady  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 11

How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 12:49 PM

Hi there,

I'm hoping someone can point me in the direction of what I'm trying to achieve as I have no idea how to go about it.


I want to create an object. Its basically just going to be a square on my form and its background colour should change based on the status of a variable I'm reading from an external device via a 3rd party comms driver. I want the ability to change the text as well. "Available, Occupied, Alarm, Warning, etc etc.

I want to have multiple instances of this object (30-50) so I want the ability to "drag and drop" onto form or programatically draw the object/s on form.

Further down the line I want the ability to be able to draw required number of objects on form based on user requirements at runtime. So if user decides they have 30 devices then the form should draw 30 boxs in columns of 3.

Based on my limited knowledge of C# I could draw one box and animate it with code. Myu thoughts are I need to create a class with a method for animating the box and changing text accordingly but have no idea how to tie it to the square object?

Make Sense? Any pointers greatly appreciated.

Thannks

Is This A Good Question/Topic? 0
  • +

Replies To: How to Create a Box object with colour animation and tie it to code

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,427
  • Joined: 12-June 08

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:04 PM

It would be a pretty straight forward project.

In your class you would have an enumeration for the status types.
A property for the x/y top left location.
A property for the height and width (you probably just need one because it's a square!)
A function/property to set the status type.
A generic event to fire that is 'status typed changed'.
A method that takes in an graphics object and does a 'draw rectangle' per the color of the status.
A constructor that takes in all the variables, x, y, height, and status.

In your main form you would have a list of type what ever that class is above. Then you add new objects to the list per the user request. Make sure to hook up the events to go to a single event. That event listener would signale a 'repaint' is needed. Then in use the form's "paint" event have a for loop cycle through all the objects in the list feeding it the event's graphic object. This would make them draw a rectangle for the given status in a given location.

Easy peasy!

http://msdn.microsof...wrectangle.aspx

Edit: once that is done you are pretty much there and can take care of the text as needed.

This post has been edited by modi123_1: 10 July 2011 - 01:05 PM

Was This Post Helpful? 0
  • +
  • -

#3 morphuisogrady  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 11

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:09 PM

View Postmodi123_1, on 10 July 2011 - 01:04 PM, said:

It would be a pretty straight forward project.

In your class you would have an enumeration for the status types.
A property for the x/y top left location.
A property for the height and width (you probably just need one because it's a square!)
A function/property to set the status type.
A generic event to fire that is 'status typed changed'.
A method that takes in an graphics object and does a 'draw rectangle' per the color of the status.
A constructor that takes in all the variables, x, y, height, and status.

In your main form you would have a list of type what ever that class is above. Then you add new objects to the list per the user request. Make sure to hook up the events to go to a single event. That event listener would signale a 'repaint' is needed. Then in use the form's "paint" event have a for loop cycle through all the objects in the list feeding it the event's graphic object. This would make them draw a rectangle for the given status in a given location.

Easy peasy!


http://msdn.microsof...wrectangle.aspx

Edit: once that is done you are pretty much there and can take care of the text as needed.
Ha ha. Easy peasey when you know how! Thats great, thanks for your help. So the approach is to go about it with code! I'll make a start with that tomorrow.

This post has been edited by Curtis Rutland: 10 July 2011 - 01:13 PM
Reason for edit:: I think I fixed his reply

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,427
  • Joined: 12-June 08

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:12 PM

What? Did I miss a reply?
Was This Post Helpful? 0
  • +
  • -

#5 morphuisogrady  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 11

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:14 PM

Hmmm. I did post a reply. It said thanks for your help. Easy peasey when you know how!

I'll get started with that in the morning
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,427
  • Joined: 12-June 08

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:15 PM

Rock on
Was This Post Helpful? 0
  • +
  • -

#7 morphuisogrady  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 11

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:18 PM

View Postmodi123_1, on 10 July 2011 - 01:15 PM, said:

Rock on


Can i steal your brain for a couple of weeks :)
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8915
  • View blog
  • Posts: 33,427
  • Joined: 12-June 08

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 01:20 PM

Naw.. my job and side projects would probably get pissed.
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,649
  • Joined: 02-June 10

Re: How to Create a Box object with colour animation and tie it to code

Posted 10 July 2011 - 02:17 PM

Remember the basics of OOP.
You don't make a program that tries to micro-manage 30 objects. You do make a box-object that can manage itself, then you make 30 instances of it.

These might help with the underlying principals.

The tutorials below walk through making an application including inheritance, custom events and custom controls, object serialization and more.
Bulding an application - Part 1
Building an application - Part 2
Quick and easy custom events
Separating data from GUI - PLUS - serializing the data to XML
Passing values between forms/classes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1