Create IconicTile without leaving the app - c#

I define an IconicTile and and create it as such:
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), icontile, true);
The app closes and the user gets to the start-screen, where the live-tile got just pinned.
How could I achieve the same effect, without leaving the app?

You can't (create a Start screen tile without the user seeing what your app is doing).

Related

C# Open a form from another form (too much processing memory)

I have been looking for some time on ways to open a second form from another already shown form.
This is some piece of code that works:
frmSecond second = new frmSecond();
this.Hide();
second.ShowDialog();
this.Close();
What it does basically is to Hide() the currently opened form, then it opens another form (the ShowDialog() method). It will only Close() the currently hidden form when the form you have just created is closed.
The problem here is: this way of doing it creates an immense thread of forms. If I need to go from frmSecond to frmThird, it will maintain the first form and the frmSecond being executed in the background, while only showing the frmThird.
Then, as the frmThird is open, if I need to get back to the first form, I would use some code like:
frmFirst first = new frmFirst();
this.Hide();
first.ShowDialog();
this.Close();
And it would create another frmFirst! Then we would have three forms being executed in the background (the first frmFirst, frmSecond, and frmThird).
This method works, but uses an increasingly amount of processing memory, which may be prejudicial for any kind of project.
Is there any alternative or add up to correct this problem?
If anything is unclear, please don't bother in letting me know.
Thank you.
If you want to get access to already created forms try using the static Application.OpenForms property. It contains a list of all of the forms currently open in your application. Documentation is here.
As an example, if you always want to keep frmFirst open and then navigate back to it when you close one of your other forms you can do this:
frmFirst existing = Application.OpenForms.OfType<frmFirst>().FirstOrDefault();
if (existing != null)
existing.Show();
You would need to remove your this.Close() calls for this to work.
To free the memory you need to dispose the form using the Dispose method when it is no longer needed.
Seems like you have a desing error here
Then, as the frmThird is open, if I need to get back to the first
form, I would use some code like:
frmFirst first = new frmFirst();
this.Hide();
first.ShowDialog();
this.Close();
This will leave the original created frmFirst in memory, not visible, doing nothing but eating memory.
If you know you want to get back to frmFirst that was created before, why not just do this :
frmFirst.Show();
and save you lots of memory.
You have 2 choices actually
Hide forms and reactivate them when needed
Close and dispose forms, and recreate them when needed
What you are doing is creating each form over and over again, without getting rid of the prior created forms. Hence you need lots of memory for hidden forms...

Remove UIAlerts When App Goes to Background

In my app I give a alert, if the user wants to confirm the offer or not.
Now I noticed that if the user hits the home button, the alert stays there & makes my app crash if he would enter anything.
How can I remove the alert (all UIAlerts) when I go to background mode?
Kind regards,
Glenn.
Edit 1:
Basically I a making a offer page. When the user clicks OK, I am showing a UIAlert for extra confirmation.
Now I also have functionality that when a user closes (home button) the app & restarts it, it will go to the overview page (where all the products are) and will ask the server for the data (makes the data up -to-date again.).
Normally there would be no problem with my app going into background mode. But with the functionality of refreshing the data & going to another controller it probaly gives problems. Therefore I need to be able to close all the UIAlerts still active.
You app crashes not because of UIAlerts but because something is going wrong. Even if you put an app in the background while showing a UIAlert, the alert stays there.
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
you can use it with this method in AppDelegate.m:
- (void)applicationDidEnterBackground:(UIApplication *)application
but Nikos M. was right: you should find and fix the source of this problem, but not to disguise it. there is a simplest way to show alert, check it, may be it'll help:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Some message" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];

Is it Possible to Place a Permanent ShellTile on the Start Screen

I'm wondering if it is possible to leave out the Uri QueryString parameter so that when a user pins a tile, it may not link to the application. This would be for design reasons when pinning several ShellTiles onto the Start Screen. The user would of course have the option to delete the tile manually from the Start Screen or from a button within the app itself. It seems when trying this I am still taken to the application but a debug error also occurs.
An example of when I create the ShellTile is as follows
ShellTile.Create(new Uri("/MainPage.xaml?" + Constants.Key + title, UriKind.Relative), LiveTile);
Can this be modified somehow?
Your secondary tile must have unique navigation URI. However you could navigate to some page that would immediately close itself. It is not the best solution but there isn't any better way.
For uniqueness just use Guid. You can close app in code with Application.Current.Terminate() for example.

C# Application loaded without focus still steals it on the first injected mouse event

I have two applications, the first is a full directX application written in c++, the second application is written in c# and renders flash videos, avi's, pdf's etc using ActiveX COM objects. The first application then captures the content of this c# app, and renders it into the 3d environment as a texture. This all works as intended, and I have code in the directX app to allow me to send key and mouse events to the c# app via SendMessage and PostMessage.
My problem lies with initial startup. I have the c# app set to start up without activation, using:
protected override bool ShowWithoutActivation
{
get { return true; }
}
which is the equivalent of SW_SHOWNOACTIVATE in the CreateProcess call. The application launches fine, and renders fine on the c++ app's texture. However, the very first mouse click forces the c# application to steal focus, and thus drops my directx context. Does anybody know why this happens, or if there's any way around it?
If I launch the c# app and dont ever click on it, the c++ app when launched still runs as intended, its only when launching it through code:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESIZE;
si.wShowWindow = SW_SHOWNORMAL;
si.dwXSize = 400;
si.dwYSize = 400;
if(!::CreateProcess(program, arguments, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
return false;
}
else
{
// use EnumWindows to conforim the app is open and get its HANDLE
}
Cheers in advance for any help,
Wayne
you an also try to make the main c# form hidden by setting its properties as WindowState=Minimized
and ShowInTaskbar=false.
then at a certain moment, if you want, you can change the above properties to bring the application form to front.
In this case, the application will be running doing all its jobs but it will not be visible. you can then capture its active region without making it visible on the screen.
Sending key presses doesn't sound like the proper way to do communication between two programs. Could you set up some sort of COM interface between the two programs? Here's a Microsoft page on Interprocess Communication with some other techniques too.

Five Questions regarding the use of C# / VisualStudio 2005

I've some questions .. and I really need your help.
I have an application.
First I display a splash screen, a form, and this splash would call another form.
Problem: When the splash form is displayed, if I then open another application on the top of the splash, and then minimize this newly opened application window, the splash screen becomes white. How do I avoid this? I want my splash to be displayed clearly and not affected by any application.
I'm using a DropDownList but I realized that there is 2 types of it . I found "Dropdown" which makes the text inside the DDL editable, and "DropDownList" which doesn't.
Problem: when I tried to use DropDownList control it doesn't allow me to add a default text while DropDown does so I want a DropDownList control which prevent modifying on the text and allow a default text .. what property should I use?
Can I add "?" which denotes to Help button to the FormBorder (with the minimization, maximization, and close buttons )
Can I change the colour of the Formborder from its default colour (blue) ?
One of my application functionality is to copy files from server to phone into a certain folder in memory card.
Problem : can I determine the free size of the MMC to notify the user if it's full while copying.
3) You have to set the "HelpButton" property of the form to true. However the "?" button is only visible if you deactivate the maximize and minimize buttons by setting "MinimizeBox" and "MaximizeBox" to false.
Here are a few...
1) you need to launch the window in another thread so that your app can do what it needs to do to start. When the startup finishes, signal to the splash screen that it can close itself.
2)
dropDownList.SelectedIndex = 0;
4) I would not recommend doing so. It is based on the system color scheme, which the user sets. I would not like an app to decide for itself which scheme to use.
5) if the MMC shows up as a mapped drive you could use one of these techniques
Once again there is no answer to this guys question.
Yes, do as the other guy said and launch the splash screen in its own thread.
There is only one type of ComboBox in .Net, However there is a property called DropDownStyle which sets its functionality.
Yes, I am clueless on how this one works and never needed it.
Yes you betcha, Its called non-client painting. you can find more info on it here http://www.codeplex.com/CustomerBorderForm/Wiki/View.aspx?title=Painting%20NonClient%20Area&referringTitle=Home
I Need more details on this.

Categories

Resources