Skip to playerSkip to main contentSkip to footer
  • yesterday
Tutorial 217 is a TradeStation EasyLanguage ShowMe study that demonstrates how to add buttons to a form. The buttons are colored with each of the named color objects available. When a button is clicked in the ShowMe study, the name of the color and the RGB value of the color are displayed at the bottom of the form. To do this a mouse click event is utilized.
https://markplex.com/free-tutorials/tutorial-217-display-color-object-colors-in-form/
Transcript
00:00Hello and welcome to tutorial 217. In this tutorial we're going to be creating a form
00:06and on that form we're going to be drawing buttons, creating buttons for all the color
00:12objects in Trader Station. So you can see we have the form here, we have the buttons applied,
00:19each of them is one of the color object colors and what I've done is added the name
00:24on the little buttons as well and then furthermore if we were to click on a particular button
00:29for example firebrick you'll see that a the name of that color appears on this label and over here
00:38we have a little bit more information about the RGB values of that color and then I've just made
00:44the back of the form that color and the same we click on another another color and those values
00:51change in the back of the the color form changes. So let's quickly go through the program let me show
00:58you what I've done I'm just going to close that for the moment so slowly what I'll do is come back
01:02to some of these methods as always you will be able to download this for a small fee or if you prefer
01:09you can copy it in as we go through it. First of all the one statement what we're doing here is creating
01:15two vectors the color vector which is going to store the color names in other words the strings
01:20and button vector which is going to store the buttons first of all we added to the color vector
01:26using dot push underscore back all the names of the color objects in trade station so we did that we
01:34went through all of those then having done that we created a form using color form equals new form now
01:42you may not be super familiar with this syntax and you could either copy and paste what I've got here
01:48or what you could do if you right click on your the area where you're programming and say add form
01:56you'll see that it creates a form and it shows you all the the various values that you can control
02:02in that form for example you could decide okay the back color I want this to be a red color and
02:10what you then might say well I want to know what is the syntax to add some labels so if we went to view
02:17toolbox and then we could just find the label add those to the the form and you can also see
02:28the the values that we can change for those labels and now if you were to go to the designer generated
02:34code you would see all the code that you have just generated so that is that is one way of getting
02:41the the syntax but we're not going to do that right now I'm just going to right click I'm going to remove
02:47the form and now you'll see that the designer generated code is empty again so let's let's go
02:56through what we did in this tutorial as I say we created the values of the colors in a vector then we
03:03created a form and then we set a few elements of the form like for example its name the original color
03:09that it's going to be in the background padding font used and we showed we use color form dot show
03:18and then for our labels we created two labels we haven't really got too much useful information
03:25in them at the moment but label one label two and we gave them initial positions we'll be changing
03:32those in a moment so don't need to think about that too much but what we then did is we looped through
03:38the color vector which has got all the names of the colors and in each case we created a new a new
03:45button we set the back color to the color now since we're using strings in the vector we need to take
03:54convert that into the color object we did that using color dot from name and then we put the the name as a
04:02string and then we set the full color and then we created the initial position then having done that
04:08what we want to do is we want to do 10 buttons in a row then we need to go to a new row 10 10 buttons 10
04:17columns then a new row etc and we do that in this little area here we add the button to the form we also add
04:27the new button text and set the font make it visible etc and then you'll notice also that we could click
04:34on a button and that would have an effect so we need to set up an event so the button has been stored in
04:39this vector so we could say button vector counter as type button dot mouse click and that then creates
04:48this event here then when we've created all the colored buttons we want to add our two we want to
04:53reposition our two labels to make them just beyond where the the color buttons are and we do that using this
05:0050 times row plus a half and you'll see that that gets them approximately where we where we want them
05:07now one thing i just skipped over there is we've got the back color for the button but we've also got a
05:12four color and that's going to be effectively for the writing and you'll notice if we uh if we just go back
05:18and look at the the form again is that the writing for these buttons varies for example some of them
05:24we've got black writing and some of them we've got white writing and that is to do with the the contrast
05:31so i deliberately uh decided to do this based on contrast and uh in this program we're doing we're
05:37making that decision based on based on the high contrast color method which which i've included so
05:45let's just have a look at that while we're discussing this if we just go to the top of the program
05:51you see we've got the uh the name spaces the variables then we've got the event a new button
05:57mouse click which happens when a particular button is clicked and then we've got this high contrast color
06:05and what it does it basically takes the color so for example black it converts that into rgb and then
06:12it uses this formula here relative luminance simplified and it just basically does a calculation
06:18and it says if that value is greater than 128 then we want to use black otherwise we want to use white
06:25and it returns that color and uses that to draw the text so that is the the where we draw all the buttons
06:34i mentioned already that we had an event which is set up in this area here so what that does let's just
06:46go back up to the top sorry to keep moving backwards and forwards but that is this event here what we do
06:53is we go through every single button and we set a value of clicked button to each button in turn
07:02and then we say if the sender in other words the uh the one that the system is picking up being
07:08clicked is equal to clicked button we now know what the clicked button is what we can do is then reset
07:16the label one text to be able equal to the clicked button back color and we can set label two dot text to be
07:26the legacy color from color object of the button that's been clicked and that is another method which
07:32we'll look at in a moment and then just the the color form we set the back color to
07:37the the back color of the clicked button so let's uh let's have a look at this other method here legacy
07:45color from color object and essentially all this does is it just provides or returns some text describing
07:54the the color and it does that through converting it in various in various ways uh for example color int
08:03that uses rgb for the color components to return an rgb color and then we have that uh those values
08:11provided separately instantly this is this is a string so so rgb color has a 32 bit integer and then we return
08:21that value and actually we use that value for the labels then apart from all of that as i mentioned
08:28we also have the namespaces variables and i've added a little bit of commentary at the top
08:37so hopefully uh you will find that useful and uh i will as i say make this available and uh otherwise
08:51you're welcome to uh to use any of the parts of it to uh to recreate a similar program and uh thank you
08:59very much for your attention
09:16you

Recommended