dcsimg
Results 1 to 18 of 18

Thread: CustomControls

  1. #1

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    CustomControls

    Hi,

    Has anyone, built there own custom contols before.

    I might be asking beyond the VB.Net abilaty but i am looking at creating a Engineer Job board for my Support Desk program.

    Before this forum has offered, me with loads of help and advice.

    Basically i want the engineers job list across 2 tv screens. I have this at the moment using a DataGridView.

    But this doesnt look very appealing basically i thought about using lables to do this but passing data to the lables was the wrong way to go.

    Does anyone have any suggestions on the best way to achieve this at all or what control would be best to show the data.

    Name:  JobBoard.jpg
Views: 317
Size:  11.9 KB

    The above image shows the idea and what i am planning.

    Thanks James

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,082

    Re: CustomControls

    Hi James,

    I presume that your jobs display needs to be implemented first on a computer, otherwise it doesn't matter much what controls you use. How to split the data out to separate TV screens seems to me a separate question from other aspects.

    A DataGridView for laying out the jobs makes sense to me, particularly if you plan to link the data to a DataTable or database. Initially, the much simpler TableLayoutPanel might be sufficient for reproducing a layout like that shown in your image.

    I would choose Buttons rather than Labels for representing the individual jobs. Unlike a Label, a Button changes visibly in response to mouse hovering, selecting and clicking. And conveniently, the DataGridView can have button columns (see msdn).

    The button's click event would serve to display a dialog for editing job data such as the sequence number, column/row number, engineer's name, job description, start and end dates etc. This is besides using different background colours or font variations for attracting immediate attention, for example to indicate the job status, which are equally possible with labels.

    BB

  3. #3

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    Hi Boops Boops,

    I have drawn up some code already using a datagridveiw it does work to a point but it just doesnt look right.

    Code:
            Dim strings(My.Settings.ListBoxStrings.Count - 1) As String
            Dim items() As String = My.Settings.ListBoxStrings.Cast(Of Object).Select(Function(o) frmJobBoardSet.ListBox2.GetItemText(o)).ToArray
            Dim subsets() As Control = {Label1, Label2, Label3, Label4, Label5, Label6, Label7, Label8, Label9}
            Dim SubsetsDB() As DataGridView = {DataGridView1, DataGridView2, DataGridView3, DataGridView4, DataGridView5, DataGridView6, DataGridView7, DataGridView8, DataGridView9}
            Dim i As Integer
            Dim myfont As New Font("Microsoft Sans Serif", 18)
            Dim jobfont As New Font("Microsoft Sans Serif", 15)
            '0 = 1 so 0-7 = 8
            For i = 0 To 8
    
                subsets(i).Font = myfont
                subsets(i).Text = items(i)
    
                Dim Sqlcon As SqlConnection = New SqlConnection("Data Source=JAMESPC\SUPPORTDB;Initial Catalog=Support_DB;Persist Security Info=True;User ID=user;Password=Password")
                Dim QueryOpen As String = "select [Job Number], Customer, fault from ['Job info$'] where [Job Completed?] = 0 and [attended by] = '" & items(i) & "' and [Due on site] <= GETDATE() ORDER BY [job number] desc"
                Dim dataAdpt As New SqlDataAdapter(QueryOpen, Sqlcon)
                Dim ds As New DataSet()
    
                Sqlcon.Open()
                dataAdpt.Fill(ds, "['Job info$']")
                SubsetsDB(i).Font = jobfont
                SubsetsDB(i).ForeColor = Color.Green
                SubsetsDB(i).BackgroundColor = Color.Black
                SubsetsDB(i).DefaultCellStyle.BackColor = Color.Black
                SubsetsDB(i).AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
                SubsetsDB(i).AutoResizeColumns()
                SubsetsDB(i).DataSource = ds.Tables("['Job info$']")
    
            Next i
    Wanted it to be kind of like this.

    Attachment 169763

    I may just have to try re-designing the old Access jobboard and point it to my SQL DB and try requery it with SQL Querys etc.

    Thanks James

  4. #4
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: CustomControls

    Quote Originally Posted by VBJames View Post
    Wanted it to be kind of like this.

    Attachment 169763

    I may just have to try re-designing the old Access jobboard and point it to my SQL DB and try requery it with SQL Querys etc.

    Thanks James
    I don't see an image of the attachment of what you want it to look like?

    It appears you are making multiple DGVs but a DGV is like a spread sheet you would put one data point in each cell etc. No other controls required?

    Are your two monitor displays always the same size? Do they line up at top? Will the image show us what the finished product looks like (both monitors)? And sample data?

    I am not sure what you mean by "custom control" exactly. Seems a basic form with a dgv (or whatever) would do? Draw your own even? Explain that logic more please.

  5. #5
    Administrator Steve R Jones's Avatar
    Join Date
    Apr 2012
    Location
    Dallas, TX
    Posts
    1,025

    Re: CustomControls

    Quote Originally Posted by VBJames View Post
    We can't see the attachment. Try again.

  6. #6
    Administrator Steve R Jones's Avatar
    Join Date
    Apr 2012
    Location
    Dallas, TX
    Posts
    1,025

    Re: CustomControls

    Quote Originally Posted by VBJames View Post
    We can't see the attachment. Try again.

  7. #7
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,082

    Re: CustomControls

    Quote Originally Posted by Steve R Jones View Post
    We can't see the attachment. Try again.
    Aha, another victim of the double-posting gotcha. I wonder who's responsible for fixing that...?

    BB

  8. #8

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    Sorry, here is the attachment Name:  Jboard.jpg
Views: 101
Size:  30.6 KB

  9. #9
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: CustomControls

    To try and answer the first question yes you can make a control or etc to do what you want more or less. It is hard to say exactly without understanding exactly what you want to do. What is the app? A one form app with the board? A database.

    Here is a start on a draw your own version. You can compare with other methods like dgv or layout panel or combination even. Drawing like this gives you the most options on what you can do with the display.

    The example has a simple class structure and lists that are drawn on a picturebox by looping through the lists.

    There are still lots of improvements and details to work out of course.

    Is that the type of thing you had in mind?

    Name:  a2.png
Views: 95
Size:  76.1 KB

    Code:
    Public Class Form5
        Private Class DataEX
            Public ITC As String
            Public Job As String
            Public Text As String
        End Class
        Private DataList1 As New List(Of DataEX)
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ClientSize = New Size(900, 400)
            BackColor = Color.DimGray
    
            For i As Integer = 1 To 3
                Dim d1 As New DataEX
                d1.ITC = "Click ITC"
                d1.Job = "54074"
                d1.Text = "DDS Job Board Control Concept. Authorized under section 21 cfr. Awaiting design commitee recomendations. "
                DataList1.Add(d1)
            Next
        End Sub
    
        Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            Dim border As Integer = 20
            Dim widthp As Integer = 400
    
            DrawJobList(e.Graphics, New Rectangle(border, border, widthp,
                                                  ClientSize.Height - (border * 2)), DataList1, "James")
            DrawJobList(e.Graphics, New Rectangle(border + (1 * (widthp + border)), border, widthp,
                                                  ClientSize.Height - (border * 2)), DataList1, "Sheila")
            DrawJobList(e.Graphics, New Rectangle(border + (2 * (widthp + border)), border, widthp,
                                                  ClientSize.Height - (border * 2)), DataList1, "Tommy")
            DrawJobList(e.Graphics, New Rectangle(border + (3 * (widthp + border)), border, widthp,
                                                  ClientSize.Height - (border * 2)), DataList1, "Other")
        End Sub
    
        Private Sub DrawJobList(g As Graphics, rect As Rectangle, dataList As List(Of DataEX), heading As String)
            Dim rh As Double = 0.7 * rect.Width
    
            With g
                .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    
                Using brHeading As New SolidBrush(Color.White),
                        brText As New SolidBrush(Color.SkyBlue),
                        fHeading As New Font("tahoma", CSng(rh / 18), FontStyle.Bold),
                        fsubject As New Font("arial", CSng(rh / 22), FontStyle.Bold),
                        ftext As New Font("arial", CSng(rh / 24))
    
                    .FillRectangle(Brushes.Black, rect)
    
                    'heading
                    .DrawString(heading, fHeading, brHeading, CInt(rect.X + (0.3 * rect.Width)), CInt(rect.Y + +(0.05 * rh)))
    
                    Dim y1 As Integer
                    Dim rectTxt As Rectangle
    
                    For i As Integer = 0 To dataList.Count - 1
                        'sub titles
                        y1 = CInt(rect.Y + (i * rh * 0.3) + (rh * 0.2))
                        .DrawString(dataList(i).ITC, fsubject, brHeading, CInt(rect.X + (rh * 0.02)), y1)
                        .DrawString(dataList(i).Job, fsubject, brHeading, CInt(rect.X + rect.Width * 0.8), y1)
    
                        'text block
                        rectTxt = New Rectangle(CInt(rect.X + (rh * 0.02)), CInt(y1 + (rh * 0.1)),
                                                CInt(rect.Width - (rh * 0.04)), CInt(rh * 0.15))
                        .DrawString(dataList(i).Text, ftext, brText, rectTxt)
    
                        .DrawLine(Pens.White, rectTxt.X, rectTxt.Y + rectTxt.Height,
                                  rectTxt.X + rectTxt.Width, rectTxt.Y + rectTxt.Height)
                    Next
                End Using
            End With
        End Sub
    End Class

  10. #10

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    Hi Tommytwotrain.

    Thanks for getting back to basically, its a job board for 9 enginners all pulled from a SQL DB backend there is also a support desk app for logging and customer & supplier information.

    Each job on the Job board will have these 3 fields

    1) Company Name
    2) Job Number
    3) Fault

    It could be built as a seperate app that looks at the SQL backend and can be launched from the support desk app.

    The job board will be spread across 2 TV screens so all open jobs for each eng can be viewed.

    Attachment 169857

    In the image above each number is a enginner which at the moment is picked up from a list saved in the app.config of the application.

    This can edited by the Application administrator if a enginner leaves or a new one joins.

    I wish i could put a image up of the current Job Board but with all the data protection and GDPR i cannot .

    Any questions please ask

  11. #11

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    Hi Tommytwotrain,

    I have edited your code to include the SQL Query for the jobs and the list of Engineers 1-9 but it only writes one table.

    Code:
    Imports System.Data.SqlClient
    Imports System.Data.SqlClient.SqlConnection
    Imports System.Configuration
    Public Class Form5
    
        Private Class DataEX
            'Public Customer As DataTable
            'Public Job As DataTable
            'Public Text As DataTable
            Public Customer As String
            Public Job As String
            Public Text As String
    
        End Class
        Private DataList1 As New List(Of DataEX)
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ClientSize = New Size(1360, 768)
            BackColor = Color.Black
            Dim Sqlcon As SqlConnection = New SqlConnection("Data Source=JAMESPC\SUPPORTDB;Initial Catalog=Support_DB;Persist Security Info=True;User ID=user;Password=password")
            Dim SQLcmd As SqlCommand
            D        Dim SQLcmd As SqlCommand
            Dim QueryOpen As String = "select Customer, [Job Number], fault from ['Job info$'] where [Job Completed?] = 0 and [attended by] = 'James' and [Due on site] <= GETDATE() ORDER BY [job number] desc"
            Dim dataAdpt As New SqlDataAdapter(QueryOpen, Sqlcon)
            Dim ds As New DataSet()
            SQLcmd = New SqlCommand(QueryOpen, Sqlcon)
            Sqlcon.Open()
            Using reader = SQlcmd.executereader()
                While reader.Read()
                    For i As Integer = 1 To 1
                        Dim d1 As New DataEX
                        d1.Customer = reader.GetString(reader.GetOrdinal("Customer"))
                        d1.Job = reader.GetInt32(reader.GetOrdinal("Job Number"))
                        d1.Text = reader.GetString(reader.GetOrdinal("fault"))
                        DataList1.Add(d1)
                    Next
                End While
            End Using
        End Sub
        End Sub
    
        Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            Dim border As Integer = 20
            Dim widthp As Integer = 400
            Dim items() As String = {"Eng1", "Eng2", "Eng3", "Eng4", "Eng5", "Eng6", "Eng7", "Eng8", "Eng9"}.ToArray
            Dim i As Integer
            For i = 0 To 8
    
                DrawJobList(e.Graphics, New Rectangle(border, border, widthp,
                                                 ClientSize.Height - (border * 2)), DataList1, items(i))
    
            Next i
        End Sub
    
        Private Sub DrawJobList(g As Graphics, rect As Rectangle, dataList As List(Of DataEX), heading As String)
            Dim rh As Double = 0.7 * rect.Width
    
            With g
                .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    
                Using brHeading As New SolidBrush(Color.White),
                        brText As New SolidBrush(Color.Green),
                        fHeading As New Font("arial", CSng(rh / 18), FontStyle.Bold),
                        fsubject As New Font("arial", CSng(rh / 22), FontStyle.Bold),
                        ftext As New Font("arial", CSng(rh / 24))
    
                    .FillRectangle(Brushes.Black, rect)
    
                    'heading
                    .DrawString(heading, fHeading, brHeading, CInt(rect.X + (0.3 * rect.Width)), CInt(rect.Y + +(0.05 * rh)))
    
                    Dim y1 As Integer
                    Dim rectTxt As Rectangle
    
                    For i As Integer = 0 To dataList.Count - 1
                        'sub titles
                        y1 = CInt(rect.Y + (i * rh * 0.3) + (rh * 0.2))
                        .DrawString(dataList(i).Customer, fsubject, brHeading, CInt(rect.X + (rh * 0.02)), y1)
                        .DrawString(dataList(i).Job, fsubject, brHeading, CInt(rect.X + rect.Width * 0.8), y1)
    
                        'text block
                        rectTxt = New Rectangle(CInt(rect.X + (rh * 0.02)), CInt(y1 + (rh * 0.1)),
                                                CInt(rect.Width - (rh * 0.04)), CInt(rh * 0.15))
                        .DrawString(dataList(i).Text, ftext, brText, rectTxt)
    
                        .DrawLine(Pens.White, rectTxt.X, rectTxt.Y + rectTxt.Height,
                                  rectTxt.X + rectTxt.Width, rectTxt.Y + rectTxt.Height)
                    Next
                End Using
            End With
        End Sub
    End Class
    I am struggling getting the Drawjoblist for another engineer rather than having one and replacing the text through the array.

    Thanks James

  12. #12
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: CustomControls

    James,

    Note I just printed the same datalist1 four times in the paint event. So it appears you are still doing that? Same datalist1 eight times?

    In the form load you should make a list of datalists. Then if you have four engineers you have four datalist1 ie:

    Code:
      Private DataLists as new ListOf( list of (DataEx).
    
      For i = 1 to 4  
    
       datalists.add(datalist1)
    
      next
    Or make four datalists ie datalist1, datalist2, datalist3... or whatever?? Maybe you don't need any lists you can just read the data from dbase as required? Not my specialty.

    BTW your last attachment is not showing again.
    Last edited by tommytwotrain; Jul 15th, 2019 at 01:35 PM.

  13. #13

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    Hi Tommytwotrains

    I am testing on what you advised my current code:

    Code:
    Imports System.Data.SqlClient
    Imports System.Data.SqlClient.SqlConnection
    Imports System.Configuration
    Public Class Form5
        Public items() As String = {"Matthew", "Jacob", "Other", "Mr Wobble", "Martin", "Paul", "Alison", "Nik", "James"}.ToArray
        Public i As Integer
        Private Class DataEX
            'Public Customer As DataTable
            'Public Job As DataTable
            'Public Text As DataTable
            Public Customer As String
            Public Job As String
            Public Text As String
    
        End Class
        Private DataList1 As New List(Of DataEX)
        Private DataLists As New List(Of DataEX)
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ClientSize = New Size(4000, 2000)
            BackColor = Color.Black
            Dim Sqlcon As SqlConnection = New SqlConnection("Data Source=JAMESPC\SUPPORTDB;Initial Catalog=Support_DB;Persist Security Info=True;User ID=user;Password=password")
            Dim SQLcmd As SqlCommand
            Dim QueryOpen As String = "select Customer, [Job Number], fault from ['Job info$'] where [Job Completed?] = 0 and [attended by] =  '" & items(i) & "' and [Due on site] <= GETDATE() ORDER BY [job number] desc"
            Dim dataAdpt As New SqlDataAdapter(QueryOpen, Sqlcon)
            Dim ds As New DataSet()
    
            SQLcmd = New SqlCommand(QueryOpen, Sqlcon)
            Sqlcon.Open()
    
            For i = 1 To 8
                DataLists.Add(DataList1)
                dataAdpt.Fill(ds, "['Job info$']")
                Using reader = SQLcmd.ExecuteReader()
                    While reader.Read()
                        For i As Integer = 1 To 1
                            Dim d1 As New DataEX
                            d1.Customer = reader.GetString(reader.GetOrdinal("Customer"))
                            d1.Job = reader.GetInt32(reader.GetOrdinal("Job Number"))
                            d1.Text = reader.GetString(reader.GetOrdinal("fault"))
                            DataList1.Add(d1)
                        Next i
                    End While
                End Using
            Next
        End Sub
    
        Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            Dim border As Integer = 20
            Dim widthp As Integer = 400
    
            For i = 0 To 8
    
                DrawJobList(e.Graphics, New Rectangle(border, border, widthp,
                                             ClientSize.Height - (border * 2)), DataList1, items(i))
    
            Next
    
        End Sub
    
        Private Sub DrawJobList(g As Graphics, rect As Rectangle, dataList As List(Of DataEX), heading As String)
            Dim rh As Double = 0.7 * rect.Width
    
            With g
                .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    
                Using brHeading As New SolidBrush(Color.White),
                        brText As New SolidBrush(Color.Green),
                        fHeading As New Font("arial", CSng(rh / 18), FontStyle.Bold),
                        fsubject As New Font("arial", CSng(rh / 22), FontStyle.Bold),
                        ftext As New Font("arial", CSng(rh / 24))
    
                    .FillRectangle(Brushes.Black, rect)
    
                    'heading
                    .DrawString(heading, fHeading, brHeading, CInt(rect.X + (0.3 * rect.Width)), CInt(rect.Y + +(0.05 * rh)))
    
                    Dim y1 As Integer
                    Dim rectTxt As Rectangle
    
                    For i As Integer = 0 To dataList.Count - 1
                        'sub titles
                        y1 = CInt(rect.Y + (i * rh * 0.3) + (rh * 0.2))
                        .DrawString(dataList(i).Customer, fsubject, brHeading, CInt(rect.X + (rh * 0.02)), y1)
                        .DrawString(dataList(i).Job, fsubject, brHeading, CInt(rect.X + rect.Width * 0.8), y1)
    
                        'text block
                        rectTxt = New Rectangle(CInt(rect.X + (rh * 0.02)), CInt(y1 + (rh * 0.1)),
                                                CInt(rect.Width - (rh * 0.04)), CInt(rh * 0.15))
                        .DrawString(dataList(i).Text, ftext, brText, rectTxt)
    
                        .DrawLine(Pens.White, rectTxt.X, rectTxt.Y + rectTxt.Height,
                                  rectTxt.X + rectTxt.Width, rectTxt.Y + rectTxt.Height)
                    Next
                End Using
            End With
        End Sub
    End Class
    But it is erroring on this part of code:

    Code:
    DataLists.Add(DataList1)
    Name:  CodeError.jpg
Views: 53
Size:  15.0 KB

    I am going to have a further tinker later this afternoon.

    Thanks for your assistance so far.

  14. #14
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: CustomControls

    James,

    First off your attachment image of something does not show in your post #10 above !!!!! So if you want us to see it you need to fix it or show it again please.

    On you comment, you did not use the list declare as I showed in post @12. DataLists is a List of multiple DataList1 which are a list of DataEx.

    So what you want to make is a list of lists of DataEx.

    You have a Datalist1, lets call it MatthewList of DataEx. And you have JacobList of DataEx.... Now you want a list of the lists. So DataLists is made like:

    DataLists.add(MatthewList)
    DataLists.add(JacobList)

    then

    DataLists(0) is MathewList
    DataLists(1) is JacobList

    You should make a practice example in a test project first. Then put into your big project after you understand it and have it working.

    Plus I am not saying that a list of lists is the best way to do it. It is just a possible way. If you can just read the reconds from the database then you dont need the lists?

    Maybe others will have suggestions?
    Last edited by tommytwotrain; Jul 16th, 2019 at 08:59 AM.

  15. #15

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    The image in post #10 is


    Name:  JobBoard.jpg
Views: 44
Size:  11.9 KB


    Each number represents a engineer.

  16. #16
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: CustomControls

    There are lots of ways to do it of course. Its the kind of thing a person can play with endlessly.

    This example has added an engineeer class with name and jobs list for each engineer.

    You can see where the names are used in an engr class object and then a list of jobs (Class JobEx was DataEx) is made for each engr.

    The engr with name and list of jobs is added to the list of engineers. A List of lists.

    Name:  a1.png
Views: 38
Size:  62.8 KB

    Code:
    'job status board
    Public Class Form5
        Private Class Engineer
            Public Name As String
            Public Jobs As New List(Of JobEX)
        End Class
    
        Private Class JobEX
            Public ITC As String
            Public Job As String
            Public Text As String
        End Class
    
        Private Engineers As New List(Of Engineer)
        Private border As Integer = 10
        Private widthp As Integer = 200         'jobs panel size
        Private heightp As Integer = 150
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ClientSize = New Size(border + (4 * (border + widthp)), border + (3 * (border + heightp)))
            Text = "Job Board"
            BackgroundImage = Image.FromFile("c:\bitmaps\apple1.png")
            BackgroundImageLayout = ImageLayout.Stretch
    
            'make the list of engineers
            Dim namelist() As String = Split("Engineer 1, Engineer 2, Engineer 3, Engineer 4, Engineer 5, Engineer 6, Engineer 7, Engineer 8, Engineer 9", ",")
    
            For i As Integer = 0 To 8
                Dim engr As New Engineer
                engr.Name = namelist(i)
                Engineers.Add(engr)
    
                'make the job list for this engr
                For j As Integer = 1 To 3
                    Dim d1 As New JobEX
                    d1.ITC = "Click ITC"
                    d1.Job = (i * j).ToString & "00"
                    d1.Text = engr.Name & " DDS Job Board Control Concept. Awaiting design commitee recomendations. "
                    engr.Jobs.Add(d1)
                Next
            Next
        End Sub
    
        Private Sub Form5_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            'draw the form backgound
            Dim linGrBrush As New Drawing2D.LinearGradientBrush(
                            New Point(0, 0), New Point(0, ClientSize.Height),
                            Color.FromArgb(200, Color.DimGray), Color.FromArgb(150, Color.Black))
            e.Graphics.FillRectangle(linGrBrush, ClientRectangle)
    
            'make the display rectangle for each engineer and draw jobs
            Dim x, y, y1 As Integer
            y1 = (2 * border) + heightp
    
            For engr As Integer = 0 To 8
                'locate each job rect by x, y upper left
                Select Case engr
                    Case 0 : x = border : y = border
                    Case 1 : x = 2 * border + widthp : y = border
                    Case 2 : x = 3 * border + (2 * widthp) : y = border
                    Case 3 : x = 4 * border + (3 * widthp) : y = border
                    Case 4 : x = border : y = y1
                    Case 5 : x = 2 * border + widthp : y = y1
                    Case 6 : x = 2 * border + widthp : y = y1 + border + heightp
                    Case 7 : x = 3 * border + (2 * widthp) : y = y1
                    Case 8 : x = 4 * border + (3 * widthp) : y = y1
                End Select
    
                DrawJobList(e.Graphics, New Rectangle(x, y, widthp, heightp), Engineers(engr))
            Next
        End Sub
    
        Private Sub DrawJobList(g As Graphics, rect As Rectangle, engr As Engineer)
    
            Dim rh As Double = 0.7 * rect.Width         'adjust width to height ratio
    
            With g
                .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    
                'scale sizes based on rect size
                Using brHeading As New SolidBrush(Color.AntiqueWhite),
                       brsubject As New SolidBrush(Color.AntiqueWhite),
                        brText As New SolidBrush(Color.White),
                        fHeading As New Font("tahoma", CSng(rh / 14), FontStyle.Bold),
                        fsubject As New Font("arial", CSng(rh / 22), FontStyle.Bold),
                        ftext As New Font("arial", CSng(rh / 24)),
                        pFrame As New Pen(Color.Black, 3),
                        brHeadingBg As New SolidBrush(Color.FromArgb(150, Color.Maroon))
    
                    'job rectangle background
                    .FillRectangle(Brushes.DimGray, rect)
                    .DrawRectangle(pFrame, rect)
    
                    'heading
                    .FillRectangle(brHeadingBg, New Rectangle(rect.X, rect.Y, rect.Width, CInt(rh / 6)))
                    .DrawString(engr.Name, fHeading, brHeading, CInt(rect.X + (0.3 * rect.Width)), CInt(rect.Y + (0.02 * rh)))
    
                    Dim y1 As Integer
                    Dim rectTxt As Rectangle
    
                    For i As Integer = 0 To engr.Jobs.Count - 1
                        'sub titles
                        y1 = CInt(rect.Y + (i * rh * 0.3) + (rh * 0.2))
                        .DrawString(engr.Jobs(i).ITC, fsubject, brsubject, CInt(rect.X + (rh * 0.02)), y1)
                        .DrawString(engr.Jobs(i).Job, fsubject, brsubject, CInt(rect.X + rect.Width * 0.8), y1)
    
                        'text block
                        rectTxt = New Rectangle(CInt(rect.X + (rh * 0.02)), CInt(y1 + (rh * 0.1)),
                                                CInt(rect.Width - (rh * 0.04)), CInt(rh * 0.15))
                        .DrawString(engr.Jobs(i).Text, ftext, brText, rectTxt)
    
                        'bottom line
                        .DrawLine(Pens.White, rectTxt.X, rectTxt.Y + rectTxt.Height,
                                  rectTxt.X + rectTxt.Width, rectTxt.Y + rectTxt.Height)
                    Next
                End Using
            End With
        End Sub
    End Class

  17. #17
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,082

    Re: CustomControls

    Quote Originally Posted by tommytwotrain View Post
    Maybe others will have suggestions?
    Hi James and Tommy, just some thoughts that may or may not be helpful. The thread title 'CustomControls' isn't irrelevant in my view, because using custom controls implies that you are taking more structured approach to your code. At the moment everything is poured into your Form5 class: data base access, list structure, visual design etc. This makes the code hard to develop and debug. I think your Job Board plans are going to be too complicated to deal with a single form.

    Structured code implies using separate Public classes for each kind of "object" in your program design. For example you could define one class to represent Engineer, another to represent Job, another to represent Customer etc.

    As you want to show these items on the screen, the usual way is make each class inherit from an existing control type (the base class Control, Button, Label etc.). That's what a Custom Control is. As I suggested in post #2, I think Buttons would be a good choice to start with for this purpose, and it's not hard to change if necessary.

    Here's a very brief sketch of how the classes might be coded:
    Code:
    Public Class Engineer
        Inherits Button
    
        Public Property EngineerName As String
        Public Property EngineerJobDescription As String
        Pubic Property JobHistory As New List(Of Job)
        Public Property Public Property CurrentJob As Job
        'etc.
    End Class
    Code:
    Public Class Job
         Inherits Button
    
         Enum Status
             Scheduled
             Delayed
             InProgress
             Delivered
         End Enum
         
         Public Property JobCustomer As Customer
         Public Property ChiefEngineer As Engineer
         Public Property Team As List(Of Engineer)
         Public Property JobStartDate As Date
         Public Property JobEndDate As Date
         Public Property JobStatus As Status = Status.Scheduled
         'etc.
    End Class
    
    Public Class Customer
         Inherits Button
         'etc.
    End Class
    Note how the above custom control classes cross-refer: the Engineer Class refers to the Job Class, and the Job Class refers to the Engineer and Customer classes. Because the classes all inherit from Button, you can set properties such as BackColor, Text, Font etc. in the Designer, as with a normal Button.

    All of the above is a very abbreviated overview of custom controls. It's clearly very different from the way you are coding at present, but in the end I think you may have to go this way in order to create a usable Job Board program.

    BB

  18. #18

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Re: CustomControls

    Thank you, everyone for all your suggestions & input.

    I think this is going to be beyond my programming ability but willing to learn & hate being beaten.

    I honestly thought this was not going to be hard to design/code but it seems i am wrong.

    Unfortantly there is no scope to push this out to a contractor as Directors/Operations want to keep this in house....

    More than likely i am going to have to seriously rethink how to do this on what i am wanting to acheive & how the code pulls the jobs from the backend SQL DB.

    At present the board is built from a Access DB form that pulls the jobs from a Access DB backend.

    Thanks James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width