On Click (text box,) Open Window - wpf

I am trying to build a basic front-end to link information together that would be accessible by clicking a text box (or a button) on the front page of the GUI. Basically, I have a number of text boxes for the different "functions" I want to show information on.
How do I make it so that on click, that box will open up a new window that I've already designeD? Within the solution (WPApplication,) I have all of the .xaml's set up (that are the seperate windows) in the solution already- I just want to call the on-click to open them. I figured it'd just be Show('Window Name') after private/as/handles, but it gives me an expression. Here's what I have:
Private Sub PO_info_MouseDown(Sendar As Object, e As MouseButtonEventArgs) Handles PO_Info.Mousedown
Show('PO Information')
End Sub
End Class

To flesh out my comment, the new window objects that you created are classes, you need to create an instance of the class before the Show Method will work. Lets assume that your PO Information forms class is POInfo you would need to do something like this.
POInfo POInformation = new POInfo;
POinformation.Show(); //This is where your show method is
Since your code looks like vb.net it would look like this in VB
Dim POInformation as New PoInfo
POInformation.Show()

Related

Creating an array of Command Buttons

I am in a situation Where I need to Create multiple Command buttons and assign a single event handler to these buttons using following Event Handler.
Private Sub Digits_Click(Index as Integer)
Display.Caption=Display.Caption+Digits(Index).Caption
End Sub
I created first button and copy paste it to the userform but it did not Prompt:
"You already have a control Name XXX. Do you want to create a control array?"
VBA doesn’t allow us to to create Control Array like in VB6 and VB.Net. My Question is Can we still create Control Array in VBA??
I am new to this Topic Please help
You might want to look at creating a loop and dynamically adding the command buttons
Every cmd should have a unique name.. It can call the same sub procedure. But every button should be unique in its own sense.

A combination of winforms' controls as a prefab?

In our winforms application we often have a situation where the same panel is used in different forms. Right now I simply copy the code and the designer elements from form to form but that is obviously a terrible practice.
So I thought of making a class that could be easily added to a different form as a "component". The only problem is to be able to prototype and maintain this panel in the visual designer in such a way that if I want to change the panel's appearance in the future it gets changed for every class instance I created.
For instance I have a panel that provides search functionality:
Alongside with the code for click/textChanged events. I want to encapsulate it in a class, which I would be able to instantiate and initialize in any form's constructor to instantly add these controls (alongside events) into that form. Now it is not necessary for me to see the controls in the designer of the recepient form, however, I need to be able to see them in the designer somewhere in order to modify them if I would ever require that.
And if I do modify the appearance somehow (for instance add an extra button) these controls instantly change across the entire project, everywhere I instantiated the class.
I do know that all this can easily be done just creating a new form and encapsulating everything in it, I just wonder if it can be done for a group of controls instead.
You just described the perfect use of a User Control. It's easy to use and direct.
First Add a user COntrol to the project:
Then add the desired controls on the user control:
Build the project and you will see the UserControl on the toolbox:
Add them to the form as a standard control:
If you change the code for the user control (in this case adding a button click handler) uit will affect all the intances of that user control:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "Button Clicked"
End Sub
Note: If you have the Control in another project on the same solution, make sure you build that project too if you make any change.

Visual Basic 6 - using the control's name in its own event code snippet

Was wondering if it is possible to use a control's name in its own event sub without specifically hard coding it's name, so it can be used on other control's events, of the same type, with the exact same syntax.
for example:
Private Sub Command1_Click()
Me.Caption = "Hello"
End Sub
Will set the containing form's caption to "hello".if i copy the same line of code to another form, it will set its caption to "hello, and so on.
i was wondering if there's another keyword for the control Command1 itself, so i'll be able to to copy-paste the same code to another command button without hard coding the name of the control.
after years of writing code in vb6, I'm 90% sure it can not be done, but it's worth the shot.
One way to do this is with the Microsoft Script Control -- add one to your form, and then you can do, as per your example:
Private Sub Command1_Click()
ScriptControl1.AddObject "me", ActiveControl, True
ScriptControl1.ExecuteStatement "me.Caption = ""Hello"""
ScriptControl1.Reset
End Sub
If you don't already have the Script Control -- check Project/Components for Microsoft Script Control 1.0 (which is msscript.ocx) -- you can download it here:
http://www.microsoft.com/en-us/download/details.aspx?id=1949

How do I use the BindingNavigator to add entries to my table and save?

First some explanation:
I am attempting to make (what should be) a simple offline "character generator" for a game I am working on. I am using VB for this and I am still a beginner. I have created a WinForms application in VS 2012 and created a local database object to hold various data. Within the database I have a 'Players' table to hold all the data. I have also added a BindingNavigator to the form, yet I removed all but the add and delete buttons as navigation is controlled by a List control which is bound to the PlayersBindingSource. I also added a save button to the BindingNavigator.
I manually populated the 'Players' table with two example entries to work with and, when the form loads, the listBox displays the two entries by their 'Player Name' field correctly. When one is selected all the controls representing each field change accordingly. If I change any values and hit the save button, it seems to work with the code I'm using.
Now the problems:
When the add button is pressed, it makes a new entry in the ListBox, yet none of the default values specified are showing up. If I edit this entry and then hit save it seems to update fine. However, if I make any other changes to any of the entries and try to save, it throws an exception.
When the delete button is pressed, the entry disappears from the list as expected, but again, if I try to save, I get an exception.
here is the code that is in my form thus far (not much):
Public Class frmMain
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.PlayersTableAdapter.Fill(Me.DatPlayerDataSet.Players)
End Sub
Private Sub SaveToolStripButton_Click(sender As Object, e As EventArgs) Handles SaveToolStripButton.Click
Me.Validate()
Me.PlayersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DatPlayerDataSet)
End Sub
End Class
Also, if I look at the data contained in the 'Players' table, the two example entries remain unchanged, and no additional entries are added, so I don't think the edits were never actually committed to the table.
If anyone can help me with this, or could even simply provide a link to some tutorials that would help me, I would be highly appreciative. I have browsed this site, and microsofts msdn library, searching for information about data binding and navigation, yet I couldn't seem to find anything that helped.
You want do one more think in "btnNewPlayer_Click" sub after insert row, clear the list and re load the list items or call the function which you are using to fill the list items.
Try refreshing the page, the list might get updated.

Loosely couple a modal dialog - is this possible?

I have a winforms custom UI control library which contains a control for displaying modal dialogs Picture-in-Picture.
This custom control receives as a parameter a pointer to the control which has initiated it's display. So they are tied together. This allows the control to be modally displayed over the window which launched it.
Dim f As New PiPCustomDialog 'this form wraps another form PictureInPicture style
f.FormToLoad = New PrintOptions() 'this is the form the user will interact with
f.Owner = Me 'used to determine the size of PiPCustomDialog
Dim dr As DialogResult = f.ShowDialog(Me) 'shows PiPCustonDialog coating, f's OnLoad event initiates display of FormToLoad centered within.
The fact that this control requires f.Owner to be set is what is stinky. User32.dll has a function GetActiveWindow() which would maybe allow the control to be more self-sufficient.
Anyone out there who would like to teach this old dog a new trick? I want to learn a better way.
I'll use this solution for now:
Remove any validation that requires
owner to be set before showing the
form modally.
if owner isn't set inside the class that is transparent cover
(first form) - do a system call into
GetActiveWindow to get owner so the size of the window can be set.

Resources