Author Topic: Line shape as AHMI control  (Read 5856 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Line shape as AHMI control
« on: January 13, 2015, 11:19:20 AM »
Hi Archie. I'm wondering if it's possible to make the Lineshape control of VS an AHMI control where color can be assigned by bit and possibly rotation as well. Or is there a different VS control that has similar function as the LineShape that I haven't found yet? Is this out of the realm of possibilities?  Thanks.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Line shape as AHMI control
« Reply #1 on: January 13, 2015, 11:30:15 AM »
The LineShape is considered a standard Windows control. It can be made into an AdvancedHMI control, but requires a little knowledge of VB.

- You would start with an existing AdvancedHMI control that has similar functionality.
- Make a copy of that control, then rename it to something unique
- Edit the newly copied file and change the class name to what you want to call your AdvancedHMI LineShape
- Near the top of the file you will see a line of code that start with "Inherits"
- Change what is inherited to the LineShape (you may need the fully qualified name of Microsoft.VisualBasic.PowerPacks.LineShape
- Then it will require some editing to fix any errors

This is kind of a summary because it is too much detail to walk through all of it in a forum post.

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Line shape as AHMI control
« Reply #2 on: January 13, 2015, 10:51:00 PM »
Tried to use the basic indicator since it has a color selection feature using your Aquagage instructions....  failed miserably!  Oh well, Not that big of an issue.  I can get along writing the code if its not possible.  It would be a nice addition if anyone wants to try and let me know how to do it. Thanks     

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Line shape as AHMI control
« Reply #3 on: January 13, 2015, 11:46:38 PM »
One of the later posts has a better choice for the line control. See further below.

Here are 3 separate and simple controls that allow for horizontal, vertical and diagonal line drawing (no rotation on either). Each one responds to a single bit on both fields: PLCAddressValue and PLCAddressVisible.

Diagonal line can be created Left-to-Right or Right-to-Left under almost any angle.
Horizontal line is created when rectangle width > height.
Vertical line is created when rectangle width < height.
If I ever manage to put all 3 in a single control, it will be posted here.

It was created in v3.97a and from the BarLevel control. Rotation feature might come in the future ... if I manage to figure it out.

The idea behind this was originally posted here: http://www.vbforums.com/showthread.php?657238-RESOLVED-LineShape-control

Edit: Check the last post for almost a perfect replacement for LineShape control
« Last Edit: April 11, 2015, 02:56:13 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Line shape as AHMI control
« Reply #4 on: January 14, 2015, 01:58:47 PM »
I took a closer look at this. Inheriting the LineShape is a bit more complicated because of the LineShape architecture. In a .NET sense, it is not truly a Control and does not have a handle. It is more like a component, such as a DataSubscriber.

The bottom line is, that it will not be quite as straight forward as I initially thought.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Line shape as AHMI control
« Reply #5 on: February 24, 2015, 10:18:55 PM »
I did manage to slightly improve the code and squeeze it into 2 separate controls (Left-to-Right and Right-to-Left).

Both allow for transparent backcolor and either control can create horizontal or vertical line if the width or height has been resized to minimum size. As suggested previously these respond to 2 PLCAddress fields and appear to be flicker free.

It is easy to add these to Purchased Controls folder as Existing Item, and then to rebuild the project in order to use them.


EDIT: The code has been improved for the 2 above mentioned controls. They have been merged into a single control, LineShape.vb, which is attached as of March 27, 2016 (the other 2 controls were removed). There are new properties that allow changing the slope of the line and changing the line DashStyle. AHMI v3.99d file is also attached.


I did also manage to convert to VB Net and AHMI a line control found here:

http://www.codeproject.com/Articles/538513/A-Better-Line-Control

It is very similar to LineShape from VB Power Pack but it has a lot of flicker. Converting this project was rather tricky and I wouldn't really recommend it for use as AHMI control. It is posted under The Code Project Open License (CPOL) and has several files that need to be converted, just in case if anybody feels like trying to do it (Archie would probably the only person who could possibly improve the way this control works).
« Last Edit: April 08, 2016, 10:31:13 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Line shape as AHMI control
« Reply #6 on: February 25, 2015, 11:48:38 AM »
I did also manage to convert to VB Net and AHMI a line control found here:

http://www.codeproject.com/Articles/538513/A-Better-Line-Control

It is very similar to LineShape from VB Power Pack but it has a lot of flicker. Converting this project was rather tricky and I wouldn't really recommend it for use as AHMI control. It is posted under The Code Project Open License (CPOL) and has several files that need to be converted, just in case if anybody feels like trying to do it (Archie would probably the only person who could possibly improve the way this control works).
If you are using Visual Studio Community Edition or Professional, this line control is added quite easily.

1) Download and extract the source code from the CodeProject web site above
2) Copy the folder \AwesomeShapeControl to your AdvancedHMI Solution folder (the same directory with \AdvancedHMI, \AdvancedHMIControls, and \AdvancedHMIDrivers)
3) Open AdvancedHMI is Visual Studio
4) In Solution Explorer, right click the Solution and select Add Existing Project
5) Browse to and select \AwesomeShapeControl\AwesomeShapeControl.csproj
6) Build the Solution
7) You should now have another group in your ToolBox with the new Line

This is possible because Visual Studio allows you to mix VB and C# projects in the same solution. If you are using an older Express version, then this will not be possible.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Line shape as AHMI control
« Reply #7 on: February 27, 2015, 08:16:06 PM »
I just discovered that this Awesome Shape Control project was compiled as DLL, so it gets better for all versions of Visual Studio in a sense that now all users can have this as AHMI control (which is close to being a perfect replacement for LineShape control).

You kind of have to be patient and slow moving while re-sizing the control with the mouse.

These would be the steps to follow:

1) Right click AdvancedHMI project and click "Add Reference" then browse to "AwesomeShapeControl\bin\debug" folder and select AwesomeShapeControl.dll
2) Do the same for AdvancedHMIControls project
3) Add the attached LineShapeHMI.vb file as Existing Item to "Purchased Controls" folder, close all open forms and rebuild the project.

Here is another way of adding any 3rd party DLL file to AHMI:
http://advancedhmi.com/forum/index.php?PHPSESSID=0d1de9331c3e49e7912a6acbc7d35aa8&topic=612.msg8033#msg8033


The line flicker was removed by adding couple of lines to base class.

The control appears to be working fine but certainly report any bug.
The file currently attached seems to have resolved all the issues I was aware of.

This control is kind of Christmassy since it allows each line to have its own LineColor, ON_Color and PLCAddressValue but still to have all the lines respond to a single PLCAddress if desired (check the attached picture for demo).

Edit: This control has been updated and the attached file replaced as of Mar 27, 2016. Also attached is AHMI v3.99d file.
« Last Edit: November 01, 2016, 02:10:31 PM by Godra »

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Line shape as AHMI control
« Reply #8 on: March 03, 2016, 10:59:15 PM »
Hi Godra, I have implemented this control and it works nicely.  Can I still access the coordinate properties X1X2Y1Y2?  I would like to cause rotation and have done this before using these properties.  Better yet, is there a way to add a rotation property to this control?  Thanks.

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Line shape as AHMI control
« Reply #9 on: March 04, 2016, 10:18:15 AM »
MrPike,

I am not quite sure but you could try adding these properties:

Code: [Select]
    '***************************************************************
    '* Property - StartPoint
    '***************************************************************
    <Browsable(True)> _
    Public Shadows Property StartPoint() As Point
        Get
            Return MyBase.StartPoint
        End Get
        Set(ByVal value As Point)
            If MyBase.StartPoint <> value Then
                MyBase.StartPoint = value
            End If
            Me.Invalidate()
        End Set
    End Property

    '***************************************************************
    '* Property - EndPoint
    '***************************************************************
    <Browsable(True)> _
    Public Shadows Property EndPoint() As Point
        Get
            Return MyBase.EndPoint
        End Get
        Set(ByVal value As Point)
            If MyBase.EndPoint <> value Then
                MyBase.EndPoint = value
            End If
            Me.Invalidate()
        End Set
    End Property

EDIT: These properties have been added and the files updated and replaced in previous post as of Mar 27, 2016.
« Last Edit: March 27, 2016, 10:37:44 PM by Godra »

Morgan

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: Line shape as AHMI control
« Reply #10 on: May 09, 2016, 03:38:40 PM »
Attached is a basic line control that includes PLC properties for three color choices and visibility.  The orientation is forced to vertical if the control width is <=10 and is forced to horizontal if the control height is <=10.  The angle of the line is determined by the control’s size and can be flipped by setting the “OrientationFlip” property.  The line width and type are adjustable through property settings. (modified 5/18/2016)
« Last Edit: May 18, 2016, 01:22:24 PM by Morgan »