How does the tooltip control enhance all controls on the form with a new property? - vb.net

When answering another question I started to wonder how I could Add new properties to all controls in a form just like the ToolTip-control does.
For example I could use that to Add a "IsDirty"-flag to all textboxes just by adding the component to the form and it would handle this for every textbox.
When adding the tooltip-control to the form all controls magically gets a new property "Tooltip on tooltip1" that can be set both programatically and in design view.
I want to be able to do my own enhancer like that.

It's an Extender Provider.

Related

How to create click event for dynamically created custom control?

Let say that I'm creating thousands of custom controls, each control has own data assigned to it (like name, id, etc.), now I would like to add
click event for each of these custom controls
access from software any of these dynamically created controls
So I would like to show MsgBox if user click control #452, which will be returning values assigned to object in custom control class (passed during creation of new control on user form)
Second thing is that I would like to access at any time any of these objects and read values assigned to object in control....
How to do it ? Each control has name assigned like "Example1", "Example2", "Example3" but I don't know how to access it from code as any of these exists during writing...
Also I were trying to find how to create and rise events but it seems that all solutions are for statically created controls and I need to rise events for dynamically crated custom controls....
Thanks in advance for any tips/help how to solve it.
I'm using VB.NET
Ok I figured it out !
It is very simple actually.
If any one will be looking for an answer :
To access dynamically created control first we are going to name it :
Dim Control as new CustomControl
Control.Name = "Name" & Counter
Next after we've created new controls we are going to access it using:
Dim _Control as new CustomControl
_Control = Ctype(Me.Panel1.Controls("Name1"), CustomControl)
MsgBox(_Control.Name.ToString)
Viola
I still not sure about custom events for all controls on custom control (so where ever user click, there should be override event which returns something back, now I can only either click panel container (not labels/pictureboxes) from code inside user class, or event per control on custom control (but issue is that I want to pass data from custom control to user class).

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

Multiple Views One Form

I'm looking to have a navigation pane on the left side of my form which will change the right side of the form accordingly. I could always use panels and store the controls on the panels but is there a better way to do this? A tab control would be nice but I wouldn't want to see the actual tabs ...
Is there a way to do this?
Edit after seeing the answer:
Dim uc As New UserControl1
Form1.Controls.Add(uc)
Will add everything in the user control to the form1. Alternatively, if I had a Panel, I could do:
Panel1.controls.add(uc)
That would add it to the panel.
You can use panels, but you could also have your panes as UserControls and load them into a single panel instance, or even directly into the form.
Putting them into UserControls also means your form's generated class won't be cluttered with control members.
I would have to agree with #Dai Here is a great thread on it. It explains how to setup the panels in the ide.

How do I create a "wizard" style ui using vb.net?

The idea is that I would have a set of forms, users would click through a "forward" and "back" button, and the current form would change to a different one. My issue is that I can write code that just pops up a new form, but im not sure how to do a "replacement" of my current form. How is this usually done?
What I did recently was to create a form with buttons already in place and a large panel to contain each step. The dialog would accept an initial step in the form of a IWizStep instance, and the things would roll from there.
Each step was a class exposing a UserControl responsible for the visual aspect of the step, while the logic itself was handled by the class (it was a little more complicated that that, but that was the general idea).
The IWizStep interface, implemented by the step and accepted by the dialog, was on the lines of:
Interface IWizStep
Event StateChanged As EventHandler
ReadOnly Property Control As Control
ReadOnly Property Title As String
ReadOnly Property CanMovePrevious As Boolean
ReadOnly Property CanMoveNext As Boolean
Function MovePrevious As IWizStep
Function MoveNext As IWizStep
End Interface
To put everything together, a controller class would know how to compose the steps necessary for each given action. Therefore I had a controller for, say, "Emit Order", which needed some 10 steps, and a controller for "Emit Orders in Batch", which needed only a couple of steps.
Create a set of UserControls, and add and remove them from a Panel in a single form. (and set Dock to Fill)
You could define a user control which acts as a "wizard". It just needs the buttons you have and an array of content panels, just have it switch through the panels when the buttons are pressed assuming a certain condition is met within the controls on the panel. There's no real definitive "wizard" maker, since it's pretty easy to roll your own wizard.
You don't need to do a "replacement" of your current form really, you could just add a new one to the project. If you do need to for whatever reason, just grab the control collection with Me.Controls, copy that somewhere, and put the new controls up. When you don't need the wizard, swap them out again. It's generally best practice to make a new form however!

Datagrid View in a custom control

I am trying to add datagridview control in my custom control but i failed.
I started creating new project[windows custom control library], added datagridview control on it and also added a property naming "DGVMain" which refers to datagridview control.
I compiled it.
While testing i find its properties like visible and other working but when i click on columns property it doesn't work. i.e i cannot add/edit columns into the datagridview of my custom control.
Did i miss any steps or do i need to add some more actions?
As you don't have other control within your custom control, maybe an inherited user control would be more appropriate in this case and I'm sure it will also fix your problem.