User Control Form (Wizard panel) to have common ShowData() function - vb.net

Like many, I'm trying to build a wizard like presentation.
I've created a Windows Form as the host for a series of "WizPanel"s that have been designed as User Control Forms. Each of them may/will have unique data connections and layouts. My intended implementation creates a Collection(of UserControl). I'm at the design point that I want to load the collection with a set of panels that best describe the process flow required by the current use case.
The problem I'm running into is how to be able to load a New UCDataReview (user control form), a New UCDataParameters (user control form), then the rest of the panels as required. I don't want the panels to load data at this point as some of the data queries may never be required - based on data supplied in previous panels (possibly, just design at this point). I just want to make sure data only loads when I specify. I like to have a function ShowData() on each of the panels and then execute it from within the main Wizard form (after the next button is clicked - it wouldn't be needed on a back as it should be there already).
So, I'm stuck on the concept of crating a 'base wizard panel' control (WizPanelBase) that has a ShowData() function that is empty in the base control form but can be overridden in the class (WizPanel) that the panel is based upon. I'd then have a Collection(of WizPanelBase) that would then allow me to issue a ShowData() call.
I'm sorry for not using the correct verbiage as I'm only a part timer and just playing to learn. I've done this with an Object Class (ObjBase_Person; ObjBase_Vehicle ...) and then extended them into Person_Student, Person_Instructor, Vehicle_Car, Vehicle_Truck etc). I'm quite sure I can, I just know enough to be dangerous, but I don't know what to even ask for to find tutorials. The similar questions here are generally about using a User Control on a Windows form.

Related

Parent form and child User Control communication in WinForms

I have my form with a menu bar and space underneath to display my controls. One of the buttons in my menu bar is suppose to be a print button that prints a graph that's currently in a User Control I display in the form. If the graph was on the form in the print button's eventhandler I could just simply call
graph.printing.print(true)
which isn't going to work in my case since the graph is in the control and not the form.
How do I communicate with a User Control from the containing form and access or pass its variables when needed? I also have a status bar on the bottom of the form which would also need to get updated from the User Control, but I'll be able to deal with that if I got help with just this one part. Please bear in mind, I also have another User Control I'm going to add to the form which will also contain a graph which will need the same treatment as the other graph on the first control when the print button is pressed. I plan on swapping these two out so I have one form displaying one control at a time.
I got this idea from this answer: https://stackoverflow.com/a/18191630/2567273 but after further research I can't find anyone asking about the actual communication process between a form and the control it contains.
I think this answer is close to what I'm looking for, but I think it's leading me down the path to using panels instead of User Controls.
After typing this I noticed the closest answer to my question may be this, but that question has the child raising events and the parent responding while I have the parent raising the event and the parent has to get information from the child.
One way to think about this is Roles. Presumably you built this UserControl to handle the management of the data related to the graphs. As such you can think of them in the Role of a Graphs Specialist . Once you do that, printing them is actually just one more thing it should perhaps do.
The form on the other hand, is not special just because it happens to get receive the command from the user to print. Its role in this might simply to be to know which usercontrol to contact and which method to invoke:
Sub PrintGraphMenuClick....
Select Case something ' determinant as to which UC to contact
Case operation.Foo
ucFoo.PrintGraph
Case operation.Bar
ucBar.PrintGraph
Other menu options like Clear, NewGraph, Save and whatever else there is somewhat the same way. The Form's Role here may be to receive the command from the user and pass it along to the right control, invoking the correct right method and passing the correct parameters - that is not a trivial task.
Of course, rather than a MainMenu, the usercontols could alternatively implement a ContextMenu and even receive those commands directly.
Very often offloading an operation to something else results in so many properties, filenames, streams etc having to be moved from here to there that it becomes burdensome. In this case it is not like the MainForm has some special ability regarding printers that the UserControl cannot handle.
There is only one right solution:
1) Add an event to your user control.
2) Raise the event when the particular "thing" happens in the user control.
3) Attach a handler to the event in Form code.
4) Add code to update the bottom bar in the event handler.

Cannot add new controls when creating a composite user control

I am trying to broaden my knowledge of user controls or to be more specific, composite user controls. Msdn has a walkthrough on the subject here which although not in VB is easy enough to follow and get results.
What I had had in mind was to create a base user control comprised of a split panel, one half of which would be used to display dynamic help and the other half which could house whatever controls the new user control which would inherit from this required. The problem that I am facing is that when I then create a new inherited control based upon my base control I cannot add new controls to the design surface. If I don't have a split panel filling the entire design surface of the base control I can add new controls, but if I do I can't.
Either I am doing something wrong, or more likely failing to do something on the base control that I ought to do , or this can't be done which I find odd to believe. I'm hoping someone can explain what it is I've missed.
This is being targeted at winforms with vb.
Thanks
Well, Did you make the split panel's modifier to protected or protected internal or public? That should do the trick.
By default it is private and so designer will prevent you from accessing it.

Making multiple forms appear as one in VB.NET

I am writing a Windows Forms application in VB.NET. I have three forms: the main form, which shows a list of accounts, the account form which allows the user to view/edit the information for a specific account, and the policy form which allows the user to view/edit the information on a specific policy for that account. I want the forms to appear as if they are all the same window. Example: when the application starts, the user clicks an account name in the list box on the main form and clicks "edit". What I want to happen is that the window stays in the exact same place and stays the same exact size, only the content of the main form appears to be replaced with the content of the account form. Same thing if the user then chooses to edit a policy from the account form. When the user finishes and clicks "save", the main form comes back up. Through this entire use case, it would appear to the user as if they were viewing the same window the entire time, with the content of that window changing.
How can I do this? I have tried something like:
Dim newForm as New AcctForm
newForm.Location = Me.Location
newForm.Show()
Me.Close()
The problem is that if the user moves the original window, the new window appears where the parent form originally appeared, not where it ended up.
I see this is already in the comments, but what I have done in this case in the past is build each "form" in the application as a custom control. Then I have one actual form, and navigation works by changing which custom control is currently loaded on the parent form. To move from one screen/view to another, you remove the current custom control from the form's controls collection and add the new custom control.
I believe this is superior to manually setting the startup position and size, because you can use the form's .SuspendLayout()/.ResumeLayout() methods to hide the interim state, where there is no control loaded, from the user. This is harder to do when you want one form to be completely replaced by another.
This also makes it easy to set certain form properties in one place and have them be consistent for the application. You can even have an area on the form with controls that will now show in every view.
When using this pattern, I typically have each of my custom controls inherit from a common base. You may not have anything specific you will do with that base at the outset, but it almost always comes in handy later.
Finally, switching to use this scheme is easier than you think. Just go to the code for the each of your current forms, and you will find that each class currently inherits from System.Windows.Forms.Form. Most of the time, all you really need to do is change them to inherit from System.Windows.Forms.Panel and you're most of the way there.
As others have said, it may be better to redesign your application using custom controls or panels etc.
However, to answer your question regarding the seemingly random location of your forms, the first thing to check is that each form has it's StartPosition property set to Manual.
If your main form is resizable, then I would also add code to adjust newForm to the same size too.
I hope that helps with your immediate issues; so that you can move on to redesigning the application!
good morning there is another way . set property for second form to (top most) and use also
from2.show();
that make you switch between forms and keep form2 top other
Thanks
try using ShowDialog()
Dim newForm as New AcctForm
newForm.Location = Me.Location
newForm.ShowDialog()
Me.Close() <-- removed this

VB Chat Interface - Displaying Users

I am new to Visual Basic and trying to get around in developing a good gui for a chat interface. I can understand the language as i have been using php and java from quite sometime.
Requirement
Basically i am trying to develop a interface which will show a list of users and along with that display a status (online/offline). My users will reside in mysql database. On clicking the user i want some actions to happen.
Question
I see there is datagrid, listview,listbox but not sure which one to use. Also is it a good idea to display the users by directly quering the mysql database or by accessing a php script which runs few queries and gives the data?
The ListBox control would not be a great option since it doesn't easily support multiple columns. The ListView control in Details view is a great option. I think it looks and works nicer than a DataGrid, but it doesn't natively support multi-line items. If you need multi-line items, the DataGrid control may be your best choice. Another option, which would give you more flexibility, would be to use a LayoutPanel control to display a vertical list of your own UserControl. You could design the UserControl anyway you want meaning you could fully control the size, look, and layout of each item in the list without being constrained by the list control.
As far as getting the data, that depends. If the database is always on the LAN and performance is important, then each client should go directly to the database. Otherwise, getting the data from a php script, web service, or WCF service would be a much better choice.
Rather than using the TableLayoutPanel, I would recommend using the FlowLayoutPanel with the FlowDirection property to TopDown and the AutoScroll property set to True. Then, to add a control dynamically, you could do something like this:
Dim item As New MyUserControl()
' Set properties of user control
FlowLayouPanel1.Controls.Add(item)

How to dynamically load, access and unload subforms in microsoft access

I am trying top transition from ASP.NET to programming in access and I am used to thinking in terms of Usercontrols when I think of subforms in Access. What I would like to do is allow user to click a button to load a subform that contains controls user can enter additional data into. I would appreciate any information or resource that would help me with understanding how this is done in MS Access -- how to load, unload and access data in the subforms as well. Thanks in advance
Well, as a general rule such loading of sub forms is done automatic and does not require any coding on your part. So you in general are best not to worry about this issue and save all that coding time for helping the poor and needy in your neighborhood.
I should however point out that if you building web forms in Access, then the sub forms are dynamic loaded ONLY when they are used. So if you place a sub form behind a tab control, then the resulting web form (they are XAML forms when published and form code is converted into JavaScript), then the sub form is dynamic loaded for you into the browser. No doubt this setup does result in web forms loading a lot faster. So for web forms, such loading is dynamic and on demand for Access Web forms.
However, my guessing here is you talking about Access client forms and not Access web forms. Given that case, on the client side, load time is rather fast and is quite rare to worry or need or waste developer time on doing this.
However, there are some cases, such having to load say 5 sub forms, and such time can start to add up to the point where a user might start to notice a delay. In this case, you can dynamic load a sub form, and you do this by setting the source object property of sub-form object.
So keep in mind that a sub form is only a "control" and is not tied to an actual form. IN most Access applications I seen the name of this sub form control is the same name as the sub form, but it certainly does not have to be.
So, to dynamic load a sub form, such as when changing to a different tab on a form, the code looks like this:
Private Sub TabCtl2_Change()
If Me.TabCtl2.Value = 1 Then
If Me.frmListContacts.SourceObject = "" Then
Me.frmListContacts.SourceObject = "frmListContacts"
End If
End Sub
So, if you place a sub form control on a form, but leave the source object setting blank, then no form will be loaded or display for that sub form. And in the above, once I loaded the form, then the source object setting will not be blank, and thus I don't attempt to set/load the sub form more than once.
As noted, in the vast majority of cases when loading a form, you need that sub form to load and display anyway, so in most typical applications such above code is not required.