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.
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 1 year ago.
Improve this question
For Xamarin Forms:
I am looking to use checkboxes to enable the next set in a series. I have used x:name to set the names of the checkboxes (Fiore, Leichtenauer and Guards). My goal is to set a if statement to change the IsEnabled to false/true in the code behind when the first checkbox is checked. I seem to be getting an error for the IsEnabled, what should I be using instead? Thank you in advance.
private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e)
{
if (Fiore.IsChecked)
{
Leichtenauer = IsEnabled(false),
Guards = IsEnabled(true)
}
}
IsEnabled is a property of the control, so you would set it like
if (Fiore.IsChecked)
{
Leichtenauer.IsEnabled = false;
Guards.IsEnabled = true;
}
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 4 years ago.
Improve this question
Ok, new to C# (What a pain!!!) and I am simply trying to have a button on Form1 open Form2
My structure:
Root Folder
|
Screens
|
Form1.cs
Form2.cs
My Code:
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
MessageBox.Show("pausing for 3 sec");
System.Threading.Thread.Sleep(3000);
Screens.Form2 f2 = new WindowsFormsApp1.Screens.Form2();
f2.ShowDialog;
}
The error is on the f2.showdialog; line:
Error: CS0201 C# Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
This makes no sense. I believe I am properly calling the form in the subfolder?
f2.ShowDialog; isn't a method call (because there are no brackets ()), so the compiler thinks you're trying to execute a property or field.
It should be f2.ShowDialog();
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 5 years ago.
Improve this question
i started a create a simple web browser...
when i code it web page is not loading...
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("textBox1.Text");
}
}
}
This is the error when i go to a web page.
When you used the "" literals, you told the Compiler to treat what is between these "" as a literal string and not a valid C# expression. So the expression will not be evaluated. And your WebBrowser control will receive this literal string "textBox1.Text" exactly as it is. And not the Text property of textBox1 Control. By removing these "" literals:
webBrowser1.Navigate(textBox1.Text);
Your WebBrowser control will receive the value of Text property of the textBox1 control.
use webBrowser1.Navigate(textBox1.Text); instead
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 8 years ago.
Improve this question
It skips the navigating to valid URL and goes straight to a Google search. If I enter "stackoverflow.com" into textbox it will Google search for "stackoverflow.com".
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text); //navigates to url in textbox
if (!textBox1.Text.StartsWith("http://"))
{
webBrowser1.Navigate("http://www.google.ie/search?q=" + (textBox1.Text));
}
}
That code, in English, basically says "navigate to whatever was entered into the textbox. Then, IF whatever you entered into the textbox does NOT start with 'http://' let's immediately do a Google search for it."
Basically you are navigating to stackoverflow.com but you're then immediately Google searching for it instead. If you want it to act differently, you need to code it differently.
Here's how I'd rework it:
private void button1_Click(object sender, EventArgs e)
{
if (!textBox1.Text.StartsWith("http://"))
{
// didn't start with "http://" so search for it
webBrowser1.Navigate("http://www.google.ie/search?q=" + (textBox1.Text));
}
else
{
// navigate directly to the URL
webBrowser1.Navigate(textBox1.Text);
}
}
In an if-else statement, only one logic path will be chosen based on conditions. It will never be the case that both run.
It searches Google because your logic is saying that 'if the textbox contents doesn't start with http:// let's do a Google search'. You are actually loading stackoverflow.com, but you immediately change the page and load Google instead.
You might want the code below with your code modified to 'filter' out and save some memory by not loading stackoverflow.com first:
private void button1_Click(object sender, EventArgs e)
{
if (!textBox1.Text.StartsWith("http://") | !textBox1.Text.StartsWith("www") || !textBox1.Text.StartsWith("http://www"))
{
webBrowser1.Navigate("http://www.google.ie/search?q=" + (textBox1.Text));
}
else
{
webBrowser1.Navigate(textBox1.Text); //navigates to url in textbox
}
}
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