Touchscreen System button help.

DouglasBell

Active member
Joined
Aug 16, 2011
Messages
38
Programming Experience
Beginner
Hi All

I have a form with 10 buttons, these buttons are dynamic based on what is in an ini file. The whole system works great but it is a nightmare to manage the content as the whole program works on this ini file and at the moment the ini file is 4000 lines long so if I have to change a button, add a button or delete a button I have to almost reorganize 4000 lines.

So what I would like is to find a better way for my dynamic buttons, even at 4000 lines the program is very very fast so I dont want to lose this. My thoughts initially were to have a database for the buttons but I am just not sure how to deal with this as my main menu might be.

A B C D E F G H I J

If you push button A it may have another 10 sub headings, then if you push a subheading it may have another 10 underneath, so each button may have multiple sub levels, this Touchscreen system is used in many areas so at the moment I just redo the ini file and it configures the touchscreen menu system, so the Touchscreen system is completly dynamic so it has multiuse.

Has anyone here come up with or use a system similar and can give me some pointers on how to handle the buttons using a Database so it is easier to manage buttons, or are there better ways to do it, also the sub levels must be dynamic too as there could be 2 or 20 depending on the choices.

Cheers

Dj
 
You should look to Xml, it is a much better option than ini.
 
Hi

I will post an extract from my ini file but to be honest it won't tell you much. As for XML, I did look into it but it is just as complicated if not more for its structure than a basic ini file is, and it would probably end up being more lines than the ini file (the way I would do it for what I know) also for me the ini file was much easier to implement.
 
I believe the reason JohnH suggested XML is not because it would result in a smaller file but because it will be much simpler to work with (once you learn how, of course). There are features built in to the .NET Framework that make dealing with XML very simple. There are no built in features for dealing with ini files in the Framework (I would guess because it is an obsolete, outdated format). Also, XML is perfect for storing the tree like structure you describe; ini not so much. Plus 4,000 lines is a relatively small file; programs today should have no problem handling a file of that size (of course it depends on how long each line is).

There is also the Application Settings architecture built in to the framework that saves application settings in XML format. You may be able to use this.
 
Last edited:
Hi

Thanks for the replys. Could you give me a quick example of how you would do a button setup using an XML file and how you would use this in VB.net

Cheers

DJ
 
Hi, ok I will post an extract of my ini file, will take me a while as I will have to go through it and change all the sensitive data.
 
Actually, probably easier just quickly making one up.

[MainButtons]. /// This tells what the main buttons will be on load, I have shown 4 but I have around 30 on one system.
Button1=Breakdown
Button2=Maintenance
Button3=Meal Breaks
Button4=Quality

[Breakdown]. /// When you press breakdown on the main buttons, the buttons change to the following items, again I have a lot more items on the full program.
Button1=Sensor Fault
Button2=PLC Fault
Button3=Motor / Belt Fault

[Breakdown PLC Fault] /// if you press button 2 PLC Fault the buttons refresh and display the following.
Button1=Dead Battery
Button2=Digital Input Fault
Button3=Digital Output Fault
Button4=Program Fault
Button5=Expansion Card Fault

[Breakdown PLC Fault Program Fault] /// if you press button 4 Program Fault you get the following buttons.
Button1=No program
Button2=Incorrect Prameters


So the above is just an example but you can have lots of sub levels with lots of buttons on each selection, I have 10 buttons on the form, if there are more than 10 items in a section then I have a next page button that becomes visable that will allow you to scroll through if there is less than 10 then the extra buttons get hidden. Hoe this helps.

Cheers

Dj
 
I would agree with XML and maybe use LINQ for querying the file. I suppose it depends if you want to spend time learning something (assuming you dont know xml and linq) or if you want a better way of querying what you have?

Database would work too ofcourse if you dont mind using them.
 
Hi

I have decided to go down the route of XML as I seen a great tutorial on using the treeview to read and write XML files, This allows me to graphically create my menu structure and maintain it much easier than just going through the text in the ini file. So far I have created my TreeView interface and have played with creating and exporting the XML structure, this works great. Now I just need to figure out how to work with the XML nodes to create my buttons, getting the main buttons is easy enough as I just pull the main nodes, now working on the onclick event to change the buttons to reflect the next levels of buttons.

Cheers for the help so far.

Dj
 
You have a tree of button nodes and you will at any given time have a root node, which parents the current button level. 'Main buttons' is at the root node of the document, and when you select one of those buttons that becomes the current root. So you just have to keep track of that dynamic root node.

I had a play with this, and I'm not sure how accurate your forum profile is, but this is probably something along the lines of what I would do in .Net 4.
Using this xml structure (simplified, just added more than 10 nodes to 'Breakdown' to test paging):
HTML:
<buttons>
  <button text="Breakdown">
    <button text="Sensor Fault"/>
    <button text="PLC Fault"/>
    <button text="Motor / Belt Fault"/>
    <button text="4"/>
    <button text="5"/>
    <button text="6"/>
    <button text="7"/>
    <button text="8"/>
    <button text="9"/>
    <button text="10"/>
    <button text="11"/>
  </button>
  <button text="Maintenance"/>"
  <button text="Meal Breaks"/>"
  <button text="Quality"/>"
</buttons>
Then a few simple turns with Linq to Xml. I used FlowLayoutPanel as container, saves laying things out manually. Added a 'Up level' button also.
    Private doc As XDocument, root As XElement
    Private page, pagecount As Integer

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        doc = XDocument.Load("buttons.xml")
        SetRoot(doc.Root)
        CreateButtons()
    End Sub

    Private Sub Buttons_Click(sender As Object, e As EventArgs)
        SetRoot(CType(CType(sender, Button).Tag, XElement))
        CreateButtons()
    End Sub

    Private Sub SetRoot(root As XElement)
        Me.root = root
        Me.pagecount = CInt(Math.Ceiling(root.<button>.Count / 10))
        Me.page = 1
        Me.ButtonNext.Enabled = pagecount > 1
        Me.ButtonUp.Enabled = Me.root.Parent IsNot Nothing
    End Sub

    Private Sub ClearButtons()
        For Each c In Me.FlowLayoutPanel1.Controls.OfType(Of Button)()
            RemoveHandler c.Click, AddressOf Buttons_Click
        Next
        Me.FlowLayoutPanel1.Controls.Clear()
    End Sub

    Private Sub CreateButtons()
        ClearButtons()
        Dim buttons = From b In root.<button> Skip (page - 1) * 10 Take 10
        For Each b In buttons
            Dim c As New Button
            c.Text = b.@text
            c.Tag = b 'storing the XElement reference in button controls Tag
            AddHandler c.Click, AddressOf Buttons_Click
            Me.FlowLayoutPanel1.Controls.Add(c)
        Next
    End Sub

    Private Sub ButtonNext_Click(sender As System.Object, e As System.EventArgs) Handles ButtonNext.Click
        page = If(page = pagecount, 1, page + 1)
        CreateButtons()
    End Sub

    Private Sub ButtonUp_Click(sender As System.Object, e As System.EventArgs) Handles ButtonUp.Click
        SetRoot(Me.root.Parent)
        CreateButtons()
    End Sub
 
Hi JohnH

Thanks for the reply, unfortuantly I dont use .NET 4.0 only 3.0 at the moment due to company restrictions. After creating a test menu with the treeview I have found a few problems with the XML file, the Treeview uses serialization to make it easier to save and load from the XML file but it makes it a little bit of a jumble, well for me anyway. Here is the XML File, the picture shows what the menu looks like.

Capture.JPG

HTML:
<?xml version="1.0" ?> 
- <TreeViewData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <Nodes>
- <TreeNodeData>
<Text>Fruit</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>true</Expanded> 
- <Nodes>
- <TreeNodeData>
<Text>Apple</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
- <TreeNodeData>
<Text>Orange</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
- <TreeNodeData>
<Text>Berries</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>true</Expanded> 
- <Nodes>
- <TreeNodeData>
<Text>Strawberry</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
- <TreeNodeData>
<Text>Blackberry</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
</Nodes>
</TreeNodeData>
</Nodes>
</TreeNodeData>
- <TreeNodeData>
<Text>Vegetables</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>true</Expanded> 
- <Nodes>
- <TreeNodeData>
<Text>Carrots</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
- <TreeNodeData>
<Text>Brocolli</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
- <TreeNodeData>
<Text>Pease</Text> 
<ImageIndex>1</ImageIndex> 
<SelectedImageIndex>2</SelectedImageIndex> 
<Checked>false</Checked> 
<Expanded>false</Expanded> 
</TreeNodeData>
</Nodes>
</TreeNodeData>
</Nodes>
</TreeViewData>
 
Hi All

Ok a little further in using the XML file posted above I now have my program look through the XML file and pickup the main buttons on load. I am struggling on how to get my sublevels working on the onclick event but I am working through this, here is how I am picking up the main buttons, is this a good method or is there a better way to do it.

VB.NET:
 Dim xmldoc As New XmlDataDocument()
        Dim xmlnode As XmlNodeList
        Dim i As Integer
        Dim str As String
        Dim fs As New FileStream("D:\TreeView.xml", FileMode.Open, FileAccess.Read)
        xmldoc.Load(fs)
        xmlnode = xmldoc.GetElementsByTagName("Nodes")
        If xmlnode(0).ChildNodes.Count > 10 Then
            BtnNext.Visible = True
        Else
            BtnNext.Visible = False
        End If
        Try
            Button1.Text = xmlnode(0).ChildNodes.Item(0).ChildNodes.Item(0).InnerText
            Button2.Text = xmlnode(0).ChildNodes.Item(1).ChildNodes.Item(0).InnerText
            Button3.Text = xmlnode(0).ChildNodes.Item(2).ChildNodes.Item(0).InnerText
            Button4.Text = xmlnode(0).ChildNodes.Item(3).ChildNodes.Item(0).InnerText
            Button5.Text = xmlnode(0).ChildNodes.Item(4).ChildNodes.Item(0).InnerText
            Button6.Text = xmlnode(0).ChildNodes.Item(5).ChildNodes.Item(0).InnerText
            Button7.Text = xmlnode(0).ChildNodes.Item(6).ChildNodes.Item(0).InnerText
            Button8.Text = xmlnode(0).ChildNodes.Item(7).ChildNodes.Item(0).InnerText
            Button9.Text = xmlnode(0).ChildNodes.Item(8).ChildNodes.Item(0).InnerText
            Button10.Text = xmlnode(0).ChildNodes.Item(9).ChildNodes.Item(0).InnerText
        Catch ex As Exception
        End Try
        ' Next
        fs.Close()
        CheckButtons()

Cheers

Dj
 
Hi All

I am still struggling to pull sub levels dynamically (So I dont have to program a routine for each level as that would mean I would have to edit the program everytime a new sub level that had not been programmed for was introduced) from the above, any help is appreciated.

Regards

DJ
 
Back
Top