Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Having hard time dealing with this because every time I navigate to another form my project lags or is unresponsive for a few seconds before it shows the content of the window.
How can I close all the child windows with a method?
I have tried this.Close() but that didn't work.
You may use Application Class as a place of storing a links to the child windows. It creates a singleton Current which is accesable from any place
public partial class App : Application
{
private List<Window> childWindows = new List<Window>();
public List<Window> ChildWindows{get{return childWindows;}}
}
To register new ChildWindow add this into Initialized event handler
private void ChildWindow_Initialized(object sender, EventArgs e)
{
((App)Aplication.Current).Windows.Add(this);
}
on ChildWindow Closing you have to remove link from collection
private void ChildWindow_Closed(object sender, EventArgs e)
{
((App)Aplication.Current).Windows.Remove(this) // here
}
if needs you may replace List with Dictionary to have a possibility of searching by key
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
When creating a winforms application I added a pannel as a header so I could make the application borderless, I was going to add some buttons when I realised no events were getting registered by the program. Have I flicked a wrong switch somewhere?
I have already tried clicking the main form and changing the AutoValidation as well as checking that the form, as well as the panel, were both enabled.
public App()
{
InitializeComponent();
}
private void TopBar_MouseHover(object sender, EventArgs e)
{
Application.Exit();
}
private void ExitButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
Expect result is that it should just close the application when I hover over the topbar or when I click the ExitButton.
I fixed this by going through the properties of the Forms/Buttons and resetting them as it turns out I had one item disabled.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm doing this Windows Forms application in C# so when you click this button multiple times, it calculates the average clicks per second you do.
I just yesterday started learning C# and the only language im good at is Lua. In Lua this would be simple, just use a table as they're very dynamic and flexible. I just have no clue how to do this in C#, the MSDN Articles just confuse me.
How would I store the times between clicks? Arrays? I have no clue. This is the button click function I have so far
private void button1_Click(object sender, EventArgs e)
{
//DO STUFF
}
You could store the time of each click, then compute the average of the times between them:
private List<DateTime> clickTimes = new List<DateTime>();
private void button1_Click(object sender, EventArgs e)
{
this.clickTimes.Add(DateTime.Now);
if (this.clickTimes.Count > 2)
{
double averageSeconds = this.clickTimes.Zip(this.clickTimes.Skip(1), (a,b) => (b-a).TotalSeconds)).Average();
// Do something with the average seconds between each click here
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Please can you help me how can i create popup panel with informations for mouseover. I using C# offline application.
I don't know how can i do this on mouseover with application. For website it is javascript but for C# ... i don't know.
I know how to use mouseover for it, but i don't know how to create popup window with informations for mouseover. It's exactly my problem. Please can you help me?
You could start by testing the following:
You can use MouseEnter to show a window in a popup style.
private void panel1_MouseEnter(object sender, System.EventArgs e)
{
MyForm frm = new MyForm();
frm.ShowDialog();
}
When you require behavior like jquery UI Tooltip you can use UserControl
private Control popup;
private void panel1_MouseEnter(object sender, System.EventArgs e)
{
MyUserControl mcu = new MyUserControl ();
this.popup =mcu; //save references to new control
this.Controls.Add(this.popup);
this.popup.Location.X = ((Control)sender).Location.X+ offsetX;
this.popup.Location.Y = ((Control)sender).Location.Y+ offsetY;
}
private void panel1_MouseLeave(object sender, System.EventArgs e)
{
this.Controls.Remove(this.popup);
}
This sounds suspiciously like a ToolTip.
So I recommend that you use the ToolTipService for this (in your xaml):
<object>
<ToolTipService.ToolTip>
<objectThatFillsTheToolTip .../>
</ToolTipService.ToolTip>
</object>
This sample is from the msdn docu page.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm building a program with C# in Windows Forms, and the following question came to me. I have several buttons in my form and when any of them is clicked, I want to be able to store its ID in a single variable that will handle only one ID at a time. I already have a method that does this, but the fact is I don't want to call this method from the event handler of each button:
button1_Click(object senders /* ... yada yada ... */)
Is there a way how I can simplify this with a single method? Is it even possible?
You don't need many Click event handlers for your buttons, just 1 is enough:
private void buttons_Click(object sender, EventArgs e){
Button button = sender as Button;
//do something with the clicked button
//...
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The utility I'm building will have several forms that are very similar to each other in appearance (the code behind the forms will differ, so I don't want to use one form for all of it, to avoid a big jumbled up mess). Rather than recreate each form one at a time, I'd like to "inherit" from the existing form. Is there a canonical way of doing this with Winforms?
If not, I'll select all of the controls on the form and paste them into the new ones...
If i get you, you want to copy all the controls from one form to another form.
There are two ways i know
1.) Create a docked panel on the main form and add all the controls to the panel and when you want to paste you use.
private void Form2_Load(object sender, EventArgs e)
{
Form1 form = new Form1();
this.Controls.Add(form.panel1);
}
2.) Use Inheritance. After Creating the Controls in the main form, in the second form you use
public partial class Form2 : Form1
{
public Form2()
{
InitializeComponent();
}
}
This will automatically copy all the controls to the new form