TweetInvi Listview can't get TweetID - c#

I'm trying to get Tweet ID via TweetInvi API but always get null point exception. I'm out of options and can't understand what i did wrong. Here is my code. Problem occurs when i select desired Item from view and press retweet.
namespace MIF_TwitterApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Auth.SetUserCredentials("KEY", "KEY", "KEY",
"KEY");
}
private void Form1_Load(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
//PROFILE
profileImage.ImageLocation = user.ProfileImageUrlFullSize;
nameLabel.Text = user.Name;
usernameLabel.Text = "#" + user.ScreenName;
followersLabel.Text = "Followers: " + user.FollowersCount;
}
//Tweeting with PICS
private void tweetBtn_Click(object sender, EventArgs e)
{
if (tweetBox.Text != "")
{
if (imgUploadPath.Text != "")
{
byte[] file = File.ReadAllBytes(imgPreview.ImageLocation);
Tweet.PublishTweetWithImage(tweetBox.Text, file);
imgPreview.ImageLocation = "";
imgUploadPath.Text = "";
tweetBox.Clear();
MessageBox.Show("Tweet posted!");
}
else
{
Tweet.PublishTweet(tweetBox.Text);
MessageBox.Show("Tweet posted!");
tweetBox.Clear();
}
}
else
{
MessageBox.Show("Please enter text!");
tweetBox.Clear();
}
}
private void addImg_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
imgPreview.ImageLocation = ofd.FileName;
imgUploadPath.Text = ofd.FileName;
}
private void dropImg_Click(object sender, EventArgs e)
{
imgPreview.ImageLocation = "";
imgUploadPath.Text = "";
}
private void timelineBtn_Click(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
var getTweets = Timeline.GetHomeTimeline(40);
listView1.Clear();
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Tweet", 570);
listView1.Columns.Add("Created By", 130);
listView1.Columns.Add("Create Time", 130);
listView1.Columns.Add("Likes", 60);
listView1.Columns.Add("Retweets", 70);
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
}
}
private void postsBtn_Click(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
var getTweets = Timeline.GetUserTimeline(user, 40);
listView1.Clear();
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Tweet", 570);
listView1.Columns.Add("Created By", 130);
listView1.Columns.Add("Create Time", 130);
listView1.Columns.Add("Likes", 60);
listView1.Columns.Add("Retweets", 70);
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
}
}
private void retweetBtn_Click(object sender, EventArgs e)
{
var checkedItems = listView1.SelectedItems;
long a = (long)listView1.SelectedItems[0].Tag;
var user = User.GetAuthenticatedUser();
var retweet = Tweet.PublishRetweet(a);
MessageBox.Show("Retweet was successfull");
listView1.Items.Clear();
}
}
}
Breakes on long a, I can't figure out how to get that Long Tweet ID
Here is the full code

Problem was that my X was not incrementing correctly as it was out of for loop.
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
x = x +1;
}

Related

Save a copy of the file to specific folder, from a LinkLabel Hyperlink

I have a program that creates a list of hyperlinks to the files i search for. I can click the resulting hyperlink and the PDF opens. I would like to also have it make a copy of the pdf on my C: also without dialog. The source of the files is from the network. FileSearchButton_Click will search a directory for files with the content that match my search string.
aLinkLabel_LinkClicked is where I feel the copy action should be done
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.DirectoryServices;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FindFilesBasedOnText
{
public partial class FileSearcherBasedOnSpecificText : Form
{
SmartTextBox DirectoryTextBox = new SmartTextBox();
SmartTextBox SearchTextBox = new SmartTextBox();
SmartButton SearchButton = new SmartButton();
SmartButton FileSearchButton = new SmartButton();
public FileSearcherBasedOnSpecificText()
{
InitializeComponent();
DirectoryTextBox.Location = new Point(70, 12);
DirectoryTextBox.ForeColor = Color.Black;
DirectoryTextBox.ForeColor = Color.Black;
this.Controls.Add(DirectoryTextBox);
SearchTextBox.Location = new Point(70, 43);
//SearchTextBox.Size = new Size(478, 20);
this.Controls.Add(SearchTextBox);
SearchButton.Location = new Point(526, 12);
SearchButton.Size = new Size(160, 23);
SearchButton.Text = "Search Directory";
SearchButton.TabStop = false;
SearchButton.Click += SearchButton_Click;
this.Controls.Add(SearchButton);
FileSearchButton.Location = new Point(526, 43);
FileSearchButton.Size = new Size(160, 23);
FileSearchButton.Text = "Search file based-on text";
FileSearchButton.TabStop = false;
FileSearchButton.Click += FileSearchButton_Click;
this.Controls.Add(FileSearchButton);
listBox1.AllowDrop = true;
listBox1.DragDrop += listBox1_DragDrop;
listBox1.DragEnter += listBox1_DragEnter;
listBox1.Focus();
}
private void listBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
private void listBox1_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
listBox1.Items.AddRange(File.ReadAllLines(file));
}
private void SearchButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
DialogResult dialogReasult = folderBrowserDialog.ShowDialog();
if(!string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
{
DirectoryTextBox.Text = folderBrowserDialog.SelectedPath;
}
}
public void FileSearchButton_Click(object sender, EventArgs e)
{
FilesPanel.Controls.Clear();
int i = 0;
int y = 5;
string filesName = string.Empty;
string rootfolder = DirectoryTextBox.Text.Trim();
string[] files = Directory.GetFiles(rootfolder, "*.*", SearchOption.AllDirectories);
foreach (string file in files)
{
try
{
string contents = File.ReadAllText(file);
if(contents.Contains(SearchTextBox.Text.Trim()))
{
i += 1;
LinkLabel aLinkLabel = new LinkLabel();
aLinkLabel.Text = file;
aLinkLabel.Location = new Point(5, y);
aLinkLabel.AutoSize = true;
aLinkLabel.BorderStyle = BorderStyle.None;
aLinkLabel.LinkBehavior = LinkBehavior.NeverUnderline;
aLinkLabel.ActiveLinkColor = Color.White;
aLinkLabel.LinkColor = Color.White;
aLinkLabel.BackColor = Color.Transparent;
aLinkLabel.VisitedLinkColor = Color.Red;
aLinkLabel.Links.Add(0, file.ToString().Length, file);
aLinkLabel.LinkClicked += aLinkLabel_LinkClicked;
FilesPanel.Controls.Add(aLinkLabel);
y += aLinkLabel.Height + 5;
}
else
{ // This shows DONE after each Search
LinkLabel aLinkLabel = new LinkLabel();
aLinkLabel.Font = new Font("", 12);
aLinkLabel.ActiveLinkColor = Color.White;
aLinkLabel.LinkColor = Color.White;
aLinkLabel.BackColor = Color.Transparent;
aLinkLabel.Text = "DONE";
FilesPanel.Controls.Add(aLinkLabel);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
void aLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
LinkLabel lnk = new LinkLabel();
lnk = (LinkLabel)sender;
lnk.Links[lnk.Links.IndexOf(e.Link)].Visited = true;
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
//Create a directory if not exist for the file to be copied into
if (!System.IO.Directory.Exists(#"C:\Temp\RoHS_Docs"))
{
System.IO.Directory.CreateDirectory(#"C:\Temp\RoHS_Docs");
}
//Perform the file copy action on click
string CopyDestinationPath = #"C:\Temp\RoHS_Docs\";
System.IO.File.Copy(WHAT????, CopyDestinationPath, true);
}
private void FileSearcherBasedOnSpecificText_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
FilesPanel.Controls.Clear();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SearchTextBox.Text = listBox1.SelectedItem.ToString();
}
private void label4_Click(object sender, EventArgs e)
{
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
}
}

C# - How will the value displayed on textbox will be displayed once the "delete" button is clicked?

I am creating a POS system. I only know how to display the data that are always submitted. But.. when I try to delete a certain product from the listview, the value displayed on the text box doesn't deduct. How can I implement the codes from it?
Here is the code..
public frm_order() {
InitializeComponent();
listView1.View = View.Details;
listView1.FullRowSelect = true;
listView1.Columns.Add("Product Name", 150);
listView1.Columns.Add("Quantity", 100);
listView1.Columns.Add("Price", 100);
}
private void add(String name, String qty, String price) {
String[] row = {
name,
qty,
price
};
ListViewItem item = new ListViewItem(row);
listView1.Items.Add(item);
}
int qty;
double price;
double subtotal;
double tax;
double total;
double vat = 0.12;
private void btn_choco_Click(object sender, EventArgs e) {
txt_name.Text = "Choco Lover";
txt_price.Text = "65.00";
txt_quantity.Text = "1";
price = 65.00;
}
private void btn_tutti_Click(object sender, EventArgs e) {
txt_name.Text = "Tutti Frutti";
txt_price.Text = "65.00";
txt_quantity.Text = "1";
price = 65.00;
}
private void btn_black_Click(object sender, EventArgs e) {
txt_name.Text = "Black Forest";
txt_price.Text = "75.00";
txt_quantity.Text = "1";
preprice = 75.00;
}
private void btn_vanilla_Click(object sender, EventArgs e) {
txt_name.Text = "Vanilla Sky";
txt_price.Text = "65.00";
txt_quantity.Text = "1";
price = 65.00;
}
private void btn_ube_Click(object sender, EventArgs e) {
txt_name.Text = "Ube My Bebe";
txt_price.Text = "65.00";
txt_quantity.Text = "1";
preprice = 65.00;
}
private void btn_smores_Click(object sender, EventArgs e) {
txt_name.Text = "Smore's Pa More";
txt_price.Text = "65.00";
txt_quantity.Text = "1";
price = 65.00;
}
private void btn_cookie_Click(object sender, EventArgs e) {
txt_name.Text = "Cookie Monster";
txt_price.Text = "65.00";
txt_quantity.Text = "1";
price = 65.00;
}
private void btn_rainbow_Click(object sender, EventArgs e) {
txt_name.Text = "Rainbow Dreamland";
txt_price.Text = "75.00";
txt_quantity.Text = "1";
price = 75.00;
}
private void btn_confirm_Click(object sender, EventArgs e) {
qty = Convert.toInt32(txt_quantity.Text);
add(txt_name.Text, txt_quantity.Text, txt_price.Text);
subtotal = price * qty;
txt_subtotal.Text = subtotal.ToString();
tax = subtotal * vat;
txt_tax.Text = tax.ToString();
total = subtotal + total;
txt_total.Text = total.ToString();
txt_name.Text = "";
txt_quantity.Text = "";
txt_price.Text = "";
}
private void delete() {
if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) {
listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
listView1.Refresh();
txt_name.Text = "";
txt_quantity.Text = "";
txt_price.Text = "";
}
}
private void btn_del_Click(object sender, EventArgs e) {
delete();
}
private void update() {
listView1.SelectedItems[0].SubItems[0].Text = txt_name.Text;
listView1.SelectedItems[0].SubItems[1].Text = txt_quantity.Text;
listView1.SelectedItems[0].SubItems[2].Text = txt_price.Text;
txt_name.Text = "";
txt_quantity.Text = "";
txt_price.Text = "";
}
private void btn_update_Click(object sender, EventArgs e) {
update();
}
private void btn_clear_Click(object sender, EventArgs e) {
listView1.Items.Clear();
txt_name.Text = "";
txt_quantity.Text = "";
txt_price.Text = "";
}
private void listView1_MouseClick(object sender, MouseEventArgs e) {
txt_name.Text = listView1.SelectedItems[0].SubItems[0].Text;
txt_quantity.Text = listView1.SelectedItems[0].SubItems[1].Text;
txt_price.Text = listView1.SelectedItems[0].SubItems[2].Text;
}
private void btn_payment_Click(object sender, EventArgs e) {
frm_payment pay = new frm_payment();
pay.Show();
}
private void frm_order_Load(object sender, EventArgs e) {
}
private void txt_quantity_KeyPress(object sender, KeyPressEventArgs e) {
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) {
e.Handled = true;
}
}
Also, how would I implement the code that will display the total of "ordered product"? hope you can answer me.
after deleting from listView you need to call update() each time. Call listView1.Refresh() after deleting like below (I tested its working for me)
listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
listView1.Refresh();

Showing words in a text file via textbox?

My code simply reads the file, splits it into words and whows each word in the textbox with 0.1 seconds frequency.
I click to "button1" to get the file and split.
After I click Start_Button the program gets stuck. I can't see any problem in the code. Can anyone see it please?
My code is here;
public partial class Form1 : Form
{
string text1, WordToShow;
string[] WordsOfFile;
bool LoopCheck;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog BrowseFile1 = new OpenFileDialog();
BrowseFile1.Title = "Select a text file";
BrowseFile1.Filter = "Text File |*.txt";
BrowseFile1.FilterIndex = 1;
string ContainingFolder = AppDomain.CurrentDomain.BaseDirectory;
BrowseFile1.InitialDirectory = #ContainingFolder;
//BrowseFile1.InitialDirectory = #"C:\";
BrowseFile1.RestoreDirectory = true;
if (BrowseFile1.ShowDialog() == DialogResult.OK)
{
text1 = System.IO.File.ReadAllText(BrowseFile1.FileName);
WordsOfFile = text1.Split(' ');
textBox1.Text = text1;
}
}
private void Start_Button_Click(object sender, EventArgs e)
{
timer1.Interval = 100;
timer1.Enabled = true;
timer1.Start();
LoopCheck = true;
try
{
while (LoopCheck)
{
foreach (string word in WordsOfFile)
{
WordToShow = word;
Thread.Sleep(1000);
}
}
}
catch
{
Form2 ErrorPopup = new Form2();
if (ErrorPopup.ShowDialog() == DialogResult.OK)
{
ErrorPopup.Dispose();
}
}
}
private void Stop_Button_Click(object sender, EventArgs e)
{
LoopCheck = false;
timer1.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = WordToShow;
}
}
}
Instead of Thread.Sleep(1000); use async/await feature with Task.Delay in order to keep your UI responsible:
private async void Start_Button_Click(object sender, EventArgs e)
{
timer1.Interval = 100;
timer1.Enabled = true;
timer1.Start();
LoopCheck = true;
try
{
while (LoopCheck)
{
foreach (string word in WordsOfFile)
{
WordToShow = word;
await Task.Delay(1000);
}
}
}
catch
{
Form2 ErrorPopup = new Form2();
if (ErrorPopup.ShowDialog() == DialogResult.OK)
{
ErrorPopup.Dispose();
}
}
}

how to add event reminder to my windows phone 7 application

I am building an app in windows phone 7 where i need to add an event reminder. On clicking a button the reminder should be set. My cs file is:
namespace KejriwalPhoneApp
{
public partial class EventDetails : PhoneApplicationPage
{
public EventDetails()
{
InitializeComponent();
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBarIconButton home = new ApplicationBarIconButton();
home.IconUri = new Uri("/Image/icon_home_deselect.png", UriKind.Relative);
home.Text = "Home";
ApplicationBar.Buttons.Add(home);
home.Click += new EventHandler(home_Click);
ApplicationBarIconButton share = new ApplicationBarIconButton();
share.IconUri = new Uri("/Image/icon_share_deselect.png", UriKind.Relative);
share.Text = "Share";
ApplicationBar.Buttons.Add(share);
share.Click += new EventHandler(share_Click);
ApplicationBarIconButton news = new ApplicationBarIconButton();
news.IconUri = new Uri("Image/icon_news_deselect.png", UriKind.Relative);
news.Text = "News";
ApplicationBar.Buttons.Add(news);
news.Click += new EventHandler(news_Click);
ApplicationBarIconButton events = new ApplicationBarIconButton();
events.IconUri = new Uri("/Image/icon_event_deselect.png", UriKind.Relative);
events.Text = "Video";
ApplicationBar.Buttons.Add(events);
events.Click += new EventHandler(events_Click);
}
void events_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
void news_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/News.xaml", UriKind.Relative));
}
void share_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/share.xaml", UriKind.Relative));
}
void home_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
private void Image_Back(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var imagePath = "";
var eventdate = "";
var location = "";
var utimee = "";
var tzone = "";
var ename = "";
var desc = "";
//check if particular parameter available in uri string
if (this.NavigationContext.QueryString.ContainsKey("image_path"))
{
//if it is available, get parameter value
imagePath = NavigationContext.QueryString["image_path"];
eventimage.Source = new BitmapImage(new Uri(#"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/" + imagePath, UriKind.Absolute));
}
if (this.NavigationContext.QueryString.ContainsKey("Time_Zone"))
{
tzone = NavigationContext.QueryString["Time_Zone"];
timezone.Text = tzone;
}
if (this.NavigationContext.QueryString.ContainsKey("uTime"))
{
utimee = NavigationContext.QueryString["uTime"];
utime.Text = utimee;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Date"))
{
//if it is available, get parameter value
eventdate = NavigationContext.QueryString["Event_Date"];
evntdate.Text = eventdate;
}
if (this.NavigationContext.QueryString.ContainsKey("Location"))
{
//if it is available, get parameter value
location = NavigationContext.QueryString["Location"];
loc.Text = location;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Name"))
{
//if it is available, get parameter value
ename = NavigationContext.QueryString["Event_Name"];
enamee.Text = ename;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Description"))
{
//if it is available, get parameter value
desc = NavigationContext.QueryString["Event_Description"];
edescription.Text = desc;
}
}
private void Image_Previous(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
private void Image_rem(object sender, RoutedEventArgs e)
{
RegisterReminder();
}
private void RegisterReminder()
{
var reminder = ScheduledActionService.Find(ename) as Reminder ?? new Reminder(ename);
reminder.Title = ename;
reminder.Content = desc;
// parse eventDate,utimee to beginDateTime
reminder.BeginTime = beginDateTime;
reminder.ExpirationTime = reminder.BeginTime.AddDays(1);
reminder.RecurrenceType = RecurrenceInterval.None;
if (ScheduledActionService.Find(ename) == null)
ScheduledActionService.Add(reminder);
else
ScheduledActionService.Replace(reminder);
MessageBox.Show("reminder set succeed!");
}
}
}Now when the reminder button is clicked i want the fields utimee, tzone to be set and i get a pop up message "Event reminder added successfully"
I am not getting the idea on how to do this
You can do these steps:
1.get the values from webservice as global variableļ¼š
eventDate,location, utimee, tzone, ename,desc.
2.click the reminder button, execute the click method
private void BtnReminderClick(object sender, EventArgs e)
{
RegisterReminder();
}
3.do reminder register
private void RegisterReminder()
{
var reminder = ScheduledActionService.Find(ename) as Reminder ?? new Reminder(ename);
reminder.Title = ename;
reminder.Content = desc;
// parse eventDate,utimee to beginDateTime
reminder.BeginTime = DateTime.Parse(eventDate).Date + DateTime.Parse(utimee).TimeOfDay;
reminder.ExpirationTime = reminder.BeginTime.AddDays(1);
reminder.RecurrenceType = RecurrenceInterval.None;
if (ScheduledActionService.Find(ename) == null)
ScheduledActionService.Add(reminder);
else
ScheduledActionService.Replace(reminder);
MessageBox.Show("reminder set succeed!");
}

C# class to play a video file

I have this class,
public class ImageBox : Grid
{
Image imgclose; public String path;
List<ImageBox> ImageBoxes;
public ImageBox(string label,List<ImageBox> ImBox)
{
this.ImageBoxes = ImBox;
imgclose = new Image();
imgclose.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Close.ico"));
imgclose.Width = 20; imgclose.Height = 20; imgclose.Cursor = Cursors.Hand; imgclose.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; imgclose.VerticalAlignment = System.Windows.VerticalAlignment.Top;
imgclose.Visibility = System.Windows.Visibility.Hidden;
imgclose.MouseLeftButtonDown += new MouseButtonEventHandler(imgclose_MouseLeftButtonDown);
this.MouseEnter += new MouseEventHandler(Blank_MouseEnter);
this.MouseLeave += new MouseEventHandler(Blank_MouseLeave);
this.Height = 100; this.Width = 100;
try
{
System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog();
path = open.FileName.Replace(Directory.GetCurrentDirectory(), "");
this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
path = label;
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
Grid.SetColumn(imgclose, 0); Grid.SetRow(imgclose, 1);
this.Children.Add(imgclose);
ContextMenu contextMenu1 = new ContextMenu();
MenuItem conitem1 = new MenuItem() { Header = "Send to back" }; conitem1.Click += new System.Windows.RoutedEventHandler(conitem1_Click);
MenuItem conitem2 = new MenuItem() { Header = "Bring to Front" }; conitem2.Click += new System.Windows.RoutedEventHandler(conitem2_Click);
contextMenu1.Items.Add(conitem1); contextMenu1.Items.Add(conitem2);
this.ContextMenu = contextMenu1;
}
void conitem1_Click(object sender, EventArgs e)
{
Canvas.SetZIndex(this, (Canvas.GetZIndex(this) - 1));
}
void conitem2_Click(object sender, EventArgs e)
{
Canvas.SetZIndex(this, (Canvas.GetZIndex(this) + 1));
}
void Blank_MouseEnter(object sender, MouseEventArgs e)
{
imgclose.Visibility = System.Windows.Visibility.Visible;
}
void Blank_MouseLeave(object sender, MouseEventArgs e)
{
imgclose.Visibility = System.Windows.Visibility.Hidden;
}
void imgclose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (System.Windows.MessageBox.Show("Are you sure?", "Confirm", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.OK)
{
ImageBoxes.Remove(this);
(this.Parent as System.Windows.Controls.Canvas).Children.Remove(this);
}
else
{
}
}
}
This class displays an image (chosen from a dialog box).
How can I modify it to make it play a video file ?
More precisely,
How should I modify the line
this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
path = label;
so that it plays a video file.
The Background property has to have some sort of Brush in it. A quick Google search came up with this: VideoBrush. I hope this is what you were looking for.

Categories