I have created a form that will play a video upon loading. However I cannot figure out how to get the video to stop playing when the user exits the form. I have tried some other solutions that people have used but they don't seem to work.
When I say the video doesn't stop playing I mean that the audio from the video can still be heard even after the form containing the video has been closed.
Any suggestions?
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 RRAS
{
public partial class frmVideoTutorial : Form
{
formRRAS _main;
public frmVideoTutorial(formRRAS main)
{
InitializeComponent();
_main = main;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmVideoTutorial_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = #"F:\Group Project\RRAS\RRAS\RRAS\Tutorial.mp4";
}
private void frm_close(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
axWindowsMediaPlayer1.close();
}
else
{
e.Cancel = true;
}
}
}
}
You can go to the form properties and go to the events. Click on FormClosed event. From there just add the code to make the player stop, upon form exit.
I was having a similar issue, and that's what I done to fix it. I had asked the same question, except it was for bringing another form up.
This should do the trick. Be sure to do it on each form that has a video. That you want stopped upon exiting.
Use the .Stop();
Related
I am trying to make a program that once a "fake" progress bar expires, the background image of the form changes to another one. This is my first time using forms as a GUI, so I would really appreciate the help. If possible, please explain how the code works. I'm using Visual Studio 2017. Here's how the code looks like.
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 Form_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.progressBar1.Increment(1);
}
}
}
in this event you have to check if the progressbar value is 100
it'll be like :
private void timer1_Tick(object sender, EventArgs e)
{
if(progressBar1.Value<100) // set progressBar max value to 100
{
// if the value smaller than 100, will increment.
this.progressBar1.Increment(1);
}
else{
timer1.Stop(); // Important to stop the timer
// here you change the background image of the form.
this.BackgroundImage = // choose ur image location.
}
}
I am developing a C# application using Visual Studio 2015
it has 2 forms, on form1 I have a button that when clicked
shows form2, now what I would like to do is print form2
after it has fully loaded, I am using the printform control
on form2 to do this, if I use this on the the form_load event
it prints a blank page and then shows the form, I have
also tried using it on form_Shown, however this prints a box
where the elements are but not the element itself as if they have
not finished loading, there is probably a better way to do this
but I am new to C# so still learning
Below is an example of the code that I have on form2
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 MyApp
{
public partial class Form2: Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.Shown += new System.EventHandler(this.Form2_Shown);
}
private void Form2_Shown(object sender, EventArgs e)
{
printForm.Print();
}
}
}
The Shown event fires a wee bit too early. The form's frame and background is painted but the rest follows later. Painting is a low priority task that occurs only when nothing else needs to be done, firing the Shown event happens first.
The workaround is simple, just ask the form to finish updating itself by calling its Update() method. Fix:
private void Form2_Shown(object sender, EventArgs e)
{
this.Update();
printForm.Print();
}
I am writing a simple code it has 3 buttons 2 that will need to open up other forms and one to close the program. When i start the program the exit button will not work even though i have it coded the same as any other time i have wrote a program.
When i press any of the buttons nothing happens. Im not 100% sure how to use the buttons to open another form but i know the exit button should work as is.
Here is the code:
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 _3343_ParksJ_Lab02
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void workerButton_Click(object sender, EventArgs e)
{
WorkerForm workersForum = new WorkerForm();
}
private void suppervisorButton_Click(object sender, EventArgs e)
{
SupervisorForm workersForum = new SupervisorForm();
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
You have to subscribe your buttons' click events to the event methods before they'll fire correctly.
You can check the Designer.cs file to see if this has already been done, though I'm guessing it hasn't. You'll be looking for something like this:
this.workerButton.Click += new System.EventHandler(this.workerButton_Click);
One way to do so is directly in the constructor:
public MainForm()
{
InitializeComponent();
workerButton.Click += workerButton_Click;
suppervisorButton.Click += suppervisorButton_Click;
exitButton.Click += exitButton_Click;
}
Normally, I'd do this through the designer. Select each Button in turn, then open the properties panel and double-click on the event you wish to subscribe to, which will create the corresponding event method in the code-behind for you.
Look at .Designer.cs file and make sure your button is adding the correct delegate method. In your case it should exitButton_Click.
Sometimes when you change names of a button VS designer does not make the name change correctly in the .Designer file. Very rare but it happens.
So.. i've googled around and everywhere i've seen different ways of creating this..
But so far, i haven't managed to make a single working menu.
So i wanted to ask, how does one create a notifyIcon menu?.. (prefered explained in details, as i'm rather new to this)
which way would be best and which should i use.. (so far people seemed to like contextmenu overally, but all i can find is contextmenustrip, not sure if it's the same.)
Currently i got a form, set to visible = false, windowstate minimized, showintaskbar = false.
that's about all it is for now. i wanted to have the menu before going wider.
Thank you for your time and effort for this (not sure if it's formulated properly)
EDIT: i've seemed to manage to make a menu, but how would i make it "appear" on my notify icon, it's a ContextMenu o_o
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 TrayTest.events
{
public partial class TrayMenu : Form
{
public TrayMenu()
{
InitializeComponent();
TrayMenuContext();
}
private void TrayMenuContext()
{
this.notify_icon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
this.notify_icon.ContextMenuStrip.Items.Add("Test1", null, this.MenuTest1_Click);
this.notify_icon.ContextMenuStrip.Items.Add("Test2", null, this.MenuTest2_Click);
this.notify_icon.ContextMenuStrip.Items.Add("Exit", null, this.MenuExit_Click);
}
void MenuTest1_Click(object sender, EventArgs e)
{
Application.Exit();
}
void MenuTest2_Click(object sender, EventArgs e)
{
Application.Exit();
}
void MenuExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
This worked fine for me. So i'll just leave it here, for other to take a peak at it.. (this is my Form1, just made 1 with a different name, and it's inside a folder named events (kinda why it has that .events))
"EDIT: i've seemed to manage to make a menu, but how would i make it "appear" on my notify icon, it's a ContextMenu o_o"
I believe you can only assign a ContextMenuStrip to the NotifyIcon using the IDE. For a ContextMenu, you'd have to wire it up via code. Double click your Form to get the Load() event, and wire it up in there:
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.ContextMenu = contextMenu1;
}
notifyIcon1->ContextMenu = gcnew System::Windows::Forms::ContextMenu();
System::Windows::Forms::MenuItem^ nI_Open_Item = gcnew System::Windows::Forms::MenuItem("Open");
System::Windows::Forms::MenuItem^ nII_Close_item = gcnew System::Windows::Forms::MenuItem("Close");
notifyIcon1->ContextMenuStrip->Items->Add(status_Item);
notifyIcon1->ContextMenu->MenuItems->Add(nI_Open_Item);
I am developing a video player for Window based computer, which can play online streaming videos from any address e.g. rtsp://live.example.com/live/mystream
For this purpose I am using Plugin from VLC.
I have 2 questions:
1. How to get status of video player that whether it started buffering or not. If yes then show buffering as a progress.
VLC Plugin shows VLC's logo in middle of video plyer screen, when no video is getting played. How to replace that logo with my custom Logo:
Following is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using SikhPlayer;
using System.Windows;
namespace SikhPlayer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
System.Threading.Thread.Sleep(500);
//axVLCPlugin21.BringToFront();
axVLCPlugin21.video.logo.file("http://localhost/logo.png");
axVLCPlugin21.video.logo.opacity = 50;
axVLCPlugin21.video.logo.Position = "center";
axVLCPlugin21.video.logo.enable();
axVLCPlugin21.AutoPlay = false;
}
private void button1_Click(object sender, EventArgs e)
{
axVLCPlugin21.playlist.playItem(#"rtsp://ip.example.com:1935/live/mystream);
axVLCPlugin21.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
axVLCPlugin21.playlist.stop();
}
}
}
Please help me if you have answer to my questions.
Thanks in Advance.
To get status of buffering, add event name axVLCPlugin21_MediaPlayerBuffering
It have 2 arguments: object sender , AxAXVLC.DVLCEvents_MediaPlayerBufferingEvent e
You can use value of e.cache to get status of buffering. Its value ranges from 0 to 100. It's like percentage of video buffered.
If I am not wrong, I think you cant. But, you can add picturebox on the video plugin and use the status of buffering (as described above), or other event like MediaPlayerPlaying, etc. to make picturebox visible or invisible.