I would like to be able to press shift+D+A+L to open another form (form2) ussing VB.net how do i do this?
Set the forms KeyPreview property to true, then add code to the forms KeyDown event. Y
Then use an if statement e.g
If e.KeyCode = Keys.F1 Then
Add each key you want as a condition and since you want to use shift add this to your if;
e.modifier = keys.shift
Then create a new instance of the second form and call the showdialog function.
Related
I have a TextBox nested inside a TabControl.
Form->TabControl1->TabPage1->TabControl2->TabpPage2->GroupBox->TextBox
When the TabPage1, TabPage2 is selected, so the TextBox is visible to the user all the TextBoxEvents works OK, but when the user selects another TabPage it doesn't work.
I have a timer that send data periodically to know if an external device is present on a specific virtual COM port.
When the external device answer I put that data in that TextBox and set a global flag(boolean) to let the rest of the program that a device is present.
I'm processing the received data on a Private Sub and changing that TextBox with a Lambda expression like this
Me.Invoke(Sub()
Me.VersionFirmwareTxt.Text = RespX.Substring(5)
End Sub)
You can access the TextBox by name from anywhere whether it is visible or not, via casting (CType), and update its text value using the syntax:
'(from within the same Form, e.g., Form1)
CType(TabControl1.TabPages(1).Controls("VersionFirmwareTxt"), TextBox).Text = RespX.Substring(5)
'(from a different Form)
CType(Form1.TabControl1.TabPages(1).Controls("VersionFirmwareTxt"), TextBox).Text = RespX.Substring(5)
If you dynamically added the TextBox to the controls of the parent (TabPage), you will know exactly where the TextBox is located, since you would have already used, e.g.:
TabControl1.TabPages(1).Controls.Add(VersionFirmwareTxt)
Whereas if you manually added the TextBox to the TabPage, you also know the parent control.
I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).
I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"
I tried this but it is not the same as pressing the same key on a keypad.
Private Sub Buton3_Click()
Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub
I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.
Public Sub projectID_KeyPress(KeyAscii As Integer)
MsgBox Chr(KeyAscii)
End Sub
This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:
http://access.mvps.org/access/forms/frm0031.htm
I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:
Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub
Don't forget similar click events for buttons 1-9
some things that may be helpful:
! is the bang operator see:
Bang Notation and Dot Notation in VBA and MS-Access
by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.
Then .Form gets the form wrapped by the subform control.
I hope this answers your question
I have a Save button on a form with a shortcut key set (ALT+S).
In my datagrid in the cellvalidated event I make a determination if I can enable or disable this button for the users.
Similar to the old VB6 problem of Event firing order....
If the button was currently enabled, but user puts invalid data in the datagrid cell. If they Click on the button, the cell validated event fires, disables the button - no issue. When, instead, they input the bad data, and do ALT+S, the cell validated event fires, but in this case the Button_Click event still fires.
Any way to prevent this? Basically if the use the ALT+, I don't want the Click event to fire.
If everything else fails - there is this method (in pseudo-code)
Class Form
private _validated as Boolean
sub Cell_validate
' validate here and set
_validated = true/false
end sub
sub Button_Click
If not _validated then Return
' have your save logic here
end sub
End class
This way you will protect your code from executing actual logic of Button_Click when button disabled.
Using VB.Net (Windows Application)
I have one main form(Data entry form), i creating many form at run time.
Code for creating a multiple form at run time.
Button1 click
If IsNothing(frm) OrElse frm.IsDisposed Then
newfrm = New frmEntry
End If
newfrm.Show()
I have popup windows for selcting the value in the Data entry form.
Code for selcting the value from popup windows
Popup Window code
If e.KeyCode = Keys.Enter Then
frmEntry.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
The above popup window code is working for Data Entry Form, but it is not working for new forms (at run time)
When i select the value from popup windows means, it is appearing in frmentry textbox, not in newfrm textbox.
Popup windows selected value should appear in current active form.
What wrong in my code.
Need VB.Net Code Help
If the form you open the popup from is what you need to change values in, have you considered passing a reference to the opening form to the popup when you open it? So that you have direct access to the form that has the controls that will need updated?
This constructor in the popup window:
Private mOpeningForm As frmEntry
Public Sub New(OpeningForm As frmEntry)
InitializeComponent()
mOpeningForm = OpeningForm
End Sub
This modified to use the reference to the form sent to the popup form:
If e.KeyCode = Keys.Enter Then
mOpeningForm.txtbox1.Text = gridview1.Rows(crRow).Cells("code").Value.ToString().Trim()
End If
This in the form when the window is being created at runTime:
If IsNothing(mEntryForm) OrElse mEntryForm.IsDisposed Then
mEntryForm= New frmEntry(me)
End If
mEntryForm.Show()
At the top level of the Data Form Class (The one creating the popups)
private mEntryForm as frmEntry
That will allow you to have a reference to the Instance of frmEntry from anywhere in the data form class. (Note that I changed the name of the popup form instance in for the button click event code too)
How to make a form always stay on top of another form.
Also both form's enabled property must be true
I don't wanna make use of topmost property.
Edit 1 :
Another similar question in C# says you can use Form.Owner Property to do the trick , how to make use of this property ?
Edit 2 : The Owner Property works fine untill I try to open it the second time.
This is the error message I get
I believe you need the frm.ShowDialog() instead of frm.Show()
frm is the other form you need to show over your current form and instead of using Show, this will make it as a dialog form over your current form (however you won't be able to select the parent form or the form behind it unless you close the frm form
EDIT
To enable edit on both forms
Form2 frm = new Form2();
frm.Owner = this;
frm.Show();
Hope this helps you out.