Calling button click from another button click - windows-phone-7

How to press RoutedEventArgs e button (button in page) from EventArgs e button (button on application bar) in windows phone 7
private void button3_Click(object sender, EventArgs e)
{
button0_Click(sender, e);
}
private void button0_Click(object sender, RoutedEventArgs e)
{
}
when i am using above code its giving me
cannot convert from 'System.EventArgs' to 'System.Windows.RoutedEventArgs'
Please Help
SMS CODE:
SmsComposeTask SCT = new SmsComposeTask();
PhoneApplicationService PAS = PhoneApplicationService.Current;
public string SMSNO;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
object sample;
if (PAS.State.TryGetValue("numbertext", out sample))
SMSNO = sample as string;
if (PAS.State.TryGetValue("messagetext", out sample))
txtOutput.Text = sample as string;
base.OnNavigatedTo(e);
}
private void button2_Click(object sender, RoutedEventArgs e)
{
if (txtOutput.Text != "")
{
SCT.To = SMSNO;
SCT.Body = txtOutput.Text;
SCT.Show();
}
else
{
MessageBox.Show("Output is Empty to send SMS.", "Wait!", MessageBoxButton.OK);
}
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
PAS.State["numbertext"] = SMSNO;
PAS.State["messagetext"] = txtOutput.Text;
base.OnNavigatedFrom(e);
}

If you don't use the parameter inside button0_Click, you can just call button0_Click(sender, null); (the reason is that the event from the application bar don't bubble that's why they don't have a RoutedEventArg parameter)

Related

How to Supress / permently Hide error box of windows media player

HI i wanted to Hide this error box:
i tried serching on internet but did not find usefull results , i am a fresher in coding so any way or any code that can help me ?
This issue is caused from server not acsepting first time but secind time it works great .
it would be great if u provide me easy steps .
MY Currrent code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Media_Player
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
label2.AutoSize = true;
label1.AutoSize = true;
}
private void button1_Click_1(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = ("http://y0b.net/radiosa.m3u");
MessageBox.Show("Successfuly Selected Radio SA , you will encounter a error , click close and then click play . " , "Thank You" , MessageBoxButtons.OK);
axWindowsMediaPlayer1.Ctlcontrols.play();
label2.Text = "Playing Radio SA";
}
private void button2_Click_1(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
}
private void button3_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.play();
}
private void button4_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = ("http://y0b.net/radiosa2.m3u");
MessageBox.Show("Successfuly Selected Radio SA Clasic , you will encounter a error after this mesage , click close and then click play . ", "Thank You", MessageBoxButtons.OK);
axWindowsMediaPlayer1.Ctlcontrols.play();
label2.Text = "Playing Radio SA CLASSIC ";
}
private void button5_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Visible = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
radioButton1.Checked = false;
axWindowsMediaPlayer1.Visible = true;
}
private void button6_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = ("http://y0b.net/radiosa3.m3u");
MessageBox.Show("Successfuly Selected Radio SA Dance Department , you will encounter a error after this mesage , click close and then click play . ", "Thank You", MessageBoxButtons.OK);
axWindowsMediaPlayer1.Ctlcontrols.play();
label2.Text = "Playing Radio SA Dance Department";
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.volume = trackBar1.Value;
label4.Text = trackBar1.Value.ToString();
}
private void label4_Click(object sender, EventArgs e)
{
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
}
private void progressBar1_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.playCount.ToString();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
}
}
Try this out. I suppressed the error message by setting enableErrorDialogs to false, then repeatedly asked it to play every 250 ms in a loop, with a ten second time out:
private async void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
axWindowsMediaPlayer1.settings.autoStart = true;
axWindowsMediaPlayer1.settings.enableErrorDialogs = false;
axWindowsMediaPlayer1.URL = "http://y0b.net/radiosa3.m3u";
DateTime stopAt = DateTime.Now.AddSeconds(10);
while (DateTime.Now<stopAt && axWindowsMediaPlayer1.playState!=WMPLib.WMPPlayState.wmppsPlaying)
{
axWindowsMediaPlayer1.Ctlcontrols.play();
await Task.Delay(250);
}
if (axWindowsMediaPlayer1.playState != WMPLib.WMPPlayState.wmppsPlaying)
{
MessageBox.Show("Failed to load stream!");
}
button1.Enabled = true;
}
Music started playing after about two seconds for me. Your mileage may vary...
Note that I added async to the method handler at the top to allow the use of await Task.Delay(250);.

C# MySql - data does not appear after insert new data

First of all, I'm new to C# and also programming. So, my situation is after I insert data from a textbox to MySql database, the new data does not appear. FYI, I have the navigation (next previous) button. I have to re-run the apps in order for the new data to be displayed. Here's part of the codes:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//MySql codes to display in textbox
showData(pos);
}
public void showData(int index)
{
txtDisplay.Text = table.Rows[index][0].ToString();
}
private void btnPrevious_Click(object sender, EventArgs e)
{
}
private void btnNext_Click(object sender, EventArgs e)
{
}
private void btnGenNext_Click(object sender, EventArgs e)
{
//codes to generate new data and also insert into db
}
}
Here's my full codes:

photo chooser task windows phone 7.1

i need to take a picture from the directory of Windows phone in my application so i add a child Windows when i click on the text in this child Windows i add a button and i called
public partial class AnnotationControl : ChildWindow
{
public ObservableCollection<string> cercle { get; set; }
public AnnotationControl()
{
InitializeComponent();
}
private void ChildWindow_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void btnsave_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void btnCancel_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void browse_Click(object sender, RoutedEventArgs e)
{
PhotoChooserTask objPhotoChooser = new PhotoChooserTask();
objPhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooseCall);
objPhotoChooser.Show();
}
but when i clicked on the button to choose a picture the application crashed
"Application_UnhandledException"
some one have any idea please
Use this may be helpful
private void changeImage(object sender, RoutedEventArgs e)
{
PhotoChooserTask photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
photoChooserTask.Show();
}
void photoChooserTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
imageTapped.Source = bmp;
}
}

Windows store app pinch zoom handling

I have followed the instruction on msdn about GestureRecognizer! for handling pinch guesture. However, I can't get the ManipulationUpdated called. Is there anything I'm missing?
In my C# class,
`private GestureRecognizer gesture = new GestureRecognizer();`
In my constructor:
gesture.GestureSettings = GestureSettings.ManipulationScale;
gesture.ManipulationUpdated += gesture_ManipulationUpdated;
gesture.ManipulationStarted += gesture_ManipulationStarted;
gesture.ManipulationCompleted += gesture_ManipulationCompleted;
In my pointer events:
private void PointerPressed_1(object sender, PointerRoutedEventArgs e)
{
var point = e.GetIntermediatePoints(null);
gesture.ProcessDownEvent(point[0]);
}
private void PointerMoved_1(object sender, PointerRoutedEventArgs e)
{
gesture.ProcessMoveEvents(e.GetIntermediatePoints(null));
}
private void PointerReleased_1(object sender, PointerRoutedEventArgs e)
{
var point = e.GetIntermediatePoints(null);
gesture.ProcessUpEvent(point[0]);
gesture.CompleteGesture();
}
void gesture_ManipulationCompleted(GestureRecognizer sender, ManipulationCompletedEventArgs args)
{
System.Diagnostics.Debug.WriteLine("Manipulation Completed {0}", args.Cumulative.Scale);
}
void gesture_ManipulationStarted(GestureRecognizer sender, ManipulationStartedEventArgs args)
{
System.Diagnostics.Debug.WriteLine("Manipulation Started {0}", args.Cumulative.Scale);
}
void gesture_ManipulationUpdated(GestureRecognizer sender, ManipulationUpdatedEventArgs args)
{
System.Diagnostics.Debug.WriteLine("Manipulation Updated {0}", args.Cumulative.Scale);
}
Try to urn on all the flags in the gesture settings property. As described in your link:
gesture.gestureSettings =
Windows.UI.Input.GestureSettings.manipulationRotate |
Windows.UI.Input.GestureSettings.manipulationTranslateX |
Windows.UI.Input.GestureSettings.manipulationTranslateY |
Windows.UI.Input.GestureSettings.manipulationScale |
Windows.UI.Input.GestureSettings.manipulationRotateInertia |
Windows.UI.Input.GestureSettings.manipulationScaleInertia |
Windows.UI.Input.GestureSettings.manipulationTranslateInertia |
Windows.UI.Input.GestureSettings.tap;

MediaElement repeatedly play Exception

I'm new in WP7, and I am trying to play sounds with a MediaElement when I press a button.
Its works, but unfortunately I get "Operation not permitted on IsolatedStorageFileStream" Exception when I press the button repeatedly, before the sound begins. How can I avoid that?
The Play method:
public void Play(string filename)
{
try
{
mediaElement.Stop();
mediaElement.ClearValue(MediaElement.SourceProperty);
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = isf.OpenFile(#"shared\transfers\" + filename, FileMode.Open))
{
mediaElement.SetSource(fileStream);
mediaElement.IsMuted = false;
mediaElement.Volume = 1.0;
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
Event handlers:
void me_MediaOpened(object sender, RoutedEventArgs e)
{
mediaElement.Play();
}
void me_MediaEnded(object sender, RoutedEventArgs e)
{
mediaElement.ClearValue(MediaElement.SourceProperty);
}
If you'd like for the user to be allowed to click the play button only once. One way would be.
public bool IsPlaying = false;
void me_MediaOpened(object sender, RoutedEventArgs e)
{
if(!IsPlaying){
mediaElement.Play();
IsPlaying = true;
}
}
void me_MediaEnded(object sender, RoutedEventArgs e)
{
if(IsPlaying){
mediaElement.ClearValue(MediaElement.SourceProperty);
IsPlaying = false;
}
}
Loading the filestream to a memorystream, before playing should make it more flexible, if you're dealing with low size streams.

Resources