My WPF application is a media player that has a button that launches another window to a certain location and is my webbrowser. Problem is, once i click my button to launch the browser, my 'hide' button does not hide the browser window :/, from what i researched i need to inherit button click events, take a look at the code:
private void button4_ClickWeb(object sender, RoutedEventArgs e)
{
//opens a web browser if 'Web' is clicked on the WPF Media PLayer
Window1 f1 = new Window1();
f1.Show();
}
the ideas i thought would work is create a 'toggle button' like such:
private void button4_ClickWeb(object sender, RoutedEventArgs e)
{
ToggleButton tb = (ToggleButton)sender;
if ((bool)tb.IsChecked)
{
f1.Show();
//or
f1.WindowState = WindowState.Normal;
}
else
{
f1.Hide();
f1.WindowState = WindowState.Minimized;
}
}
this approach failed, and yes i tried variations and moving things around with NO success, i was told that i need to make a class of f1 to inherit button click events but i have no idea how to do that :/ any ideas?
here is how the app looks like:
Related
I have an application which runs mostly within the taskbar, and its icon may be left clicked in order to open a Windows form.
The NotifyIcon also has a few MenuItems which can be accessed by right clicking, and each have their own click events to serve their functionality.
private void menuItem4_Click(object Sender, EventArgs e)
{
if (programEnabled == false)
{
programEnabled = true;
Console.WriteLine("Enabled!");
}
else
{
programEnabled = false;
Console.WriteLine("Disabled!");
}
}
//Icon clicked!
private void notifyIcon1_MouseClick(object Sender, EventArgs e)
{
//Reopen the form
Form f = new TemperForm();
}
Every time a MenuItem click event is activated however, NotifyIcon_Click also runs and I need that event for opening the Windows form. I don't want every time I click any MenuItem to also run the code that I wish to run when the icon is clicked.
How can I still use the NotifyIcon_Click event while not having it run every time I click a MenuItem?
I've been at this for hours and it's driving me up the wall!
I want to be able to press a button and have the program open up a new window and close the old one.
I have followed solutions from this link but i have never has success with any of them How do I open a second window from the first window in WPF?
Here is my work soo far:
Window editor = new Window();
editor.Show();
this.Close();
But this does nothing.
The program should open up a new window and close the old one.
The functionality you described will work just fine. The Problem there is would more likely be the function or Methode in which you call this function.
To write a Methode that would handle a Button press as you want is pretty good described here: https://www.c-sharpcorner.com/forums/c-sharp-button-click-hold-and-release.
Hopefully, this will help you otherwise just ask
here is a small Implementation if that helps:
public partial class MainWindow : Window
{
private void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
Window editor = new MainWindow();
editor.Show();
this.Close();
}
private void MainWindow_KeyUP(object sender, KeyEventArgs e)
{
}
public MainWindow()
{
this.KeyDown += MainWindow_KeyDown;
this.KeyUp += MainWindow_KeyUP;
}
}
You have to call the second window from the first. This is something I did for a project where it popped up a new login panel window:
private void displayLoginPanel_Click(object sender, EventArgs e)
{
LoginPanel myLogin = new LoginPanel(this);
myLogin.Show();
this.Hide();
}
I used hide() instead of close() because you can see that I am sending a reference of the parent to the child LoginPanel in order to come back later. You can replace the Hide() with Close().
I have a page that have a button to open a popup windows like this:
//in page.xaml.cs
private void Add_Click(object sender, RoutedEventArgs e)
{
New_Window window = new New_Window ();
window .Show();
}
Then in a popup New_Window, i want to close the popup window and reload the previous page after a click method in a popup window. How do i do it ? thanks a lot.
I'm a beginner and having some dicciculties with XAML.
I have a main view A, which has a button to open a pop-up-window B. When this happens, Window A should still be visible and openened, but disabled. I've done this in code behind (maybe not the cleanest way, but the only way I know how). The code i used for this is the following:
//Code behind from view A
private void X-Button_Click(object sender, RoutedEventArgs e)
{
var BWindow = new BView();
BWindow.Show();
this.IsEnabled = false;
}
I would like to get window A enabled again once i close window B, but i can t seem to get this work. Any help would be very much appreciated.
You could do it in the following way.
You register yourself on the Closed event of the window, and when it gets closed, you unregister the event, and re-enable the this form.
private void Button_Click(object sender, RoutedEventArgs e)
{
Window BWindow = new BWindow();
BWindow.Show();
BWindow.Closed += BWindow_Closed;
this.IsEnabled = false;
}
void BWindow_Closed(object sender, EventArgs e)
{
Window win = sender as Window;
if (win != null)
{
win.Closed -= BWindow_Closed;
}
this.IsEnabled = true;
}
I assume you are looking for modal window. See similar question asked here: How do make modal dialog in WPF?
The solution is in using ShowDialog method from Window class. See here for reference:
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx
Modal window is the concept when you open new window B from the existing window A. While the B is open, the A is disabled and cannot be used. Window A become active only when the B is closed.
I am learning windows forms and can create a one form with textboxes and stuff, but I was wondering how can I change the form upon let's say clicking a button?, so for instance my initial form has a textbox and a button, if the button is clicked I want to show a form with a dropdown and a button. SO the question should be:
1) How do I change the form upon clicking a button but without creating a new instance of the form.
2) If I wanted, how can I add a form when the button is clicked showing the same drop down and button as a pop up form?
In reality I would like to know both cases, changing the form via using the same form and via popping a new form on top.
Should the questions not be clear, I am willing to further explain
Thank you
I'm assuming you already know how to add controls in the form designer and how to implement event handlers.
Question 1
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.Visible)
{
comboBox1.Visible = false;
textBox1.Visible = true;
}
else
{
comboBox1.Visible = true;
textBox1.Visible = false;
}
}
The button click handler simply toggles the visibility of the two controls.
Question 2
private void button2_Click(object sender, EventArgs e)
{
Form1 form = new Form1();
form.ShowDialog();
}
This time the button handler instantiates a new form an then shows it as a modal dialog. Call Show() if you don't want to show modally.