topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday December 11, 2024, 1:39 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Visual Basic .NET - Can I make a dynamic GUI?  (Read 9795 times)

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Visual Basic .NET - Can I make a dynamic GUI?
« on: March 21, 2008, 05:36 PM »
Does anyone know if it is possible to make a drag-and-drop GUI, configurable on-the-fly by the user? Something like this...

User starts program
Program window opens, awaits action
User clicks Button1 to execute action XYZ. After execution the user returns to the program.
User right clicks on Button1, and drags Button1 to a new location
The user closes the program (optional)
Program saves custom GUI item locations
User starts program (if program was closed)
Program window opens, loads the GUI item locations, adjusts items accordingly, and awaits user action
User clicks Button1 as if it were positioned originally (from in the VB designer) and action XYZ executes.

To be totally honest, I expect this to be very complicated and use a lot of code, and on top of that I have absolutely no idea how to save settings (I am going to go Google-mad after this post and begin researching on Setting saving and loading). But, I figure it is worth a shot to ask! Can't know until you try, right?

If anyone understood any of the ideal end-user steps above, and could help me with this in any way, please help me understand how I would go about doing this :)

PPLandry

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 702
    • View Profile
    • InfoQube Information manager
    • Read more about this member.
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #1 on: March 21, 2008, 05:51 PM »
I can definitely be done, I've done exactly that using VB3 15 years ago and it wasn't complicated to do...

[edit]
  • You basically put an invisible copy of every control type you want (textbox, commandbutton, radiobutton, etc)
  • When the user does the right thing, you programmatically copy the invisible one to a new visible one
  • You save the configuration to a text file. I used tab-delimited (now may be more convenient to use XML format)
  • On re-open, you re-create the controls based on this file
  • To switch between design and run modes, simply change the dragmode properties

If you want sample code, just ask.
Real generosity toward the future lies in giving all to the present -- Albert Camus -- www.InfoQube.biz
« Last Edit: March 21, 2008, 06:20 PM by PPLandry »

CWuestefeld

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,009
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #2 on: March 21, 2008, 06:16 PM »
Dynamically creating and moving controls in .Net is trivial -- look at the code that the designers generate for you, and you can see that this is exactly what it's doing.

What will be more complicated is keeping the user from being confused as you switch modes from making the button actually click as it's designed vs. making it grab-able and dragable.

And BTW, if you find examples of this for C#, it's pretty much exactly the same for VB. Other than the syntactic differences, the way you handle the WinForms framework isn't dependent on the calling language.

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #3 on: March 21, 2008, 06:29 PM »
I don't really understand what you are saying PPLandry (I get the idea, just not how to execute it). I know how to make invisible controls, but the copying I don't "get". I am getting a feel for saving settings right now (reading several examples and searching), but I don't know how to actually move the items while the program is running (I don't see what you mean by "look at the code", CWuestefeld - I have done it before where it gives me an XML type of data sheet, but I can't get it to do it now; could you elaborate as to how to get that info?).

I will Google for examples though. Didn't know about that.

PPLandry

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 702
    • View Profile
    • InfoQube Information manager
    • Read more about this member.
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #4 on: March 21, 2008, 06:33 PM »
I would have to look up how to do it in .net, but in plain old VB, your invisible control is a control array. So you simply do ControlName.add. This can help:
http://visualbasic.a.../bldykctrlarraya.htm
http://msdn2.microso...ibrary/aa289500.aspx
Real generosity toward the future lies in giving all to the present -- Albert Camus -- www.InfoQube.biz
« Last Edit: March 21, 2008, 11:54 PM by PPLandry »

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #5 on: March 21, 2008, 06:35 PM »
I can make a control invisible by simply changing a setting in .NET on the options bar off to the right - that isn't an issue. I just don't see what you mean by copying the original button to the new location?

CWuestefeld

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,009
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #6 on: March 21, 2008, 09:12 PM »
If it's simply a matter of moving a control, all you need to do is to modify its location via the Top and Left properties, like so:
        Button1.Left = x
        Button1.Top = y

Attached is a simple project with 1 window. Click the button to see a message box. But if you're holding down ALT while you do it, it moves the button to the next corner of the window, clockwise. It's a VS2008 project, so you may not be able to read it, but even if you can't, just open Form1.vb to see the form's code.

BTW, when I said "look at the code that the designers generate", I meant look in the FormXYZ.Designer.vb file. The designer generates code here that actually creates and places each of the controls you put on the form. This will show you how to actually create new controls dynamically.

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #7 on: March 21, 2008, 09:29 PM »
Alright, now I think I understand. :) Downloading now (I have VB '08). Will take a look and see if I can make sense of how to do this myself. Thanks!

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #8 on: March 21, 2008, 11:52 PM »
On a related note, I was wondering if there is a way to change to a different tab when a button is clicked. Something like

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error Resume Next
GoToTab("TabName")
End Sub

I have been searching for about 2 weeks on this and come up dry on whatever search results I try. I am thinking about just typing in commands and using the autocomplete function in VB Express Edition to scan and see what commands I can look into that could help me with this (it works sometimes).

Anyone got any ideas for this? There has to be a way to do it, but I just can't find out how! :tellme:

wreckedcarzz

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,626
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #9 on: March 21, 2008, 11:59 PM »
Never mind, I was able to find a solution via guess and check. I am starting to love the autocomplete option. :-*

CWuestefeld

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,009
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #10 on: March 22, 2008, 08:03 AM »
You might want to pick up a copy of the Chris Sells' "Windows Forms Programming" book (http://www.amazon.co...pment/dp/0321125193/.

There's a VB version that's getting a little old, but if you don't mind seeing the samples in C# (as I said, the differences are only in syntax -- it's the same function calls), go for the newer editions.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: Visual Basic .NET - Can I make a dynamic GUI?
« Reply #11 on: March 26, 2008, 04:12 PM »
Actually, I found the one by Erik Brown better:

http://www.amazon.co...206565872&sr=1-4

Of course that's just personal opinion...