Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm working on my first mobile app. I'm getting input from the User and having them click a button before retrieving data into a dataset. All that is working well but getting the data displayed has stopped me in my tracks. Can/Should I display it in the same page or create a 2nd one? How do I call a second page from my c# code? I don't know best practices for Xamarin and mobile so any assistance or direction would be helpful.
There are multiple ways of doing this and reasons for doing it, it all depends on your app. I assume you're not using xamarin forms, so I'll give default android/iOS answers.
Can/Should I display it in the same page?
If you're making the usual search control it helps displaying the search results in the same page as the one you are typing in.
If you have a list of items, where selecting one shows more details, then the usual way of doing it is to navigate to a new page that displays the information. So you'll have to create another page.
There are multiple ways of doing this it all depends on your app.
How do I call a second page from my c# code?
You don't call the second page from your first page, you rather launch the page and pass the information you want.
Android: You'll create a new Activity with it's layout file and use an intent to launch the activity from your Action (clicking a button in your case).
You can use this tutorial to get up to speed with miltiscreen Xamarin applications for android. Your code should look similar to the following.
Button yourButton = FindViewById<Button> (Resource.Id.YourButtonId);
yourButton.Click += (sender, e) =>
{
var intent = new Intent(this, typeof(SecondActivity));
StartActivity(intent);
};
To pass information to the second page you can use one of the intent.PutExtra() methods. Similar to
intent.PutStringArrayListExtra("YourKey", myList);
Which passes a list to the launching activity through the intent, storing the value under YourKey. In your SecondActivity you can get the data from your intent using
intent.GetExtra("YourKey")
iOS: Not much code involved so I'll list the steps to do this briefly. You can use this tutorial to get started with multiscreen iOS applications.
You'll create a new controller in your Main storyboard, using Interface Builder or Xamarin Studio.
On your first view, place your button.
press Ctrl and drag it to the new ViewController. On releasing your click select Show (push) segue.
In your FirstViewController override prepareForSegue and set the data you want to use in your SecondViewController.
Something like below.
public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue (segue, sender);
// set the View Controller that’s powering the screen we’re
// transitioning to
var secondViewController = segue.DestinationViewController as SecondViewController;
secondViewController.YourData = "Your data you want to pass over";
}
Let me know if this answers your question. Goodluck.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Pretty much new to Windows Forms, I know the C# language, just not in the same context. I have searched around for a while and it seems to me that every solution is doing something similar to this:
Label1.Text = "I'm a label".
But I don't understand where Label1 is coming from.
All I have is a new Windows Form Application, which comes with one form preloaded and a Program class. So as this class came with some code, I thought this would be a logical way of accessing the label's properties:
static class Program
{
static void Main(String[] args)
{
FormUpdate frmUpdate = new FormUpdate();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(frmUpdate);
// Why isn't this a suitable way of getting the label?
frmUpdate.label1.Text = "I cause an error!";
}
}
But I don't understand where Label1 is coming from.
Someone used the Visual Studio Designer for Windows Forms and dragged and dropped a Label component onto their form. As Visual Studio has no way of naming them, but needs a name, it simply counts up. The first dropped label is called "Label1".
The access specifier for those controls added is private by default and I'd suggest to leave it that way. If you want to interact with your form, either do it from inside your form or write a public method that you call that will then set all the private properties like the text of a certain label.
Generally speaking, Application.Run(frmUpdate); is running the program, based on the starting form you gave. Anything after that will have little effect. So you ran your form and after you closed it, you set the label. That's not going to have any visible effect. You need to do that before you run the form or while you are running it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My friend and I are trying to work on a text game using Visual Studios Community. As of now, we have started our project in windows form. One thing we are stuck on is being able to design multiple screens but using only one window. As of right now, the way we have it designed is after you click "Start Game" on the first window, it pops open a second window to the character select screen. Once you select a character, it opens a third window.
What we would rather do is be able to design the GUI to display a basic opening splash screen and clicking on "Start Game" would bring up a new "screen" but in the same window. The new screen should have it's own unique GUI from the initial splash screen. Also part of the game, we are going to want to put a pause menu with options. When the user clicks on the pause button, that should bring up a new "screen", again with it's own unique GUI from the main screen you would see during the game.
Is it possible to create multiple GUIs but only using one window in window form? If not, how could we make something like that happen?
Thanks in advance!
You have to use UserControl in this case. A UserControl can be set up as a whole form, then you simply swap the UserControls that you have created.
In visual studio create a UserControl item, put your user interface in them, basically very similar to designing a normal Form you just put buttons, labels and other stuff on it and wire up events and logics and you are ready to go.
You propably need to implement a global logic or business model to handle or pass the events of each usercontrol you are creating to have a unified model accross your application.
Here is a good tutorial on using UserControl
You can also apply transition animations while swapping between different controls, anyway if you google these stuff up you will find plenty of useful data.
You can create a wizard like control which can have a custom TabControl. Each tab page can then have different controls you would like to place. You can also create user controls and add them to tab pages which would make it a bit easy to maintain.
Customizing a tab page:
public class CustomWizard : TabControl
{
protected override void WndProc(ref Message m)
{
// Second condition is to keep tab pages visible in design mode
if (m.Msg == 0x1328 && !DesignMode)
{
m.Result = (IntPtr)1;
}
else
{
base.WndProc(ref m);
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.Tab)
return;
base.OnKeyDown(e);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.ResumeLayout(false);
}
}
You can then use this tab in your form and have next and back buttons. Handle the click event of these buttons to move back and forth.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am designing C# windows application using 3-Tier architecture, Basically i am making management system for super market in which i have created a form for generating BILL. I have used FlowLayout panel for generating 4 ComboBoxes, 3 TextBoxes and 2 Numeric UpDown respectively to hold Bill values accordingly. I have supplied add button with which we can create these controls dynamically on each button click, so, for example, when user clicks on the add button to add new item, new row will be generated with 4 CBs, 3 TBs and 2 NUpDowns. Having mentioned the scenario, I have following queries:
How can i access each and every of the control in each row in turn? So, for example, I want to access 3rd ComboBox of 5th row, How can I access that in particular.
I am using 3-tier application architecture to design the application. I have placed their functions in BusinessLogicLayer and have called them in UI in button event. Am i alright with this approach?
I want each ComboBox, in each row, to be connected with the first one. for example first one indicates main category when user selects anything from that, second combo box(sub category) should show items connected with the first one and so on. How can i do that?
Thanks
I don't know the very architecture of your application, but let me try and help you. Assumed you have some sort of Customer, Product and Order objects for your business logic the workflow could be the following
void ButtonFindCustomer_Click(object sender, EventArgs e)
{
m_order.Customer = Customer.Find(TextBoxFirst.Text, TextBoxLast.Text, TextBoxCustomerID.Text);
}
void ButtonAddProduct_Click(object sender, Event args)
{
m_order.AddArticle(Product.Find(TextBoxArticleNumber.Text), NumericUpDownArticleAmount.Value);
}
void ButtonSubmit_Click(object sender, EventArgs e)
{
m_order.Place();
}
I used the prefix for the member variable here just for clarity, for the lack on context. In your real code you should avoid it. Furthermore I have omitted the check if the user exists in ButtonFindCustomer_Click, this case should be handled, too. In ButtonAddProduct_Click the case a product is added is handled. Again the existence of the product is assumed, thus you'll have to introduce some error handling here, for example by using something like
if(Product.Exists(productNumber))
{
// add to order
}
else
{
// emit error message
}
The actual transaction is performed in the ButtonSubmit_Click handler. The order is validated and then sent to the data access layer (for example written to a SQL-Database). Once again the error handling is missing, please keep that in mind.
To get to your actual questions:
1) You'll somehow have to keep track the controls you created. If you are always creating them in the same groups, you should consider a user control, which avoids keeping track of which controls belong together. The control could - for example - contain a drop down box for categories, a drop down box for products and a numeric up down for the amount.
class ProductSelector : UserControl
{
... //add controls to user control
public event EventHandler CategoryChanged;
public event EventHandler ProductChanged;
...
public void PopulateCategories(list<string> names, list<string> ids)
{
...
}
public void PopulateProducts(list<string> names, list<string ids)
{
...
}
}
Now any time anything about the product is changed, you'll receive an event and can directly access your user control and all necessary data (if you wrote the functions in ProductSelector). If you want to access the controls in turn, you can either get all controls of type ProductSelector from MainForm.Controls or create a list of all ProductControls you added.
2) Yes, I think you'll be alright with this approach. Somewhere you'll have to access the functions of your BLL and UI event handlers are a good starting point for.
3) Please see me answer to 1).
I hope my explanation met your requirements and answered you questions. Feel free to ask, if I may help you any further.
I have an application for Windows 8 with a page (Frame) for displaying a list of items and a page for downloading & displaying the items details. I am also using MVVM Light for sending notifications.
Application use goes something like this:
Open Main Page
Navigate to List Page
Frame.Navigate(typeof(MyPage));
Choose Item
//Complete logic
Frame.GoBack();
Back on Main Page, I start downloading the file in the view model, I send ONE NotificationMessage saying BeginDownloadFile and after it is downloaded ONE NotificationMessage saying EndDownloadFile.
The first time I do steps 2,3, & 4 my NotificationReceived method is hit once, the second twice and so forth.
private async void NotificationMessageReceived(NotificationMessage msg)
{
if (msg.Notification == Notifications.BeginDownloadFile)
{
FileDownloadPopup.IsOpen = true;
}
else if (msg.Notification == Notifications.EndDownloadFile)
{
FileDownloadPopup.IsOpen = false;
}
}
Additional information: I only have one FileDownloadPopup, yet each time, an additional popup is shown each time the NotificationMessageReceived method is called.
My only conclusion is that between navigating forwards and backwards in my app, there are multiple MainPages being created and never closed. This results in many NotificationsMessageReceived methods just waiting for a notification to come their way so they can show their popup.
I have two questions:
1. Does this sound like normal behaviour for a Windows 8 app?
2. How can I close all instances of the MainPage or return to the previous instance without creating a new instance?
Please let me know if I have missed something important out before marking my question down.
This sounds normal to me. The default navigation behaviour in Windows 8 is to create a new page instance each time you navigate to a new page, regardless of whether this is forward or back navigation.
Try setting the NavigatinCacheMode on MainPage to Required. See the MSDN documentation for details of how page caching works.
It sounds like you are registering eventhandlers in the page and then not removing them. Each time you navigate to the page again the handler is being added again in addition to the one you previously added. Try to add your event handler in OnNavigatedTo, and make sure you unregister it in OnNavigatedFrom.
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
MyEvent.OnDownloadRequest += MyLocalDOwnloadHandler; // add the handler
}
protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
MyEvent.OnDownloadRequest -= MyLocalDOwnloadHandler; // remove the handler
}
I have asked the question "Is there something like master page in desktop applications?" Now I am in position that I have to extend the question. Thanks for understanding.
I have add one MDI master form into my project and several inherited forms that inherit MDI master one. I was using this code.
private void searchToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form child in this.MdiChildren)
{
child.Close();
}
Search childSearchForm = new Search();
childSearchForm.MdiParent = this;
childSearchForm.Text = "Search ";
childSearchForm.Show();
}
This code is triggered when I press some button on master form and the new in this case Search form is opened inside master.
Now my question is the right way to build desktop applications or there is some other more elegant way where content of user interface can be dynamic and switch from view to view by clicking on the buttons inside. For instance clicking on "Search" button on some search form will take you to search results grid, all that happening in one master form.
And if this is right way (which I doubt) how can I achieve to open other inside forms by clicking on buttons inside them. Also if I put some controls on masterpage they will appear two times in master form and in inherited form.
Thanks.
PS
I am using Visual Studio 2008 and MS SQL 2005.
If you are only wanting to show one view at a time you could create a new user control for each view you require. e.g One for your search results.
Then you could add a panel and clear the controls contained within the panel and add the new one to display the view you are after.
Or as described, the other option is to use a tab control, hide the tabs and set the visible index programatically.
Not sure how you would easily do this in winforms, but in WPF you could create a navigation app - a link driven navigation similar to a web browser experience but still a stand alone application. See http://msdn.microsoft.com/en-us/rampup/cc514215.aspx for details of how to get started.