Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: [RESOLVED] Move controls at runtime

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Resolved [RESOLVED] Move controls at runtime

    Hello everyone
    I got this code that allows moving controls at runtime
    Code:
    Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture
        SendMessage Text1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
    End Sub
    And I'm wondering if it is possible to save the new position
    I mean even after closing the application, the control keeps its new position
    Thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: Move controls at runtime

    Yes, but it will have to be outside of the application. This is where an INI file might be useful. The FAQ 'sticky link' on the previous page has some info on INI files.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: Move controls at runtime

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Sub ReleaseCapture Lib "user32" ()
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    Private Const MyAppIni As String = "\MyAppSettings.ini"
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal strSection As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    
    Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then Call SendMsgToCtrl(Me.ActiveControl.hWnd)
    End Sub
    
    Private Sub SendMsgToCtrl(ByVal CtlHwnd As Long)
    Dim XCoord As Single
    Dim YCoord As Single
    XCoord = Me.ActiveControl.Left
    YCoord = Me.ActiveControl.Top
    Call ReleaseCapture
    SendMessage CtlHwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    If XCoord <> Me.ActiveControl.Left Or YCoord <> Me.ActiveControl.Top Then
        Call SaveCtlPos(Me.ActiveControl.Name, Me.ActiveControl.Left, Me.ActiveControl.Top)
    End If
    End Sub
    
    Private Sub SaveCtlPos(CtlName As String, ByRef CtlLeftPos As Single, ByRef CtlTopPos As Single)
    Dim Retval As Long
    'Save new control position to 'app' ini file
    Retval = WriteToAppINI("Positions", CtlName & " Left", CStr(CtlLeftPos), App.Path & MyAppIni)
    Retval = WriteToAppINI("Positions", CtlName & " Top", CStr(CtlTopPos), App.Path & MyAppIni)
    End Sub
    
    Public Function WriteToAppINI(strSection As String, strKeyName As String, strValue As String, strFile As String) As Long
    Dim intStatus As Long
    On Error GoTo PROC_ERR
    intStatus = WritePrivateProfileString(strSection, strKeyName, strValue, strFile)
    WriteToAppINI = (intStatus <> 0)
    
    PROC_EXIT:
    Exit Function
      
    PROC_ERR:
    MsgBox "Error: " & Err.Number & "   " & Err.Description, , "WriteToAppINI"
    Resume PROC_EXIT
    End Function
    aaannnd.. of course in Form_Load event retrieve settings from ini file.

    Code:
    'add to declaration section
    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal strSection As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    
    Public Function ReadFromAppINI(SectionHeader As String, VarName As String, ByVal Default As String, strFile As String) As String
    Dim RetStr As String
    RetStr = String(255, Chr(0))
    ReadFromAppINI = Left(RetStr, GetPrivateProfileString(SectionHeader, ByVal VarName$, Default, RetStr, Len(RetStr), strFile))
    End Function
    
    Private Sub Form_Load()
    Dim Ctl As Control
    For Each Ctl In Me.Controls
        If TypeOf Ctl Is TextBox Then
            Ctl.Left = ReadFromAppINI("Positions", Ctl.Name & " Left", Ctl.Left, App.Path & MyAppIni)
            Ctl.Top = ReadFromAppINI("Positions", Ctl.Name & " Top", Ctl.Top, App.Path & MyAppIni)
        End If
    Next
    End Sub

  4. #4
    Frenzied Member gibra's Avatar
    Join Date
    Oct 2009
    Location
    ITALY
    Posts
    1,695

    Re: Move controls at runtime

    You can see this complete sample project, also:

    VB6.0 various projects page
    http://nuke.vbcorner.net/Projects/VB...S/Default.aspx


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: Move controls at runtime

    Thank all you for your help
    I would like to ask you where I have to pu Mr. Tech99's code
    I''m referring to the first code.
    In module or general declaration?
    thanks

  6. #6
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: Move controls at runtime

    Quote Originally Posted by samer22 View Post
    Thank all you for your help
    I would like to ask you where I have to pu Mr. Tech99's code
    I''m referring to the first code.
    In module or general declaration?
    thanks
    Sub 'SaveCtlPos' can remain in form or put to module, if you put it in module change declaration from private to public.

    Likewise Function 'WriteToAppINI' and 'Declare Function WritePrivateProfileString' can remain in form or put to module, private/public definition applies to these also - like in above.

    Others from first 'code tag' (Text1_MouseDown, SendMsgToCtrl and declarations/constants used by those) should be put in to form, where controls are positioned during runtime.

    aand... if you need to move other controls, then add it's type to
    Code:
        If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Combobox Or TypeOf Ctl Is CheckBox Or TypeOf Ctl Is PictureBox 'etc...
    line.
    Last edited by Tech99; Jan 18th, 2016 at 05:35 PM.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: Move controls at runtime

    thanks a lot Mr.Tech99
    Nearly everything is perfect
    except with labels
    the code doesn't move these controls
    I found another code that enables me to move them but the position is not saved
    Is there a solution?
    thanks a lot

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Move controls at runtime

    It doesn't move labels because they don't have handles



    P.S. gibra's code (post 4) can move labels, lines, and other controls that have no handles because his code moves objects using the drag method instead of the:

    Call ReleaseCapture
    SendMessage CtlHwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&

    approach which can only move controls with handles
    Last edited by jmsrickland; Jan 18th, 2016 at 06:03 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: Move controls at runtime

    Quote Originally Posted by samer22 View Post
    thanks a lot Mr.Tech99
    Nearly everything is perfect
    except with labels
    the code doesn't move these controls
    I found another code that enables me to move them but the position is not saved
    Is there a solution?
    thanks a lot
    Windowless controls (label, image, line...) can't receive focus, but sure these could move during runtime.

    fex. add Label1 to form and following code to the previous sample...

    Code:
    '<Add to form declaration section>
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Dim bMove As Boolean
    '</Add to form declaration section>

    Code:
    '<add label1 to the form and this code>
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        bMove = True 'allow moving
        TrackMouse "Label1", Label1.Left, Label1.Top
    End If
    End Sub
    
    Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then bMove = False 'stop moving
    End Sub
    '</add label1 to the form and this code>
    Code:
    Private Sub TrackMouse(CtlName As String, ByRef CtlLeftPos As Single, ByRef CtlTopPos As Single)
    Dim lastPos As POINTAPI
    Dim lastX As Long, lastY As Long
    
    GetCursorPos lastPos
    lastX = lastPos.X - CtlLeftPos / Screen.TwipsPerPixelX
    lastY = lastPos.Y - CtlTopPos / Screen.TwipsPerPixelY
    Do
        DoEvents
        GetCursorPos lastPos
        Label1.Move (lastPos.X - lastX) * Screen.TwipsPerPixelX, (lastPos.Y - lastY) * Screen.TwipsPerPixelY
    Loop While bMove
        
    If CtlLeftPos <> Label1.Left Or CtlTopPos <> Label1.Top Then 
        Call SaveCtlPos(CtlName, Label1.Left, Label1.Top)
    End If
    End Sub
    aandd add..
    Code:
    If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Label ...
    Same 'logic' applies for the image control...

    Code:
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        bMove = True 'allow moving
        TrackMouse "Image1", Image1.Left, Image1.Top
    End If
    End Sub
    
    Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then bMove = False 'stop moving
    End Sub
    and...
    Code:
    Private Sub TrackMouse(CtlName As String, ByRef CtlLeftPos As Single, ByRef CtlTopPos As Single)
    Dim lastPos As POINTAPI
    Dim lastX As Long, lastY As Long
    
    GetCursorPos lastPos
    lastX = lastPos.X - CtlLeftPos / Screen.TwipsPerPixelX
    lastY = lastPos.Y - CtlTopPos / Screen.TwipsPerPixelY
    Do
        DoEvents
        GetCursorPos lastPos
        Select Case CtlName
        Case "Image1"
            Image1.Move (lastPos.X - lastX) * Screen.TwipsPerPixelX, (lastPos.Y - lastY) * Screen.TwipsPerPixelY
        Case "Label1"
            Label1.Move (lastPos.X - lastX) * Screen.TwipsPerPixelX, (lastPos.Y - lastY) * Screen.TwipsPerPixelY
        End Select
    Loop While bMove
    
    Select Case CtlName
        Case "Image1"
            If CtlLeftPos <> Image1.Left Or CtlTopPos <> Image1.Top Then
                Call SaveCtlPos(CtlName, Image1.Left, Image1.Top)
            End If
        Case "Label1"
            If CtlLeftPos <> Label1.Left Or CtlTopPos <> Label1.Top Then
                Call SaveCtlPos(CtlName, Label1.Left, Label1.Top)
            End If
    End Select
    End Sub

    Unfortunately i have no time right now, to write more generic code (...to detect name of the windowless control under the mouse, when mouse button is pressed). Hence quick and dirty sample with 'constant' label1/image1 name.
    Last edited by Tech99; Jan 18th, 2016 at 07:01 PM.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: Move controls at runtime

    This is the code I'm using to move labels
    Code:
    XX = X
    YY = Y
    
    Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Private Sublabel1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
    label1.Left = label1.Left - XX + X
    label1.Top =label1.Top - YY + Y
    End If
    End Sub
    but the onl problem is that the position is not saved

    P.S. I couldn't find gibra's code
    I followed the link but I haven't find the code

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: Move controls at runtime

    Tech99
    You are so generous and a genius programmer
    I'm so grateful to you
    Thanks a lot
    Everything now is perfect

  12. #12
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Move controls at runtime

    Quote Originally Posted by samer22 View Post
    P.S. I couldn't find gibra's code
    I followed the link but I haven't find the code
    You go to the link and it will expose the page with all the samples on it. Look on the left and you will see a listing of each sample. Find the one you want and click on it. You will then get a message saying you have to be a member to download. Go over to the right side and click on Register and fill in all the text boxes then submit. You will receive a code number in your email. Use that code number when you sign in and then you are a member. Go back to the page where the samples are and click again on what you want. This time it will download.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  13. #13
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: Move controls at runtime

    Quote Originally Posted by jmsrickland View Post
    You go to the link and...
    Before that - i would be you - would create an disposable e-mail address. One can question for itself, why such a complicated method to download trivial samples - so be cautious out there.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Back again with one small question
    Is it possible to save colors , fonts, fontsize in ini files
    Now I'm using database to do that?
    Thanks a lot

  15. #15
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: [RESOLVED] Move controls at runtime

    Quote Originally Posted by samer22 View Post
    Back again with one small question
    Is it possible to save colors , fonts, fontsize in ini files
    Now I'm using database to do that?
    Thanks a lot
    Sure it is possible to save all properties of controls in to ini file.

    Code:
    to save setting
    Retval = WriteToAppINI("Control", CtlName & " Fontname", CStr(Ctl.Fontname), App.Path & MyAppIni)
    
    'to read setting
    Ctl.Fontname = ReadFromAppINI("Control", Ctl.Name & " Fontname", Ctl.Fontname, App.Path & MyAppIni)

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Tech99
    Thank you for the quick reply
    I just want to know where I should insert the code
    I tried putting the first code in the subvsave
    Private Sub SaveCtlPos(CtlName As String, ByRef CtlLeftPos As Single, ByRef CtlTopPos As Single)
    Dim Retval As Long
    'Save new control position to 'app' ini file
    Code:
    Retval = WriteToAppINI("Positions", CtlName & " Left", CStr(CtlLeftPos), App.Path & MyAppIni)
    Retval = WriteToAppINI("Positions", CtlName & " Top", CStr(CtlTopPos), App.Path & MyAppIni)
    Retval = WriteToAppINI("Control", CtlName & " Fontname", CStr(Ctl.Fontname), App.Path & MyAppIni)
    And the second code in form load event
    Code:
    If TypeOf ctl Is TextBox Or TypeOf ctl Is CommandButton Or TypeOf ctl Is Label Then
            ctl.Left = ReadFromAppINI("Positions", ctl.Name & " Left", ctl.Left, App.Path & MyAppIni)
            ctl.Top = ReadFromAppINI("Positions", ctl.Name & " Top", ctl.Top, App.Path & MyAppIni)
            ctl.FontName = ReadFromAppINI("Control", ctl.Name & " Fontname", ctl.FontName, App.Path & MyAppIni)
    But it did not work
    Thanks

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    I tried to insert the second code also in the ReadFromAppINI Function
    Code:
    Public Function ReadFromAppINI(SectionHeader As String, VarName As String, ByVal Default As String, strFile As String) As String
    Dim RetStr As String
    Dim ctl As Control
    RetStr = String(255, Chr(0))
    ReadFromAppINI = Left(RetStr, GetPrivateProfileString(SectionHeader, ByVal VarName$, Default, RetStr, Len(RetStr), strFile))
    Ctl.Fontname = ReadFromAppINI("Control", Ctl.Name & " Fontname", Ctl.Fontname, App.Path & MyAppIni)
    But no succees
    thank you

  18. #18
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: [RESOLVED] Move controls at runtime

    Settings needs to read when form is loaded/constructed, hence code below goes to From load routine.

    Code:
     Private Sub Form_Load()
    Dim Ctl As Control
    For Each Ctl In Me.Controls
        If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Image Or TypeOf Ctl Is Label Then
            Ctl.Left = ReadFromAppINI("Positions", Ctl.Name & " Left", Ctl.Left, App.Path & MyAppIni)
            Ctl.Top = ReadFromAppINI("Positions", Ctl.Name & " Top", Ctl.Top, App.Path & MyAppIni)
            'image, picture, line etc. has no font/fontname properties
             If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Label Then
                Ctl.FontName = ReadFromAppINI("Control", Ctl.Name & " Fontname", Ctl.FontName, App.Path & MyAppIni)
            End If
        End If
    Next
    End Sub
    and... settings needs to save after changed or when form is unloaded, so because settings change code is missing sample saves settings on form unolad.
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    Dim Ctl As Control
    For Each Ctl In Me.Controls
    If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Label Then
        'in my previous post, there were typematic error, dot were missing from Ctl.Name
        Retval = WriteToAppINI("Control", Ctl.Name & " Fontname", CStr(Ctl.FontName), App.Path & MyAppIni)
    End If
    Next
    End Sub

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Tech99
    thanks a lot
    the code now is working exept for the colors and sometimes the fontsize
    I wanted to add them in the save and read functions but I failed

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    I'm very very happy to have found the solution alone


    Code:
    Retval = WriteToAppINI("Control", Ctl.Name & " forecolor", CStr(Ctl.ForeColor), App.Path & MyAppIni)
    Code:
     If TypeOf Ctl Is TextBox Or TypeOf Ctl Is Label Then
    Ctl.ForeColor = ReadFromAppINI("Control", Ctl.Name & " forecolor", Ctl.ForeColor, App.Path & MyAppIni)
    Thanks a million sir for your help

  21. #21
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: [RESOLVED] Move controls at runtime

    For the control colors (Forecolor, Backcolor etc.) and fontsize you can 'duplicate' the Fontname code.

    as...

    Ctl.Name & " Fontname", CStr(Ctl.FontName ->
    Ctl.Forecolor & " Forecolor", CStr(Ctl.Forecolor...
    Ctl.Backcolor & " Backcolor", CStr(Ctl.Backcolor...

    and for the fontsize

    Ctl.Name & " Fontsize", CStr(Ctl.FontSize

    Setting and getting properties of controls is the most trivial things to do - so it should not be that hard to imitate?

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    It's me again I'm sorry for disturbing you
    Now if I want to get back the default fonts and colors...., I need to delete the ini file
    I used this code but did not succeed
    Code:
     File = "App.Path & MyAppSettings.ini"
        DeleteFile File
    How can I do that please?
    Last edited by samer22; Jan 20th, 2016 at 02:31 PM.

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    I googled for some time and I found it
    Code:
    Kill App.Path & "\MyAppSettings.ini"
    thanky you

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Please Mr. Tech99 perhaps this is the last worry.
    I was met with a problem with the ini file
    I'm using the ini file to save some settings of two forms .
    Well because the two forms read from the same ini file, I'm getting some trouble.
    For example if I set the background of form1 blue and form2.green, when I launch the application I find the two forms with the same background.
    My question is there a way to create two ini files? Or may be another solution?
    thank you

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    please tell me if this is possible otherwise I will use the ini for one form and database for the other form

  26. #26
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Move controls at runtime

    Of course you can have two INI files. You can have as many as you like. Just give each file a different name; ie: Form1.ini, Form2.ini, etc


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  27. #27
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: [RESOLVED] Move controls at runtime

    Might want to take a break and think this through. If your prefix your INI keys with the form name, that could solve the problem.

    Example. Instead of
    WriteToAppINI("Control", Ctl.Name & " forecolor", CStr(Ctl.ForeColor), App.Path & MyAppIni)
    Ctl.ForeColor = ReadFromAppINI("Control", Ctl.Name & " forecolor", Ctl.ForeColor, App.Path & MyAppIni)

    Maybe:
    WriteToAppINI(Me.Name & ".Control", Ctl.Name & " forecolor", CStr(Ctl.ForeColor), App.Path & MyAppIni)
    Ctl.ForeColor = ReadFromAppINI(Me.Name & "Control", Ctl.Name & " forecolor", Ctl.ForeColor, App.Path & MyAppIni)

    By including the form name (Me.Name) in your INI keys/sections, you avoid the problem if you have a control named Command1 on both forms, but the controls have different settings.

    A better solution would be needed if you create forms dynamically during runtime, since they would have the same name
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Code:
    WriteToAppINI(Me.Name & ".Control", Ctl.Name & " forecolor", CStr(Ctl.ForeColor), App.Path & MyAppIni)
    Ctl.ForeColor = ReadFromAppINI(Me.Name & "Control", Ctl.Name & " forecolor", Ctl.ForeColor, App.Path & MyAppIni)
    I found my hapness with this code
    Thanks a lot

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Code:
    Of course you can have two INI files. You can have as many as you like. Just give each file a different name; ie: Form1.ini, Form2.ini, etc
    Just by curiosity
    please can you show me in the code above which function is used to create the ini file?
    thanks

  30. #30

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Mr.LaVolpe
    Now I'm sometimes having problems in deleting the ini file
    Code:
    Kill App.Path & "\MyAppSettings.ini"
    I don't know if that is because I have modified the original code or I"m having another problem
    thank you

  31. #31
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: [RESOLVED] Move controls at runtime

    Quote Originally Posted by samer22 View Post
    ...which function is used to create the ini file?
    thanks
    That very same function, just change the filename part (MyAppIni), call it fex. MyAppIni2 - but if i would be you, i would use the same ini file and just prefix those keys with form name - as Lavolpe above already succested.
    Retval = WriteToAppINI("Control", Ctl.Name & " forecolor", CStr(Ctl.ForeColor), App.Path & MyAppIni)

    Samer... I can't believe, that these kind of trivial questions are even asked, start thinking and learning for yourself.
    Last edited by Tech99; Jan 21st, 2016 at 07:43 PM.

  32. #32
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    672

    Re: [RESOLVED] Move controls at runtime

    Quote Originally Posted by samer22 View Post
    Now I'm sometimes having problems in deleting the ini file
    Code:
    Kill App.Path & "\MyAppSettings.ini"
    I don't know if that is because I have modified the original code or I"m having another problem
    thank you
    Neither do we know, because 'our crystal ball' has run out of batteries - flat power - capische.

    Code:
    Kill App.Path & MyAppIni
    Should work ok. There is no need to reference file name again, as when you change MyAppIni constant value, then you have to change that "\MyappSettings.ini" also - otherwise file deletion does not work.

  33. #33

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Tech99
    You are so kind sir thank you a lot

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Hello again
    I tried various codes to delete the ini file.
    I sometimes succeed to delete it but I fail in most of the cases.
    A code can delete on one occasion but fails in hundereds times.
    Now I want to know if it is possible to clear the content or at least part of the ini content.
    For example if I wanted restore the original background , how can I clear this section in the ini file?
    Thank you

  35. #35
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,072

    Re: [RESOLVED] Move controls at runtime

    Wouldn't writing a null string (i.e., vbNullString) clear the entry?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: [RESOLVED] Move controls at runtime

    Quote Originally Posted by LaVolpe View Post
    Wouldn't writing a null string (i.e., vbNullString) clear the entry?
    Thanks a lot sir

  37. #37
    Lively Member
    Join Date
    Jul 1999
    Location
    London
    Posts
    76

    Re: Move controls at runtime

    VB6.0 various projects page
    http://nuke.vbcorner.net/Projects/VB...S/Default.aspx

    [/QUOTE]


    Piece of c**p, after wasting time to register it says i cant access the "panel???".
    MBS

  38. #38
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,409

    Re: [RESOLVED] Move controls at runtime

    And WHY are you posting this to a 3+ year old thread that was already RESOLVED?

    You joined in '99? Wonder why you haven't provided assistance (i see you only posted 59 times) to others over the past TWENTY YEARS!

    Anyway,...have a great rest-of-the-day!

    Sammi

  39. #39
    Lively Member
    Join Date
    Jul 1999
    Location
    London
    Posts
    76

    Re: [RESOLVED] Move controls at runtime

    I only post when I think I will contribute with something... something that will help others.
    In this case, someone else who might be looking for the same info I was... that person won't waste time registering in that s**ty site.

    Before creating new threads with the same topics i use to research, because that I've updated a thread that is 3+YO.

    Instead of a "powerposter" i'm still a "member" after all these 20 years. The order is: "if you dont have anything to contribute SFU!"

    Anyway,...have a great rest-of-the-day!
    MBS

    Quote Originally Posted by SamOscarBrown View Post
    And WHY are you posting this to a 3+ year old thread that was already RESOLVED?

    You joined in '99? Wonder why you haven't provided assistance (i see you only posted 59 times) to others over the past TWENTY YEARS!

    Anyway,...have a great rest-of-the-day!

    Sammi
    MBS

  40. #40
    Lively Member
    Join Date
    Jul 1999
    Location
    London
    Posts
    76

    Re: [RESOLVED] Move controls at runtime

    I only post when I think I will contribute with something... something that will help others.
    In this case, someone else who might be looking for the same info I was... that person won't waste time registering in that s**ty site.

    Before creating new threads with the same topics i use to research, because that I've updated a thread that is 3+YO.

    Instead of a "powerposter" i'm still a "member" after all these 20 years. The order is: "if you dont have anything to contribute SFU!"

    Anyway,...have a great rest-of-the-day!
    MBS

    Quote Originally Posted by SamOscarBrown View Post
    And WHY are you posting this to a 3+ year old thread that was already RESOLVED?

    You joined in '99? Wonder why you haven't provided assistance (i see you only posted 59 times) to others over the past TWENTY YEARS!

    Anyway,...have a great rest-of-the-day!

    Sammi
    MBS

Page 1 of 2 12 LastLast

Posting Permissions

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



Click Here to Expand Forum to Full Width