Change button background using button tag - vb.net

I have setup 30 buttons and assigned them tags 1-30. I am looking for a way to use the tag so I can use a loop to change each of the 30 background colors. here is the way I have it setup but would like to use a loop.
Pb_Seg1.BackColor = Color.FromArgb(intRed(intStepNumber), intGreen(intStepNumber), intBlue(intStepNumber))
Pb_Seg2.BackColor = Color.FromArgb(intRed(intStepNumber), intGreen(intStepNumber), intBlue(intStepNumber))
Pb_Seg3.BackColor = Color.FromArgb(intRed(intStepNumber), intGreen(intStepNumber), intBlue(intStepNumber))
Pb_Seg4.BackColor = Color.FromArgb(intRed(intStepNumber), intGreen(intStepNumber), intBlue(intStepNumber))
Pb_Seg5.BackColor = Color.FromArgb(intRed(intStepNumber), intGreen(intStepNumber), intBlue(intStepNumber))
Here is the way I set them on an event handler using the tag
Private Sub Segment(sender As Object, e As EventArgs) Handles Pb_Seg99.MouseHover, Pb_Seg99.Click, Pb_Seg98.MouseHover, Pb_Seg98.Click, Pb_Seg97.MouseHover, Pb_Seg97.Click, Pb_Seg96.MouseHover, Pb_Seg96.Click, Pb_Seg95.MouseHover, Pb_Seg95.Click, Pb_Seg94.MouseHover, Pb_Seg94.Click, Pb_Seg93.MouseHover, Pb_Seg93.Click, Pb_Seg92.MouseHover, Pb_Seg92.Click, Pb_Seg91.MouseHover, Pb_Seg91.Click, Pb_Seg90.MouseHover, Pb_Seg90.Click, Pb_Seg9.MouseHover, Pb_Seg9.Click, Pb_Seg89.MouseHover, Pb_Seg89.Click, Pb_Seg88.MouseHover, Pb_Seg88.Click, Pb_Seg87.MouseHover, Pb_Seg87.Click, Pb_Seg86.MouseHover, Pb_Seg86.Click, Pb_Seg85.MouseHover, Pb_Seg85.Click, Pb_Seg84.MouseHover, Pb_Seg84.Click, Pb_Seg83.MouseHover, Pb_Seg83.Click, Pb_Seg82.MouseHover, Pb_Seg82.Click, Pb_Seg81.MouseHover, Pb_Seg81.Click, Pb_Seg80.MouseHover, Pb_Seg80.Click, Pb_Seg8.MouseHover, Pb_Seg8.Click, Pb_Seg79.MouseHover, Pb_Seg79.Click, Pb_Seg78.MouseHover, Pb_Seg78.Click, Pb_Seg77.MouseHover, Pb_Seg77.Click, Pb_Seg76.MouseHover, Pb_Seg76.Click, Pb_Seg75.MouseHover, Pb_Seg75.Click, Pb_Seg74.MouseHover, Pb_Seg74.Click, Pb_Seg73.MouseHover, Pb_Seg73.Click, Pb_Seg72.MouseHover, Pb_Seg72.Click, Pb_Seg71.MouseHover, Pb_Seg71.Click, Pb_Seg70.MouseHover, Pb_Seg70.Click, Pb_Seg7.MouseHover, Pb_Seg7.Click, Pb_Seg69.MouseHover, Pb_Seg69.Click, Pb_Seg68.MouseHover, Pb_Seg68.Click, Pb_Seg67.MouseHover, Pb_Seg67.Click, Pb_Seg66.MouseHover, Pb_Seg66.Click, Pb_Seg65.MouseHover, Pb_Seg65.Click, Pb_Seg64.MouseHover, Pb_Seg64.Click, Pb_Seg63.MouseHover, Pb_Seg63.Click, Pb_Seg62.MouseHover, Pb_Seg62.Click, Pb_Seg61.MouseHover, Pb_Seg61.Click, Pb_Seg60.MouseHover, Pb_Seg60.Click, Pb_Seg6.MouseHover, Pb_Seg6.Click, Pb_Seg59.MouseHover, Pb_Seg59.Click, Pb_Seg58.MouseHover, Pb_Seg58.Click, Pb_Seg57.MouseHover, Pb_Seg57.Click, Pb_Seg56.MouseHover, Pb_Seg56.Click, Pb_Seg55.MouseHover, Pb_Seg55.Click, Pb_Seg54.MouseHover, Pb_Seg54.Click, Pb_Seg53.MouseHover, Pb_Seg53.Click, Pb_Seg52.MouseHover, Pb_Seg52.Click, Pb_Seg51.MouseHover, Pb_Seg51.Click, Pb_Seg50.MouseHover, Pb_Seg50.Click, Pb_Seg5.MouseHover, Pb_Seg5.Click, Pb_Seg49.MouseHover, Pb_Seg49.Click, Pb_Seg48.MouseHover, Pb_Seg48.Click, Pb_Seg47.MouseHover, Pb_Seg47.Click, Pb_Seg46.MouseHover, Pb_Seg46.Click, Pb_Seg45.MouseHover, Pb_Seg45.Click, Pb_Seg44.MouseHover, Pb_Seg44.Click, Pb_Seg43.MouseHover, Pb_Seg43.Click, Pb_Seg42.MouseHover, Pb_Seg42.Click, Pb_Seg41.MouseHover, Pb_Seg41.Click, Pb_Seg40.MouseHover, Pb_Seg40.Click, Pb_Seg4.MouseHover, Pb_Seg4.Click, Pb_Seg39.MouseHover, Pb_Seg39.Click, Pb_Seg38.MouseHover, Pb_Seg38.Click, Pb_Seg37.MouseHover, Pb_Seg37.Click, Pb_Seg36.MouseHover, Pb_Seg36.Click, Pb_Seg35.MouseHover, Pb_Seg35.Click, Pb_Seg34.MouseHover, Pb_Seg34.Click, Pb_Seg33.MouseHover, Pb_Seg33.Click, Pb_Seg32.MouseHover, Pb_Seg32.Click, Pb_Seg31.MouseHover, Pb_Seg31.Click, Pb_Seg30.MouseHover, Pb_Seg30.Click, Pb_Seg3.MouseHover, Pb_Seg3.Click, Pb_Seg29.MouseHover, Pb_Seg29.Click, Pb_Seg28.MouseHover, Pb_Seg28.Click, Pb_Seg27.MouseHover, Pb_Seg27.Click, Pb_Seg26.MouseHover, Pb_Seg26.Click, Pb_Seg25.MouseHover, Pb_Seg25.Click, Pb_Seg24.MouseHover, Pb_Seg24.Click, Pb_Seg23.MouseHover, Pb_Seg23.Click, Pb_Seg22.MouseHover, Pb_Seg22.Click, Pb_Seg21.MouseHover, Pb_Seg21.Click, Pb_Seg20.MouseHover, Pb_Seg20.Click, Pb_Seg2.MouseHover, Pb_Seg2.Click, Pb_Seg19.MouseHover, Pb_Seg19.Click, Pb_Seg18.MouseHover, Pb_Seg18.Click, Pb_Seg17.MouseHover, Pb_Seg17.Click, Pb_Seg16.MouseHover, Pb_Seg16.Click, Pb_Seg15.MouseHover, Pb_Seg15.Click, Pb_Seg14.MouseHover, Pb_Seg14.Click, Pb_Seg13.MouseHover, Pb_Seg13.Click, Pb_Seg12.MouseHover, Pb_Seg12.Click, Pb_Seg11.MouseHover, Pb_Seg11.Click, Pb_Seg100.MouseHover, Pb_Seg100.Click, Pb_Seg10.MouseHover, Pb_Seg10.Click, Pb_Seg1.Click
Dim Segment As PictureBox = DirectCast(sender, PictureBox)
Segment.BackColor = Color.FromArgb(PatternColorsRed(ColorSelected), PatternColorsGreen(ColorSelected), PatternColorsBlue(ColorSelected))
' ColorSelected = (pb.Tag)
intRed(intStepNumber) = PatternColorsRed(ColorSelected)
intGreen(intStepNumber) = PatternColorsGreen(ColorSelected)
intBlue(intStepNumber) = PatternColorsBlue(ColorSelected)
End Sub

Resolved the issue. Setup picture array and cast each picture.
picturetest(0) = Pb_Seg1
picturetest(2) = Pb_Seg2
picturetest(3) = Pb_Seg2
for i=0 to 2
picturetest(i).BorderStyle = BorderStyle.Fixed3D
next

Related

Loop Through Array of Labels Using Temp Variable

I've got a 2D array of 100 labels in a 10x10 matrix (it's 2D because it represents some hardware out in the real world, if anyone cares). I want to loop through and check a conditional, and change the label background color if the conditional is false.
I've tried this ten different ways, but I keep getting an exception thrown because the temp variable I have created won't take an assignment to one of the label names.
'Table for correct switch module for corresponding actuator
Dim ActLabelLookup(,) As Label =
{{MTA91, MTA92, MTA93, MTA94, MTA95, MTA96, MTA97, MTA98, MTA99, MTA100},
{MTA81, MTA82, MTA83, MTA84, MTA85, MTA86, MTA87, MTA88, MTA89, MTA90},
{MTA71, MTA72, MTA73, MTA74, MTA75, MTA76, MTA77, MTA78, MTA79, MTA80},
{MTA61, MTA62, MTA63, MTA64, MTA65, MTA66, MTA67, MTA68, MTA69, MTA70},
{MTA51, MTA52, MTA53, MTA54, MTA55, MTA56, MTA57, MTA58, MTA59, MTA60},
{MTA41, MTA42, MTA43, MTA44, MTA45, MTA46, MTA47, MTA48, MTA49, MTA50},
{MTA31, MTA32, MTA33, MTA34, MTA35, MTA36, MTA37, MTA38, MTA39, MTA40},
{MTA21, MTA22, MTA23, MTA24, MTA25, MTA26, MTA27, MTA28, MTA29, MTA30},
{MTA11, MTA12, MTA13, MTA14, MTA15, MTA16, MTA17, MTA18, MTA19, MTA20},
{MTA1, MTA2, MTA3, MTA4, MTA5, MTA6, MTA7, MTA8, MTA9, MTA10}}
Private Sub UpdateActuatorStatus()
Dim X As Integer
Dim Y As Integer
Dim CurrAct As New Label
For X = 0 To (ActControl.MAX_X - 1)
For Y = 0 To (ActControl.MAX_Y - 1)
If TempFunctionalActuatorMatrix(X, Y) = False Then
CurrAct = ActLabelLookup(X, Y)
CurrAct.BackColor = Color.Firebrick
End If
Next
Next
End Sub
With this code, CurrAct is never getting set to anything. Anyone see what I'm doing wrong?
Your array isn't initialised (well, it is, but it is initialised with nothings as the labels are nothing as the form instance is created).
Try filling it before parsing (in Form Load or in UpdateActuatorStatus):
ActLabelLookup =
{{MTA91, MTA92, MTA93, MTA94, MTA95, MTA96, MTA97, MTA98, MTA99, MTA100},
{MTA81, MTA82, MTA83, MTA84, MTA85, MTA86, MTA87, MTA88, MTA89, MTA90},
{MTA71, MTA72, MTA73, MTA74, MTA75, MTA76, MTA77, MTA78, MTA79, MTA80},
{MTA61, MTA62, MTA63, MTA64, MTA65, MTA66, MTA67, MTA68, MTA69, MTA70},
{MTA51, MTA52, MTA53, MTA54, MTA55, MTA56, MTA57, MTA58, MTA59, MTA60},
{MTA41, MTA42, MTA43, MTA44, MTA45, MTA46, MTA47, MTA48, MTA49, MTA50},
{MTA31, MTA32, MTA33, MTA34, MTA35, MTA36, MTA37, MTA38, MTA39, MTA40},
{MTA21, MTA22, MTA23, MTA24, MTA25, MTA26, MTA27, MTA28, MTA29, MTA30},
{MTA11, MTA12, MTA13, MTA14, MTA15, MTA16, MTA17, MTA18, MTA19, MTA20},
{MTA1, MTA2, MTA3, MTA4, MTA5, MTA6, MTA7, MTA8, MTA9, MTA10}}
Change the member-level declaration of ActLabelLookup to just:
Dim ActLabelLookup(,) As Label
In the form's Load event handler add a line to initialize it:
ActLabelLookup(,) =
{{MTA91, MTA92, MTA93, MTA94, MTA95, MTA96, MTA97, MTA98, MTA99, MTA100},
{MTA81, MTA82, MTA83, MTA84, MTA85, MTA86, MTA87, MTA88, MTA89, MTA90},
{MTA71, MTA72, MTA73, MTA74, MTA75, MTA76, MTA77, MTA78, MTA79, MTA80},
{MTA61, MTA62, MTA63, MTA64, MTA65, MTA66, MTA67, MTA68, MTA69, MTA70},
{MTA51, MTA52, MTA53, MTA54, MTA55, MTA56, MTA57, MTA58, MTA59, MTA60},
{MTA41, MTA42, MTA43, MTA44, MTA45, MTA46, MTA47, MTA48, MTA49, MTA50},
{MTA31, MTA32, MTA33, MTA34, MTA35, MTA36, MTA37, MTA38, MTA39, MTA40},
{MTA21, MTA22, MTA23, MTA24, MTA25, MTA26, MTA27, MTA28, MTA29, MTA30},
{MTA11, MTA12, MTA13, MTA14, MTA15, MTA16, MTA17, MTA18, MTA19, MTA20},
{MTA1, MTA2, MTA3, MTA4, MTA5, MTA6, MTA7, MTA8, MTA9, MTA10}}

highchart display goal on mouse hover

Below is my code to display highcharts, now in the chart goal is showed on mouse over. i want to display it as thin line:
options.series[1] = new Object();
options.series[1].name = "Goal Points";
options.series[1].data = Goallimit;
options.series[1].type = 'arearange';
options.series[1].lineWidth = 0;
options.series[1].linkedTo = ':previous';
options.series[1].color = '#A6E685';
options.series[1].fillOpacity = 0.3;
options.series[1].zIndex = 0;!
Here is Highchart image

How do I create a XAML storyboard animation from C++\CX?

I've defined a Rectangle in the XAML named "MyRectangle" and when clicked I execute this code:
auto animation = ref new Windows::UI::Xaml::Media::Animation::DoubleAnimation();
animation->From = 0.01;
animation->To = 5.50;
animation->AutoReverse = true;
auto beginTime = Windows::Foundation::TimeSpan();
beginTime.Duration = 0;
animation->BeginTime = beginTime;
auto duration = Windows::Foundation::TimeSpan();
duration.Duration = 20000*1000;
animation->Duration = duration;
auto storyboard = ref new Windows::UI::Xaml::Media::Animation::Storyboard();
auto scaleTransform = ref new Windows::UI::Xaml::Media::ScaleTransform();
MyRectangle->RenderTransform = scaleTransform;
storyboard->SetTargetProperty(animation, "(Rectangle.RenderTransform).(ScaleTransform.ScaleX)");
storyboard->SetTarget(animation, MyRectangle);
storyboard->SetTargetName(animation, "MyRectangle");
storyboard->SpeedRatio = 1.0;
storyboard->Begin();
However, nothing happens. What am I doing wrong?
You must add the "animation" (or more animations) to the "storyboard" childrens:
storyboard->Children->Append(animation);
This is the C# equivalent:
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.animation.storyboard

How to move control at the correct position when Windows Forms is maximised

I am using VB.NET and I have added buttons and text edits in a windows form.
When I press maximize button, the buttons and text edits do not cover the entire windows form.
I have checked the Docking method, but it works when I have few controls (like 2 or 3 buttons).
I will need to add around 20 button controls in the form.
How do I make sure the controls will move accordingly when the window form is maximized?
Thank you.
It's not so obvious to automatically adapt the position of your child controls when the parent control resizes in Windows Forms, but do you really want that ?
It seems like a terrible idea for usability.
If you want to achieve this though, you should use a TableLayoutPanel, set the size of the columns/rows to a certain percentage and then fill the panel with your controls. Here is some sample code:
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Location = new System.Drawing.Point(7, 0);
this.label1.Margin = new System.Windows.Forms.Padding(7, 0, 7, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 25);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label2.AutoSize = true;
this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
this.label2.Location = new System.Drawing.Point(105, 0);
this.label2.Margin = new System.Windows.Forms.Padding(7, 0, 7, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(84, 25);
this.label2.TabIndex = 1;
this.label2.Text = "label2";
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.AutoSize = true;
this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.label2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(147, 107);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(196, 25);
this.tableLayoutPanel1.TabIndex = 3;

VB.Net Image is not Showing at Runtime

Button image and icon is not showing at runtime
Button Image
Me.wibtnAdd.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
Me.wibtnAdd.DisabledImagesGrayScale = False
Me.wibtnAdd.Enabled = False
Me.wibtnAdd.Image = CType(resources.GetObject("wibtnAdd.Image"), System.Drawing.Image)
Me.wibtnAdd.ImageFixedSize = New System.Drawing.Size(24, 24)
Me.wibtnAdd.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top
Me.wibtnAdd.Location = New System.Drawing.Point(53, 302)
Me.wibtnAdd.Name = "wibtnAdd"
Me.wibtnAdd.Shape = New DevComponents.DotNetBar.RoundRectangleShapeDescriptor(2)
Me.wibtnAdd.Size = New System.Drawing.Size(61, 52)
Me.wibtnAdd.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled
Me.wibtnAdd.TabIndex = 8
Me.wibtnAdd.Text = "Add"
Form Icon
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
to make your code more clear : 1) get rid of the 'Me'
2) use a 'With' clause
(i edited)
the issue seems to be in your access to resources : are you sure
you have a resource named "wibtnAdd.Image" ? it seems 'strange'
that it has same name as your object/property... Check your
wibtnAdd.Image, it might be Nothing. Same for your Icon.
Btw why not doing this in xaml ?? it would be much more readable,
and you can edit everything while seeing results.