Codenameone showForm not recognized in second form? - codenameone

In my StateMachine class I can use showForm("form2",null) to load a second form which loads the next form. In this next form I have a form2 class but if I try to do a showForm in this class the command is not recognized. So how do I call a form from a different class or does everything have to go through StateMachine?
Many thanks.

you can use show form2
Form form2 = new Form();
form2.show();
and you can pass an object of Statemachine (stateMachine) to Form1 then call
stateMachine.showForm("NewForm", null); // NewForm should be created in designer theme.

Related

Winforms OpenFileDialog problems

I would like to create a file dialog form that works like the one in MS Word. Specifically, you can select an existing file, create a new one, or delete a file, all within the file dialogue window. OpenFileDialog is a read-only deal. You can't create a new file with that control. SaveFileDialog can't be used to select an existing file. Is there a control that will do all of the above?
To create your custom dialog you should follow these steps:
Create a new form, call it MyFolderDialog
In the new form add the controls you need. For example, in order to let the user browse the file system, you can add a treeView and populate it using the classes System.IO.FileInfo and System.IO.FolderInfo.
Create a property in your form that reflects the user choice, something like public string SelectedFolder
Add a "Confirm" button and a "Cancel" button to your form
In the cancel button click event handler add the code this.DialogResult = DialogResult.Cancel;
In the confirm button click event handler add the code this.DialogResult = DialogResult.Ok;
Call your custom dialog like that
private string PickAFolder()
{
string selectedFolder = string.Empty;
using(var f = new MyFolderDialog())
{
if(f.ShowDialog() == DialogResult.Ok)
{
selectedFolder = f.SelectedFolder;
}
}
return selectedFolder;
}
Note that when the form is shown using ShowDialog method, the form won't dispose when it will be closed, so you can still read his properties after you confirmed. So it a good practice dispose it manually when you don't need it anymore. An elegant way to do it is to use the using keyword.
I hope this helps.

Call public function in User Control WPF

I am new to WPF
I have many master forms.which is having some buttons in all forms.so i wrote that button handing in usercontrols and using this same in all other master forms
now i want to handle each button.for that i wrote code on each form and trying to access it to user control class. but i couldn't. How can i do it ?
I have 3 forms
1)Aform
2)BForm
3)CForm
each form having 2 button.Say Save and Delete
Each form have to differently handle these buttons. So i wrote code on each form as function or Sub
Now I want to call that function to user control..'
I tried like this
in AForm.Vb :
Public Sub SaveA()
{}
In UserControl :
Dim ParentControl as Window=Window.GetWindow(me)
ParentControl.SaveA () // But i couldn't
What can i do for this ?
You need to type-cast the Window object to your specific Window implementation. For example given you defined the function in MainWindow class :
Dim ParentControl as MainWindow = CType(Window.GetWindow(me), MainWindow)
ParentControl.SaveA()

Retrieving Property from another WPF form

I am a beginner in WPF and trying to learn,So Sorry for this type of query.
I have added a property named GetName in WPF Form1 as below:
public string GetName
{
get { return this.uname.Text; }
set { this.uname.Text = value; }
}
Trying to retrieve the GetName property in WPF Form2 as below:
public Home()
{
InitializeComponent();
Form1 mn = new Form1 ();
MessageBox.Show(mn.GetName.ToString());
}
But I am getting prompt with blank. What I am doing wrong here. Please help.
You create a new Form:
Form1 mn = new Form1 ();
Then you request the Text value of what I assume is a TextBox control to be shown in a MessageBox:
MessageBox.Show(mn.GetName.ToString());
I would not expect GetNameto return a value, as when a TextBox control is created, unless specified, it will not have a value.
Between creating the Form and showing the MessageBox, you do not show your Form, for example:
mn.Show();
You need to show your Form first, input a value into your uname control and then request its value.
Calling ToString() on GetName is redundant, just use:
MessageBox.Show(mn.GetName);

how can i pass value to a running form

I have 2 forms : Form1 and Form2
Form1 start running with Application.Run()
and Form1 have a datagridview if user Start Edit the DataGridView
i run Form2 like this in CellBeginEdit event
Form2 addStock = new Form2(productNo, stockString, this);
addStock.Activate();
addStock.Show();
After Form2 finish the task, When i click a button on Form 2 i want to get value return to Form1 and show in the DataGridView on Form1 and close the Form2
i tried to pass the Form1's object
Form2 addStock = new Form2(productNo, stockString, this);
but on Form2 i can't access the Form1's DataGridview with that object
how can i do to accomplish this?
what i suggest made a custom class and make some static members and when you are navigating to form2 jux check them.
class CustomClass
{
public static int ProductNo;
public static string StockString;
}
//these are call to form2 from form1
CustomClasss.ProductNo=12; //some value
CustomClass.StockString="Some Value";
Form2 addStock = new Form2();
addStock.Activate();
addStock.Show();
now call these custom class members in form 2 and validate according to ur need..
like
if(CustomClass.ProductNo==2 && CustomClass.StockString=="Some String")
{
//do something
}
Hope it helpx..
Add public properties to Form2. After finishing the computation whatever you are doing within Form2 set the values to those properties. Now these values are accessible within From1 with the same From2 instance you have created to show the Form2.
Now within From1 access those property values of Form2.
Form2 addStock = new Form2(productNo, stockString, this);
addStock.Activate();
addStock.Show();
//Reading the property value of Form2
string stockValue = addStock.StockStringProperty;

Update window data. WPF

I have a WPF project with PRISM. In my bootstrapper I have following code.
protected override DependencyObject CreateShell()
{
Form1 form1= new Form1();
Form2 form2= new Form2();
var mainWindow = new MainWindow();
mainWindow.Show();
mainWindow.Activate();
RegionManager.SetRegionManager(form1, this.Container.Resolve<IRegionManager>());
RegionManager.SetRegionManager(form2, this.Container.Resolve<IRegionManager>());
RegionManager.UpdateRegions();
return mainWindow;
}
protected override IModuleCatalog GetModuleCatalog()
{
var moduleCatalog = new ModuleCatalog();
moduleCatalog.AddModule(typeof(MainModule));
moduleCatalog.AddModule(typeof(Form1Module), InitializationMode.OnDemand);
moduleCatalog.AddModule(typeof(Form2Module), InitializationMode.OnDemand);
return moduleCatalog;
}
On MainForm I have ListBox and button. When we select some item in the ListBox and click "Show" button the form1 is shown with some data and the mainWindow is hidden. Form1 also has button "Go to Main", when user clicks it I do form1.Hide() (hide form1 with data) and mainWindow.Show() (again show mainWindow).On mainWindow user selects another item from the ListBox and clicks "Show" - the form1 is shown and it should display new data because user selected new item on mainWindow but form1 displays old data (data which was shown when module for form1 was loaded for the first time).
Example - on mainWindow we have the ListBox with the list of offices of some company, we select "Office1" and click "Show", this mainWindow hides and form1 loads, form1 displays the expenses list for "Office1". When I select another office on mainWindow, e.g. "Office2" form1 should display expenses for "Office2" but it displays expenses for "Office1".
I do moduleManager.LoadModule("") when user clicks "Show" button on mainWindow. I found the information that we can't reload module, it means the module is loaded only when we click "Show" button for the first time, but how can we update the data on the view?
I am not sure I completely follow, but I will take a stab at this.
CreateShell should be for your main window only. Prism uses this to setup the very first window for the application. The only reason I have seen to make more than one visual window in here is for a splash screen.
So have CreateShell make your MainWindow. Then, have MainWindow create your other forms as needed. If you need new data each time, you can new them up each time.
The LoadModule part of your question is also a bit confusing. The ModuleManager is a way to allow you to get parts of your application without needing a hard reference it.

Resources