Lukee9's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Active Members
Active Posts:
64 (0.05 per day)
Joined:
15-August 12
Profile Views:
3,212
Last Active:
User is offline Mar 27 2016 11:48 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Lukee9 has not set their status

Posts I've Made

  1. In Topic: Convert RGB to closest known color name

    Posted 26 Mar 2016

    Right, sorry for the slow reply as I was unavailable most of the day. I've pretty much got it sorted but I would like some input on improving the efficiency of the function.

    To create the list of colour names this code was used:

    
        Private Structure TStoredColours
            Dim Name As String
            Dim R As Short
            Dim G As Short
            Dim B As Short
        End Structure
        Dim Colours As New List(Of TStoredColours)
        Private Sub GenerateColourList()
            Dim ColourType As Type = GetType(System.Drawing.Color)
            Dim PropertyInfo As System.Reflection.PropertyInfo() = ColourType.GetProperties(System.Reflection.BindingFlags.[Static] Or System.Reflection.BindingFlags.DeclaredOnly Or System.Reflection.BindingFlags.[Public])
            For Each c As System.Reflection.PropertyInfo In PropertyInfo
                If Not c.Name = "Transparent" Then
                    Colours.Add(New TStoredColours With {.Name = c.Name, .R = Drawing.Color.FromName(c.Name).R, .G = Drawing.Color.FromName(c.Name).G, .B = Drawing.Color.FromName(c.Name).B})
                End If
            Next
            Dim SortOrder As System.Collections.Generic.IEnumerable(Of TStoredColours) = From c In Colours Order By c.Name Select c
            Colours = SortOrder.ToList
        End Sub
    
    
    


    And to return a colour name from a given colour this code is used: (and this is the function I would like to speed up if possible):

    
        Private Function ColourToName(ByVal Colour As System.Drawing.Color) As String
            Dim NearestColour As TStoredColours = New TStoredColours With {.Name = "NULL", .R = 255, .G = 255, .B = 255}
            Dim NearestColourVal As Integer = Integer.MaxValue
            For Each c As TStoredColours In Colours
                If Colour = Color.FromArgb(255, c.R, c.G, c.B)/>/>/>/> Then
                    'Found exact match
                    Return c.Name
                Else
                    'Couldn't find exact match, working out which colour is closest to given colour
                    If (Math.Abs(Colour.R - c.R) + Math.Abs(Colour.G - c.G) + Math.Abs(Colour.B - c.B)/>/>/>/>) < NearestColourVal Then
                        NearestColourVal = Math.Abs(Colour.R - c.R) + Math.Abs(Colour.G - c.G) + Math.Abs(Colour.B - c.B)/>/>/>/>
                        NearestColour = c
                    End If
                End If
            Next
            Return NearestColour.Name
        End Function
    
    
    



    P.S. The code tags automatically added lots of '/>' symbols in? Is that to stop xss or something?
  2. In Topic: Picturebox location from thread within class

    Posted 27 Jan 2016

    I've thought about what you said and edited my code, it is now working thanks to you :)/>
    Whenever I referenced animation I was probably talking about animating controls (with movement by changing location)

    'When in a class you cannot just arbitrarily yell 'form1' and think you are getting the original thread.

    Let alone you probably do not have a handle back to the original thread's graphics object.'

    helped me, I realised that if I sent a 'handle' of the form I was trying to edit to the thread as a parameter then the thread would have full access to it.

    Here is the amended code:

    Sending 'Me' as a parameter too
    Dim tws As New AnimationThread(ExpandMenu.Location.X, 220, Me)
            Dim a As New Threading.Thread(New Threading.ThreadStart(AddressOf tws.ExpandMenu_Thread))
            a.Start()
    


    Within the AnimationThread class: (receiving 'Me')
    Public Class AnimationThread 'Partial?
        Private XCoord As Integer
        Private YCoord As Integer
        Private FormHandle As Form1
        Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal Handle As Form1)
            XCoord = x
            YCoord = y
            FormHandle = Handle
        End Sub
    


    Using the handle:
    Private Sub ExpandMenu_LocationSet(ByVal XLoc As Integer, ByVal YLoc As Integer)
            Dim d As New SetLocationCallBack(AddressOf ExpandMenu_LocationSet)
            If FormHandle.ExpandMenu.InvokeRequired Then
                FormHandle.Invoke(d, New Object() {XLoc, YLoc})
            Else
                FormHandle.ExpandMenu.Location = New System.Drawing.Point(XLoc, YLoc)
                FormHandle.Refresh()
            End If
    
        End Sub
    


    I have a couple finisher questions (more just reassuring what I think I already know):
    1. What is better to use to send parameters to a thread? A ParameterizedThreadStart delegate or using Private Sub New() as I did? From what I've read the latter is more secure so better to use.
    2. In my case should the class 'AnimationThread' be declared as partial? (From what I've read this just makes the class spread over multiple source files, I don't see an advantage to this but I have seen lots of people use Partial when they are doing the same kind of thing as me).


    P.S. Thanks for guiding me through it all :)
  3. In Topic: Picturebox location from thread within class

    Posted 27 Jan 2016

    I suppose 'all willy-nilly like'. Form1 was autogenerated when I started a new project (and so Public Class Form1 was autogenerated to put code in). I haven't redeclared Form1 anywhere, should I have?
  4. In Topic: Picturebox location from thread within class

    Posted 27 Jan 2016

    This is being called from within the AnimationThread class (separate from Form1). The code is found within a subroutine used by the thread.
  5. In Topic: Picturebox location from thread within class

    Posted 27 Jan 2016

    After some testing I now don't believe that refreshing is my issue, I've added a button so that I can manually do Me.Refresh() after the thread has finished but I still get no movement of the picturebox. I believe that the issue is with:

       If Form1.ExpandMenu.InvokeRequired Then
                Form1.Invoke(d, New Object() {XLoc, YLoc})
            Else
                Form1.ExpandMenu.Location = New System.Drawing.Point(XLoc, YLoc)
                Form1.Refresh()
            End If
    
    


    Using 'Form1.' at the start is what is causing the issue. I think this because putting a breakpoint on Form1.Invoke I realise that Form1.ExpandMenu.InvokeRequired is ALWAYS false, when I didn't put this code in a separate class and just used ExpandMenu.InvokeRequired then it was sometimes true (and Invoke would be called). I don't quite know what to make of this information however.
    Also the reason I have it in a separate class now is to send parameters to the thread.

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Lukee9 hasn't added any friends yet.

Comments

Lukee9 has no profile comments yet. Why not say hello?