HowTo Dynamic ToolTip or changing tooltip on one button - vb.net

I have a small VB winforms app with a forward and back button. These two buttons allow you to cycle through numerous "pages". I would like to display the next and previous page title in tooltips when the mouse hovers over the buttons(arrows).
Example, when hovering over the left arrow button, I would like to display the name previous page.
So page 1 is applications, page 2 is emails, page 3 is pdf documents etc...
I added the tooltip property from the toolbox in Visual Studios, but it only allows me to type a single item as opposed to scrolling through my list of pages and determining what the previous page name is and displaying it.
The page or form itselt doesn't change, and neither do the buttons, just a panel contained inside the form has the "pages" that change, so I need to be able to write a function that figures out which page is previous and which page is next on the fly when mousehovers the buttons in question... Then returns the data so I can display it in the tooltip.
Better Question;
How can I pass any variable into a tooltip instead of setting it as a property.

Given a tooltip named ToolTip1, then you can set variable text to a control, like this:
Dim myToolTipText = "Dummy text"
ToolTip1.SetToolTip(Me.Button1, myToolTipText)

I wanted to assign the button's text to the tooltip title at runtime. I used the following code:
Private Sub ToolTip1_Popup(sender As Object, e As System.Windows.Forms.PopupEventArgs) _
Handles ToolTip1.Popup
ToolTip1.ToolTipTitle = e.AssociatedControl.Text
End Sub

Related

How to add existing winform to multiple tabpages

I want to add the same Form in project to five tabpages in TabControl.
This is what i have tried
For i As Integer = 0 To 4
'XtraTabPage instance (DevXpress)
Dim page As New XtraTabPage()
'ExamsTab is the existing form that i want to add tho the page
Dim fm As New ExamsTab
fm.TopLevel = False
fm.Dock = DockStyle.Fill
page.Controls.Add(fm)
fm.BringToFront()
fm.Show()
'Adding the page to the TabControl in Exams_Class
Exams_Class.ExamsTabControl.TabPages.Add(page)
Next
This only adds the form to the last tabpage but doesn't add to others.
If that didn't work I'd try page.Controls.AddRange(fm.Controls) but I'm not in a position to test it.
In the past when I've wanted to keep my code better organized into one form per tab I've:
made a new form
put a tabcontrol on it with a single page, call the control TheTabControl for example
put all the controls into the tab page, put all the events etc in the form code
put a line of code that retrieves the tab:
Public Function GetTab() As TabPage
Return Me.TheTabControl.TabPages(0)
End Function
on the main form, with the one tabcontrol that should contain all the other tab pages, have a code like:
MainTabCobtrol.TabPages.Add(New SomeOtherForm().GetTab())
This way all the controls and their event handlers stay in one form (a good thing) but you can combine them together into one Tab Control on another form. Putting them inside a tab means you can get an idea of how to size it, and you can specify in the designer other things like the tab name etc
From a code organising perspective, it's something the designer can more easily cope with than having all the TabPages in one. Control and all the event handlers etc (makes for a fairly monster form code behind and it doesn't respond well to being split into partial classes)
If you want to add a tab control to the existing form the Document Outline window might be helpful for moving the controls into it with drag and drop. You could also cut all the controls, add a tab and paste, but check the eventbhabdlers are all still wired up afterwards- I find that sometimes this makes them go missing

Changing a control's value in a particular Tab of a TabStrip

Basically, I have a multipage for different departments of information called mpageTabsMain.
Inside each page of the multipage is a tabstrip, that contains tabs that represents different people.
What i'm doing for testing right now is using a button click to fill in a textbox's text on my 2nd page of the multipage.
mpageTabsMain.Pages(1).TextBox1.Text = "test"
However, what this does is it fills in the TextBox1's text for every Tab (person) in the TabStrip.
How do I refer to a particular tab (person)'s control in a TabStrip so that only that one is filled?
Thanks.
1) You can't have the same control names within a UserForm.
2) If you want to handle different controls for each page (e.g. TextBox1 on page1, TextBox2 on page2) you should use a Multipage control and maybe this would be the better choice for your requirements.
3) A Tabstrip control makes sense for pages with a similar or identical layout, but uses ONE set of controls only. So if you assign a value to your TextBox1.Text property without further conditions
(i.e. distinguishing between the different kinds of pages) you'll get the same text for the same TextBox1 control independantly of which page you are addressing. Though a Tabstrip can possibly
facilitate to write comparable code for only a few controls (distinguishing at which page you are), it could be the harder part to code.
Addendum (refers to comment below)
OK, you are using a TabStrip within a Multipage and apparently you want to display a tabstrip tab for every person. (BTW, I wouldn't do that, you could just change the tab name dynamically, but that isn't the question).
There is no more than one unique TextBox1 control in the whole UserForm. As TextBox1 is a unique Name, and instead your long code line it's sufficient to assign a string value via Me.TextBox1.Text = "test content for Person A" referring to a current tab view of Person A or TextBox1.Text = "test content for Person B" according to another tab view and another tab value. But it's the same TextBox1 in any case. Me stands for the UserForm itself inside the Userform code module.
You only 'fake' the view to this text (control) depending on the tab situation and are responsible to write it back properly or save it according to the actual tab view :-;

Access Form Opening on Bottom of the Screen

I have an access form with about 7 tabs on it.
When I click on one of the tabs, the window automatically opens to the very bottom of the page for some reason.
I'm really not sure what's causing this... There is no VBA code stating to do this.
I tried implementing this code:
Private Sub Incident_Information_Click()
Forms![PIR Form].[Claim Number].SetFocus
End Sub
And:
Private Sub TabCtl0_Click()
If Me.TabCtl0.Value = 2 Then
Forms![PIR Form 2].[Claim Number].SetFocus
End If
End Sub
I hoped that when the user goes to the "Incident Information" tab, the window would automatically be set to the first control (in this case text box named "Claim Number").
Sometimes this works and sometimes it doesn't. The majority of the time, the screen still scrolls down to the bottom of the form.
Can anyone assist? I don't what's causing this issue and how to correct it.
Open the form in design view and select the controls (tab control) that are shown at the bottom of the screen.
Change this property: Vertical Anchor to Top.
Change your Tab Stop property to No for vertically long controls.
There are controls in some of my Tabs that are vertically long. Whenever I just clicked the tab, the scrollbar would go down. I changed Tab Stop property to No on a subform in one tab and a multiline textbox in another tab and it fixed the scrollbar jump problem.

Loading new form within a navigation tab in ms Access 2010

I have created the following navigation structure in a Microsoft access 2010 database:
You can see that there are two tabs, and the data for the tabs is populated with information linked to the ClientID, which is stored in an un-editable textbox at the top of the form. When the Communications Forms tab is selected, a list of communications forms that have been completed for the specific ClientID is shown. And there is a button to create a new form. My question is how do I write the macro so that clicking on the Create New Form button will cause a blank new form to be loaded in the space that is currently occupied by the List of Forms?
Below is what I have so far. It sends the user to a new form instead of embedding the new form underneath the Communication Forms tab in the current form. How can I change the below so that the blank new form is loaded under the Communication Forms tab in the current form, so that all the navigation controls remain visible/usable?
EDIT:
To address HK1's assumptions below, I am adding the following description of the steps I took to create the form in the screenshot above:
1.) I created a blank form in design view.
2.) I added a listbox to list client fullname and id, and a textbox to filter the listbox.
3.) I added the clientid and fullname textboxes to the form, and set them to change based on
what the user selects from the listbox
4.) I dragged a navigation control onto the form next to the listbox
5.) I dragged a form called "ListOfForms" onto a new tab in the navigation control to create the tab
6.) I added the CreateNewForm command button to the ListOfForms form while embedded in the main form
Here is the result of HK1's suggested code:
While I appreciate it, it does not do what I need. You can see that it just adds an additional row to the list in ListOfForms. Instead, I need the code to place a blank MyForm in the place of MainForm where ListOfForms is currently located. Thus, under the CommunicationsForms tab, all the user would see would be a blank MyForm object, which is a different form than ListOfForms.
When I click on the place where ListOfForms is located in Layout View, I see that it is called NavigationSubForm in the Property Sheet. Thus, NavigationSubForm would swap in MyForm in place of ListOfForms when the user clicks on the Create New Form command button. But if the user clicks on CommunicationForms tab again, ListOfForms would again be placed in NavigationSubForm.
I tried the following:
Private Sub cmdCreateNewForm_Click()
Forms!MainForm!NavigationSubform = MyForm
End Sub
But it generates a Runtime Error '438': Object doesn't support this property or method.
Next, I tried:
Private Sub cmdCreateNewForm_Click()
Forms!MainForm.NavigationSubform.SourceObject = MyForm
End Sub
This causes the NavigationSubForm to go blank, so that ListOfForms disappears. This seems like I am on the correct track, but what do I need to do to get it to put a blank MyForm in the NavigationSubForm instead of just an empty space?
The form you have labeled as "List of Forms" appears to be what's called a continuous form, and I'm guessing it's inside a subform control located on a another form. I'm also guessing that your Create New Form button is probably located on the header section of your continuous form. I'm also making the assumption that your continuous form/subform is bound to an editable recordset/recordsource but there's no way I can tell this by looking at the screenshot.
With these assumptions in place, the code for your Create New Form button would probably be something like this:
Private Sub cmdCreateNewForm_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord, , acNewRec
End Sub
If any of my assumptions above are incorrect than it's likely this code won't work as expected.
Be aware that New Records in continuous forms (and datasheet forms) always appear at the bottom of the list. I'm not aware of any easy way of making them appear anywhere else.

Option Group frame: can I add text boxes that are part of the frame instead of rad button options?

Ok so this maybe a simple/silly question but I don't know so here goes:
In access let's say I want to have a frame control, so I click the option group button and add it to the desgin surface. However, I am not wanting to use this as a option group with radio button selection, instead I would like to add text boxes instead the frame, so that when I reference the frame, it references every control instead of it, hence the text boxes, cbo boxes, etc.....just as it would if they were radio option selections.
So can you do this?
I want whatever controls I add inside the frame to be easily referenced (i.e. make all controls visible just by using frameExample.visible = true) so that I can build my own tab control groupings.....
can this be done?
Thanks!
EDIT:
What I am trying to accomplish is having a form that includes a collection of controls (input controls - cbo boxes, text boxes, etc), that serve as the Main record information. These are saved to a table via an INSERT statement on button_click because this form is unbound.
Next I have 8 categories that are relative per each main record (and data that goes along with it). Each of these categories could have a sub form area and a button click that bring it's relative form into the sub form area. These sub forms would be unbound as well as I would just save data via SQL statement. So i know I could accomplish this by running the insert statement from the parent form, on the main collection control's data that would create the KeyID number, then run a SQL statement that would turn around and load that KeyID number right back onto the page in a hidden text box.
Then when I click one of the sub forms and load its relative collection of controls, I could then save that data along with KeyID for each of these sub-forms/tables.
SO......
I was wondering if instead you could define these controls as a collection so that you could hide and make visible all the ones you need on button clicks and avoid the need for additional forms (subs). I know that if a user enters data into a text box, and then somewhere along the way that box becomes hidden, the data still exists in it and still ends up in the SQL statement....
So I want all these controls to exist on the same form, but I thought what is I could encapsulate them into a frame like an option group, then I could call the frame and all the relative controls would be called up (made visible) as needed.
Sorry for the long explanation but I thought it would help.
I do not think you can do it with an Option Group, but what you are describing is pretty much a subform, yesno?
Some examples of hiding the tab control from an app that went live in March 1998:
Tab driven by transparent command buttons over labels styled to look like colored command buttons:
Same approach, more buttons:
In this case, fake colored command buttons don't drive the tab, but insted show/hide the tab and a subform. In this case, the tab is actually driven by the listbox:
A view of when the tab is hidden and the subform revealed. The listbox drives navigation within the subform, which has a visible tab on it:
So, there's a lot that can be done without showing the tab control.