AdvancedHMI Software
General Category => Support Questions => Topic started by: Rox on November 24, 2017, 07:21:32 AM
-
Hi!, Support please,
I have a basic label that on click i would like to display a screen configuration pop-up to change Min-Max Engg units for scaling and the Option to change the suffix. How can I do that?
(https://farm5.staticflickr.com/4538/26839556169_9f8d6e658f_z.jpg) (https://flic.kr/p/GTHJYr)
Thanks, Rox (https://flic.kr/p/GTHJYr)
-
I am not sure what your Min and Max values refer to.
The following code shows one possible way of doing this and can be added to the MainForm to handle suffix changes for the BasicLabel1 in this example:
Private Sub BasicLabel1_MouseUp(sender As Object, e As MouseEventArgs) Handles BasicLabel1.MouseUp
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim bLabel As AdvancedHMIControls.BasicLabel = DirectCast(sender, AdvancedHMIControls.BasicLabel)
Dim lblMin, lblMax, lblSuffix As New System.Windows.Forms.Label
Dim tbMin, tbMax, tbSuffix As New System.Windows.Forms.TextBox
Dim btnOK As New System.Windows.Forms.Button
Dim f = New System.Windows.Forms.Form
f.StartPosition = FormStartPosition.CenterScreen
f.Size = New Size(288, 260)
f.Text = "Change Min/Max/Suffix"
f.AcceptButton = btnOK
f.TopMost = True
lblMin.Location = New Point(25, 37)
lblMin.Font = New Font("Microsoft Sans Serif", 14)
lblMin.Text = "Min:"
lblMin.TextAlign = System.Drawing.ContentAlignment.MiddleRight
lblMax.Location = New Point(25, 69)
lblMax.Font = New Font("Microsoft Sans Serif", 14)
lblMax.Text = "Max:"
lblMax.TextAlign = System.Drawing.ContentAlignment.MiddleRight
lblSuffix.Location = New Point(25, 104)
lblSuffix.Font = New Font("Microsoft Sans Serif", 14)
lblSuffix.Text = "Suffix:"
lblSuffix.TextAlign = System.Drawing.ContentAlignment.MiddleRight
tbMin.Size = New Size(100, 20)
tbMin.Location = New Point(130, 37)
tbMin.Font = New Font("Microsoft Sans Serif", 12)
tbMin.ReadOnly = False
tbMax.Size = New Size(100, 20)
tbMax.Location = New Point(130, 69)
tbMax.Font = New Font("Microsoft Sans Serif", 12)
tbMax.ReadOnly = False
tbSuffix.Size = New Size(100, 20)
tbSuffix.Location = New Point(130, 104)
tbSuffix.Font = New Font("Microsoft Sans Serif", 12)
tbSuffix.ReadOnly = False
btnOK.Size = New Size(81, 37)
btnOK.Location = New Point(87, 162)
btnOK.Text = "OK"
f.Controls.Add(lblMin)
f.Controls.Add(lblMax)
f.Controls.Add(lblSuffix)
f.Controls.Add(tbMin)
f.Controls.Add(tbMax)
f.Controls.Add(tbSuffix)
f.Controls.Add(btnOK)
AddHandler btnOK.Click, Sub()
Try
'Add here code to handle Min and Max changes
'This line will change suffix if new one is entered
If Not String.IsNullOrEmpty(tbSuffix.Text) Then bLabel.ValueSuffix = tbSuffix.Text
f.Close()
f.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
f.Show()
End If
End Sub
A new form will only show up on the right-click of the mouse.
Do note that if the PLCAddressKeypad field is populated then this right-click of the mouse will also show the Keypad itself.
In order to prevent this and limit the Keypad show only with the left-click of the mouse, update the following Sub inside the BasicLabel code:
'***********************************************************
'* If label is clicked, pop up a keypad for data entry
'***********************************************************
Protected Overrides Sub OnClick(e As System.EventArgs)
MyBase.OnClick(e)
If e.GetType = GetType(System.Windows.Forms.MouseEventArgs) Then
Dim mea As System.Windows.Forms.MouseEventArgs = e
If mea.Button.ToString = "Left" Then
If m_PLCAddressKeypad IsNot Nothing AndAlso (String.Compare(m_PLCAddressKeypad, "") <> 0) And Enabled Then
ActivateKeypad()
End If
End If
End If
End Sub
Make any changes to the code as you see it fit for your purpose.
-
Hi Godra Thanks so much for support,
tried your code, I can now change the suffix, but my attempt to write the Min-Max value for use in PLC scaling calculation failed, it returns an exception, here's my attempt to write to Modbus register:
'Add here code to handle Min and Max changes
ModbusTCPCom1.Write("40002", lblMax.Text)
on your second pasted code, im getting an error "m_PLCaddressKeypad is not declared.
Regards, Rox
-
Hi Godra Thanks so much for support,
tried your code, I can now change the suffix, but my attempt to write the Min-Max value for use in PLC scaling calculation failed, it returns an exception, here's my attempt to write to Modbus register:
'Add here code to handle Min and Max changes
ModbusTCPCom1.Write("40002", lblMax.Text)
Here, you have to use the value from the TextBox, not Label, and also use the ComComponent of the bLabel to write:
'Add here code to handle Min and Max changes
If Not String.IsNullOrEmpty(tbMax.Text) Then bLabel.ComComponent.Write("40002", tbMax.Text)
on your second pasted code, im getting an error "m_PLCaddressKeypad is not declared.
Here, you have to double check all the code since your "m_PLCaddressKeypad has an odd character " in front of the name and the lower case "a" in the address. You should have just copy/pasted the code I posted over the same sub.
Regards, Rox
EDIT: There is additional code added to check if the textbox value was empty/nothing since the Modbus driver might throw an exception if the textbox is left empty and button OK was clicked.