I have a VB6 form with buttons with the text 'Continue' and 'Cancel'. I want to check which one was clicked. In C# every form has a dialog result and I could set it before exiting the form depending on which button was clicked. I don't see this in VB6.
Is there a dialog result? If not what is the best practice for checking the dialog result?
To simulate the .net WinForms behaviour, you will need a helper function in your form's code:
Public Function ShowDialog() As VbMsgBoxResult
Me.Show vbModal
ShowDialog = Iif(Cancelled, vbCancel, vbOk)
Unload Me
End Function
The form level Cancelled variable can be set by the button event functions before calling .Hide() or .Close(), or you could have a variable containing the result code directly.
In VB6 a dialog generally returns an integer value, which may correspond to vbYes, vbNo, vbCancel, etc.
See this article for details: http://www.vb6.us/tutorials/understanding-msgbox-command-visual-basic
http://www.code-vb.com/fragments/Dialogs.htm#Msgbox OK-Cancel
You'll have to specify it on your form if you've created the form yourself.
The last answer in this post has a hint that may help: http://www.xtremevbtalk.com/archive/index.php/t-306663.html
Related
So on one form I have a button than opens a filtered form based on a combobox on the previous form. Works fine. But on the opened form I also have combobox for selecting records - which doesn't work when the form is filtered. I would want to disable the filter when user selects record in that combobox.
Is there a way to disable the form filter using expression in onChange event?
For example:
=[FilterOn]=False
or
=[Filter]=""
These don't work for me though.
Thanks
Cannot be an expression like that in event property. Could build a VBA custom public function with code to neutralize filter and call function in event property. It would be complicated because have to pass form name or form object as argument of function =ClearFilter("formnamehere"). I have not developed function code and really don't think this is best approach.
In most cases, when OnChange event is used, really should be AfterUpdate.
I've got standard CreateNewEntity screen. Entity can contain list of entities of some other type. By default there is an add button that opens modal window when user wants to add another entity into collection. However, default modal window was lacking some of the needed functionality so I've done a bit of research. Turns out that default modal screens cannot be modified. So, I found a nice custom modal window helper class. The problem is that I can't seem to be able to access modal window fields in order to enforce needed logic. There are two dropdown lists that are associated. Change in one will result in limiting the other dropdown list options. I'm stuck at this particular part:
var proxy = this.FindControl("DodavanjeParcele");
proxy.ControlAvailable += (s, e) =>
{
var ctrl = e.Control as System.Windows.Controls.Control;
//how to obtain access to ctrl fields?
};
"DodavanjeParcele" is custom modal window. Before this, modal window is instantiated and initialized. It pops up after button click and functions as expected. The only thing missing are above-mentioned rules. I need to set change event handlers for modal window fields in order to define rules. As seen above I tried to cast IProxy as a standard Windows control. This is where I got stuck. I can't seem to find a way to access control fields and set event handlers. Any thoughts?
If I understand you correctly, I'm not sure why you need to search through controls or cast anything.
Control1 is an entity which creates an AutoComplete Box (dropdown list). That selection is copied into a local property in the Control1_Changed method. That property is used as a parameter in a filter query to create Control2.
C#:
private void Control1_Changed()
{
this.MyLocalProperty = this.Control1.SelectedItem;
}
VB.NET:
Private Sub Control1_Changed()
Me.MyLocalProperty = Me.Control1.SelectedItem
End Sub
Just make sure you have Auto Execute Query checked in Control2's Properties and the second control should update and filter when Control1 changes the query parameter.
The code in my screen shots all takes place inside of Yann's Modal Helper so there is nothing special you need to do.
I have a form designed with the GUI designer with input textfields and buttons. I have attached actions to the buttons. When I call up the form with showForm(Form,null), the textfields are not accepting input and the buttons are not triggering the action. This is happening only for this form. Initially, there was the problem solved here Unable to call a specific form from a button in codenameone and then the problem solved here Simulator keeps defaulting to old Main form. What could be the issue now?
As far as I know there may be some issues as you say, but first need to see code
In the form after you added the text fields did you select the text field component and press action event?
Assuming you did that you should get a callback method in the Statemachine class.
This call will be invoked only when the user changes the content of the text field. You can run in the debugger and set breakpoints/step into code to see what is going on.
What's the name of the default red button with an X in the middle at the top right?
EDIT: I want to get the event associated with clicking that button.
You cannot disable the close box on its own using in properties window like you can with the minimize and maximize boxes. You can however disable the control box which contains them all.
Setting ControlBox to false will remove the minimize, maximize and close buttons.
You might want to consider why you are doing this though, as it's generally a good idea to let users quit out of windows using the close button (think of it as a cancel button).
EDIT:
You can handle when the user clicks on that close button using either the Closing or the Closed events of the Form. The difference between the two is that the Closing event fires before the form has closed (meaning that you can veto the closure by setting the Cancel property of the FormClosingEventArgs to true), whereas the Closed event fires after the form has actually closed.
it is possible to hook all messages goes to a form by implementing ImessageFilter interface
this link can be use full Using IMessageFilter to create a generic filter for operating system events
You can disable it by setting the ControlBox to false in the form properties, or in code like the following:
this.ControlBox = false;
Setting this will also hide the minimize and maximize buttons if that is OK. If not, the solution is a bit more elaborate.
In my application I call App.Current.MainWindow.Show()/App.Current.MainWindow.Hide() to show/hide my application but I don't know how to catch the event when the form is hidden/showed. Please help if you know how to!
One of your tags is WPF and the other is WinForms... I'm better with WinForms, so I'll answer for that tag.
The Form.Shown event documentation is here with sample code...
There is no corresponding Form.Hidden event. The best you can do is choose from Form.Closing or Form.Closed or one of the other events.
Added from my comment above
Question - if you're CALLING the Hide and Show in your code, why do you need to capture the events? You already KNOW when it's happening. If you want to run some code inside the form after hiding and closing it, expose the code as a public function, and call the function after showing and hiding the form...