|
-
Aug 24th, 2000, 11:47 AM
#1
Thread Starter
Member
I want my user customize their form in runtime. I doesn't mean form size change or something like that
I mean how a enduser can change a item's place,
delete a unnecessary item, add a new item on the form
and how can I store this new form designed by my user.
Thank you
-
Aug 24th, 2000, 12:36 PM
#2
Fanatic Member
You would probably use the Windows Registry.
The 'pure' VB functions so Save, Get, and Delete settings are these:
Code:
'Argument list
SaveSetting(Title, Section, Key, Value)
GetSetting(Title, Section, Key, Default)
DeleteSetting(Title, Section, Key)
Code:
'Used in practice:
'Save a setting
Call SaveSetting(App.EXEName, "Cmd1Pos", "Left", Cmd1.Left)
'Restore that setting later on
Cmd1.Left = GetSetting(App.EXEName, "Cmd1Pos", "Left", 200)
'Delete that setting
Call DeleteSetting(App.EXEName, "Cmd1Pos", "Left")
The registry saves values permanently, so these changes will last through the next boot etc. until you delete them.
If there are a lot of values which you need to store, a text file might be a better choice, because clogging up the registry gets impractical after a while.
-
Aug 24th, 2000, 01:04 PM
#3
Try this. Add a CommandButton (Command1) and set it's
Index to 0. When you click on it, it will bring up a
box asking you what you want the caption for a new button to
be. Enter anything and a button will be created in the
Top-Left corner. To Delete buttons, simply, select the button
you want deleted and press Delete. To drag buttons around
the Form, you must hold Alt and then drag it like you
would normally drag an object. The saving and loading is automatically
done when you load and unload the Form.
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 Function ReleaseCapture Lib "user32" () As Long
Const SC_MOVE_EX = &HF012
Const WM_SYSCOMMAND = &H112
Private Sub Command1_Click(Index As Integer)
Dim iCount As Integer
'Add new button
Retval = InputBox("Enter caption for button")
If Retval <> "" Then
iCount = Command1.Count
Load Command1(iCount)
Command1(iCount).Caption = Retval
Command1(iCount).Move 0, 0
Command1(iCount).Visible = True
End If
End Sub
Private Sub Command1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
'If Delete is pressed then the Button will be deleted
If KeyCode = vbKeyDelete Then Unload Command1(Index)
End Sub
Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'While holding Alt, you can drag the control around
If Shift = 4 Then
If Button = 1 Then
ReleaseCapture
SendMessage Command1(Index).hwnd, WM_SYSCOMMAND, SC_MOVE_EX, 0
End If
End If
End Sub
Private Sub Form_Load()
'Load our (if any) previous settings
If Dir$("MyProgramSettings") <> "" Then
Open "MyProgramSettings" For Input As #1
Do While Not EOF(1)
Input #1, tIndex, tCaption, tLeft, tTop
If tIndex <> 0 Then Load Command1(tIndex)
Command1(tIndex).Caption = tCaption
Command1(tIndex).Left = tLeft
Command1(tIndex).Top = tTop
Command1(tIndex).Visible = True
Loop
Close #1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Save our settings as we exit
On Error Resume Next
Open "MyProgramSettings" For Output As #1
For I = 0 To Command1.Count
Write #1, I, Command1(I).Caption, Command1(I).Left, Command1(I).Top
Next I
Close #1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|