Having a problem with visual studio Databinding when leaving and coming back to the same form - vb.net

For making this simply I have two forms a button on each to navigate between the two forms. Then on one I have a checkbox and label when the checkbox is checked it displays the label by using the following code in the form.load event:
Me.label1.DataBindings.Add("Visible", Me.checkbox1, "Checked")
The problem is if I were to leave the form with the checkbox and label and the checkbox is not checked and then I come back to the form with the checkbox and try and check it the label doesn't show up any suggestions or solutions.

Delete that line of code from the form load
Open your form in the designer, the one with the label and the checkbox on it
Click the checkbox
In the Properties grid expand (PropertyBinding) and open the drop down next to (none), click New at the bottom
Pick an initial value, and choose a name for the setting. Make it user scoped if you want to be able to save it and restore it next time the program opens
Now go to your label, properties, click the [...] next to (PropertyBinding) to see a list of all bindable properties, scroll to Visible and drop down to choose the same setting
Run the program.
Side note; when I did this I think I may have encountered a bug/feature of databinding (that I plan to research more) in that the behavior was only as expected if the bool starts out as true (so the control is visible) when the binding is set up. If the control is invisible, it never binds properly to see when the property has become true - so as a workaround (purely in this case where we're binding Visible), replace he call to InitializeComponent() with this, in the form's constructor:
if (!Properties.Settings.Default.FormatWithoutConfirmation)
{
Properties.Settings.Default.FormatWithoutConfirmation = true;
InitializeComponent();
Properties.Settings.Default.FormatWithoutConfirmation = false;
}
else
InitializeComponent();

Related

Set backgroundcolor of every form in vb.net

How can I set the BackColor of every form that exists in my vb.net (fw 4.7.2) project?
And yes, I could do
Form1.BackColor = ...
Form2.BackColor = ...
......
but that would be too messy then.
Open one of your forms in the designer, any form, doesn't matter
Click the form background
In the property grid, at the top, go to (Application Settings) then click the dots button in (Property Binding), find BackColor in the list of proeprties, click the dropdown next to it and click New at the bottom
Call your setting ThemeColor, pick the color you want for the light theme, such as White
OK everything
Open the designer for another form, go Application Settings/Property Binding again. This time don't click New, just bind BackColor to the existing ThemeColor setting
Repeat for all forms in your app
Add a button to the "Settings" form (or wherever you want to offer a toggle for the theme), and in its click handler write:
My.Settings.ThemeColor = Color.White
Add another button to the form, make its click handler set Color.Black
Run the application. Open one or more forms, including the settings form. Click one of the buttons to change the setting. All forms change color
You could:
For Each f as Form in Application.OpenForms
f.BackColor = Color.Red
Next f
at any point after you've opened a boatload of forms
.. or you'd just set the back color in the designer if you were designing a form and you wanted every form instance of that form that you created be red as soon as it was shown
I would have said you could create a class:
Public Class ColoredForm
Inherits Form
Public Sub New()
Me.BackColor = Color.Red
End Sub
End Class
And then in every form you add, open the designer and change the code so that it Inherits this form instead; but it's messing with the designer files (not everyone wants to do it, and changes could be lost if they were regenerated) and isn't actually any different to just.. setting the back color in the designer property grid. If you have some more involved behavior you want all your forms to adopt then consider an inheritance, but if it's as trivial as setting the BackColor, just do it in each form as a design time thing (If you have a lot of forms, can use find/replace for it)

How can a ContextMenuToolStripItem be displayed, without doing it programmatically?

I've taken over a project, which contains some UltraWinGrid controls on some of the forms.
On one of the original forms which has been there since before I took on the project, there is a ContextMenuStrip, which has just one ContextMenuToolstripItem on it, captioned 'Default for Column'.
This ContextMenuStrip is hidden by default, however, when the user right-clicks on the UltraGrid, the ContextMenuStripItem is displayed on the grid (rather than at the top of them form where the ContextMenuStrip is).
I'm trying to replicate this behaviour in a new form that I've added myself, however, after adding the ContextMenuToolstripItem in, I cannot get it to display when right-clicking my grid.
I've put a breakpoint on every subroutine in the in the older forms class, and none of them are triggered when right-clicking it.
Additionally I have also searched the class for DefaultForColumnToolstripMenuItem, and the only place it appears is in the Click event of the ContextMenuToolStripItem itself.
So, how else is it possible to show it when right-clicking the grid? I've copy and pasted the ContextMenuStrip from the old form onto the new form and still nothing occurred.
I'm assuming it's in a property somewhere that I'm missing?
Check for a ContextMenuStrip property on the UltraWinGrid. You can set it in the designer and your context menu will appear on right click without having to deal with the MouseClick handler, checking the mousebutton used, etc.

Checkbox with image and autosize

In Word 2012 I have seen the following checkbox:
I am wondering if this checkbox is a .NET control with an image assigned to it (with property "imagealign" being middle right) or if this is a custom solution by MS for their Office GUIs.
I can reproduce the appearance, but I am unable to easily check if the user clicks the checkbox (and wants to change its state) or the info button and wants to show the tooltip.
Also, I have to add some spaces at the end of the checkbox text, else the image is under the text if the checkbox autosize property is set to True.
I would tend to think that the checkbox is a custom solution by MS or perhaps the image is a separate control.
Does anybody know more about this?
I think you are looking for
Checkbox.AutoSize = False
CheckBox.Image = "Your Image"
CheckBox.ImageAlign = MiddleRight
But this way you won't be able to distinguish if the user clicks the checkbox or the info button to show the tooltip.
As far as I know, there is no control available at .NET which allows this behavior, so I suppose they are using separate controls.
I think you'll need to use a PictureBox near the CheckBox and then use CheckBox_CheckedChanged and PictureBox_Click events to do whatever you want on each case.

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.

VB.Net UI is missing

I'm using Visual Studio 2012 to make a Vb.Net application.
In short, I added DotNetBar RibbonControl with some RibbonItems on it as my menu.
What happened is one of my tab is suddenly missing along with all the buttons in it.
I have searched for it on my Document Outline still no luck.
But what even more odd is, when I tried to recreate it with the same name, it shows an Alert "Property value is not valid" with message "The name AppPOButton is already in use by another component".
When I checked it on the form's Designer I do found this lines:
Me.AppPOButton = New DevComponents.DotNetBar.ButtonItem()
and
'AppPOButton
'
Me.AppPOButton.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText
Me.AppPOButton.Image = Global.ProjectBMT.My.Resources.Resources.approval
Me.AppPOButton.ImageFixedSize = New System.Drawing.Size(40, 40)
Me.AppPOButton.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top
Me.AppPOButton.Name = "AppPOButton"
Me.AppPOButton.SubItemsExpandWidth = 14
Me.AppPOButton.Text = "Approve"
Me.AppPOButton.Visible = False
and
Friend WithEvents AppPOButton As DevComponents.DotNetBar.ButtonItem
Is there anyone can explain why this is happening?
Thank you
This behavior is weird itself, but it's not a problem actually, All the Ribbon style works on "Containers", if you check your ribbon control and click the left-upper button will see these little arrows that move four containers, these objects hold the buttons, images and other controls. Within your design window in the right panel (Properties) you can still see the names of the controls you "lost" when you deleted your tab, wich is also a container.
Steps:
Add a container within your design view and Dock it into the Ribbon control Form.
Click on the uppper right boton (Right Arrow) and select "Layout Ribbon", this will adjust the lenght and hight of the controls conatained.
Add the tab that will contain all the controls you have.
The fact that they are still in the designer form is the prove that they still exist, This behavior is just a glitch in the position and order of the controls set above your form ;-)