Get information from different hidden Form C++/clr - c++-cli

I have a Windows Form application I am creating in C++/CLR Visual Studio 2012.
The goal is to have the user input values into the form named Home Page. Then once all the info is filled in they click a button and the Home Page form is hidden and then second form called Setup Info is shown.
The part I need help with is the info from Home Page needs to be accessible in Setup Info. To get an idea of how my files are setup this is the youtube video I followed to create my C++ Windows Form Application Click Here.
In my HomePage.h
// Button that will hide the Home Page Form and then show the SetupInfo Form.
private: System::Void Start_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
SetupInfo^ SetupInfo = gcnew ExcelToPPT::SeuUpInfo();
SetupInfo->Show();
}
In my Setup Info.H
// When Setup Info is loaded button1 will have the text of textbox1 from Home Page Form.
private: System::Void SetupInfo_Load(System::Object^ sender, System::EventArgs^ e) {
button1->Text = HomePage->Textbox1->Text;
}
This is the general idea but it doesn't work. How do I get this to work?
Let me know if you need any more information.
[EDIT]
I am able to do this through extern global variables, but is there another way to directly access the text text boxes?
Also wen I exit out of my Setup Information it doesn't seem to kill my program how do I solve this problem?

The simplest thing would probably be to just pass your Home Page form to the new SetUpInfo form.
private: System::Void Start_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
SetUpInfo^ setUpInfo = gcnew ExcelToPPT::SetUpInfo(this);
setUpInfo->Show(); ^^^^
}
In SetUpInfo.h:
public ref class SetUpInfo : Form
{
private:
HomePage^ homePage;
public:
SetUpInfo(HomePage^ homePage);
};
In SetUpInfo.cpp:
SetUpInfo::SetUpInfo(HomePage^ homePage)
{
this->homePage = homePage;
}
void SetUpInfo::SetUpInfo_Load(System::Object^ sender, System::EventArgs^ e)
{
button1->Text = this->homePage->Textbox1->Text;
}

Related

Updating a textbox in main GUI from a thread (created on button click) in cli

I am very new with C++/CLI, which is based on c#. I have a main GUI form.
public ref class MyForm : public System::Windows::Forms::Form
On clicking a button in the from I am creating a thread using CreateThread. Code as following:
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
HANDLE h1;
h1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread1,0, 0, &threadID1);
}
Now my problem is I need to update a TextBox in Myform from the thread. Can anybody please tell me how to do it in cli?
It is safe to use .NET Thread^ in this scenario. Inside your thread1 method use Control::BeginInvoke or Control::Invoke like #AlexF mentioned. Here you have an example from C#.

Manipulation events of MediaElement not fire when on FullWindows mode

When I set player not in fullscreen (player.IsFullWindows = false), event work normally but when change player to full screen all manipulation event not work. Anyone have solution?
<MediaElement Name="player"
Margin="10,5" ManipulationCompleted="player_ManipulationCompleted"
ManipulationDelta="Grid_ManipulationDelta"
ManipulationMode="TranslateX"
>
I can reproduce this scenario by enabling both the IsFullWindow="True" and the AreTransportControlsEnabled="True". I think it makes sense, because when we are in the Full Window mode, it will go to the new layer named FullWindowMediaRoot instead of the MediaElement. Inside the FullWindowMediaRoot, it is the MediaTransportControls. You can see that clearly by using the Live Visual Tree as following:
So when we are in the Full Window mode, we need to handle the manipulation event of the TransportControls instead of the manipulation event of the MediaElement as following:
public MainPage()
{
this.InitializeComponent();
player.TransportControls.ManipulationMode = ManipulationModes.TranslateX;
player.TransportControls.ManipulationDelta += TransportControls_ManipulationDelta;
player.TransportControls.ManipulationCompleted += TransportControls_ManipulationCompleted;
}
private void TransportControls_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
}
private void TransportControls_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
}
Thanks.

Going from a parent form to a child form without creating a gcnew form

Hello I have a main form (Form1) and a child form (Form5). If I click a button for the first time I want it to open a new form. However if it is being clicked for the second time I want it to open the form I opened the first time, holding that forms data I will have filled in (textboxes etc). This is what I have:
.cpp file:
System::Void Form1::button5_Click(System::Object^ sender, System::EventArgs^ e){
formclick++;
if (formclick == 1)
{
Form5 ^dos1 = gcnew Form5(this, MyArray, MyArray1);
dos1->Show();
}
if (formclick==2)
{
otherform->Show();
}
Form1.h file:
> Form1(System::Windows::Forms::Form ^ Form5)
> {
>
>
> otherform = Form5;
> InitializeComponent();
> } public: System::Windows::Forms::Form ^ otherform;
However I get the error:
An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll
Additional information: Object reference not set to an instance of an object.
TIA
You are storing the newly created form in the local scope of the button5_click function (in the dos1 variable) and that means it is free to be removed from memory when the function exists.
The code excerpts you've given is a little messy, but it could be enough for you to change the click funtion to the following:
System::Void Form1::button5_Click(System::Object^ sender, System::EventArgs^ e){
if (!otherForm)
otherForm = gcnew Form5(this, MyArray, MyArray1);
else
otherform->Show();
}
Code not tested, but the principal thing is that you need to store the newly created form in a class member, and not only locally to the click funtion!
Regards
Even

Replicate Hardware Back Button Functionality from UI in Windows Phone

I'm trying to write a windows phone application and am wondering if it's possible to have a software button in the UI that does the same thing as the hardware back button (just sends a system back command). I can't seem to find any information on how to do this online.
try this:
XAML:
<Button x:Name="btnBack" Content="Back" Click="btnBack_Click"></Button>
CS:
private void btnBack_Click(object sender, RoutedEventArgs e)
{
if (NavigationService.CanGoBack)
NavigationService.GoBack();
else
App.Current.Terminate();
}
This would work as same Back button. if any back-state is there it would go to that state or if not it would close (Terminate) the Application.
you can override the back button function
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
//Do your work here
base.OnBackKeyPress(e);
}

Invoking Message dialog from Settings Flyout causes Message Dialog to flicker

I'm trying to invoke messagedialog from setting flyout for my Windows 8 Metro app but it's causing the message dialog to flicker. Below is the code.
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested+=settings_CommandsRequested;
}
private void Settings_CommandsRequested(SettingsPane sender, SetttingsPaneCommandsRequestedEventArgs args)
{
SettingsCommand cmd = new SettingsCommand("test","test1232",new UICommandInvokedHandler(CreateDialog));
args.Request.ApplicationCommands.Add(cmd);
}
private void CreateDialog(IUICommand command)
{
if (ReferenceEquals(command.Id, "cmd"))
{
MessageDialog md = new MessageDialog("Hi");
md.ShowAsync();
}
}
I've contacted official microsoft dev-support and their response was:
"MessageDialog is not recommended within the SettingsFlyout".
So in case you want to implement something simillar to support user's decision from the SettingsPane, you should either:
1) Enable toggling feature in the Flyout.
2) Desiging the SettingsFlyout so it lets the user make decision (for example in Logout cases, add Yes/no buttons inside the settingsFlyout) - Thats the option I chose.